|
快速eclipse插件开发经验:
1.取得对当前选中文本内容,并转换。
1)定义action实现ieditoractiondelegate接口。
2)取得当前编辑器(geteditor())。
platformui.getworkbench().getactiveworkbenchwindow().getactivepage().getactiveeditor();
3)取得选中文本。
(itextselection) geteditor().geteditorsite().getselectionprovider().getselection();
4)替换选中文本。
abstracttexteditor editor = (abstracttexteditor) geteditor();
editor.getdocumentprovider().getdocument(editor.geteditorinput());
document.replace(offset, length, replacetext);
5)选中替换后的文本。
itextselection tsnew = new textselection(document, offset, length);
geteditor().geteditorsite().getselectionprovider().setselection(tsnew);
2.菜单分组,图标,快捷键,工具条的实现。
1)菜单分组。如下分成4组,组之间有分隔线。
<menu label="xxxxtools(&t)" id="xxxxtoolsmenu">
<separator name="xxxxtoolsgrouptxt"></separator>
<separator name="xxxxtoolsgroupsql"></separator>
<separator name="xxxxtoolsgroupcode"></separator>
<separator name="xxxxtoolsgrouprefrence"></separator>
</menu>
|
2)分配action到组。设置图标。和工具条。
<action label="to lower case(&l)"
class="xxxxtools.actions.text.tolowercaseaction"
icon="icons/lower.gif"
menubarpath="xxxxtoolsmenu/xxxxtoolsgrouptxt"
toolbarpath="xxxxtoolsgrouptxt"
id="xxxxtools.actions.text.tolowercaseaction"
definitionid="xxxxtools.actions.text.tolowercaseaction">
<selection class="org.eclipse.jface.text.itextselection" />
</action>
|
3)设置快捷键。
<extension point="org.eclipse.ui.commands">
<command name="to lower case"
id="xxxxtools.actions.text.tolowercaseaction" />
</extension>
<extension point="org.eclipse.ui.bindings">
<key sequence="ctrl+shift+u"
contextid="org.eclipse.ui.texteditorscope"
commandid="xxxxtools.actions.text.tolowercaseaction"
schemeid="org.eclipse.ui.defaultacceleratorconfiguration" />
</extension>
|
|