关于选择部分,问题“通过Eclipse通过插件comand替换从Eclipse编辑器中选择的代码 ”足够满足您的需求:
try {
IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if ( part instanceof ITextEditor ) {
final ITextEditor editor = (ITextEditor)part;
IDocumentProvider prov = editor.getDocumentProvider();
IDocument doc = prov.getDocument( editor.getEditorinput() );
ISelection sel = editor.getSelectionProvider().getSelection();
if ( sel instanceof TextSelection ) {
// Here is your String
final TextSelection textSel = (TextSelection)sel;
}
}
} catch ( Exception ex ) {
ex.printStackTrace();
}
然后,您可以在弹出菜单中添加一个项目来链接此选择,如下面的SO问题: “ 如何在Eclipse中为编辑器上下文菜单贡献命令 ”
<command
commandId="org.my.command.IdCommand"
tooltip="My Command Tooltip"
id="org.my.popup.IdCommand">
<visibleWhen>
<with variable="selection">
<instanceof value="org.eclipse.jface.text.ITextSelection"/>
</with>
</visibleWhen>