您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

将项目添加到Eclipse文本查看器上下文菜单

将项目添加到Eclipse文本查看器上下文菜单

关于选择部分,问题“通过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>
其他 2022/1/1 18:31:58 有451人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶