关于选择部分,问题" 通过插件命令从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();
}
Run Code Online (Sandbox Code Playgroud)
然后,您可以将此选择与弹出菜单中的项目添加相关联,如此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>
Run Code Online (Sandbox Code Playgroud)