java - 用于自动帮助搜索所选文本的 Eclipse 插件

标签 java eclipse eclipse-plugin

我目前正在尝试制作一个 Eclipse 插件,您可以在其中从编辑器中选择文本,按下快捷方式(在我的例子中是 alt+F1),然后 Eclipse 帮助搜索打开并自动搜索所选文本。

现在,我已经在一个将所选文本作为字符串返回的方法中进行了 Binding->Command->Handler 和文本选择,我一直在研究如何打开 Eclipse 帮助搜索和查询特定字符串我的代码。

我搜索了一下,从 org.eclipse.help.search 中找到了 ISearchEngine2,它可以帮助我完成我想做的事情,但由于我是 Eclipse 插件开发的新手,我真的不知道如何实现

谁能帮我解决这个问题?

我的代码目前看起来像这样:

    public class Button1 extends AbstractHandler {

        public Button1() {}

            public String getCurrentSelection()
            {
            IEditorPart part =PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
            if (part instanceof ITextEditor)
            {
            final ITextEditor editor = (ITextEditor) part;
            ISelection sel = editor.getSelectionProvider().getSelection();
            if (sel instanceof TextSelection)
            {
                 ITextSelection textSel = (ITextSelection) sel;
                 return textSel.getText();
            }
            }
            return null;
            }

public void searchInHelp(String str){
...
}

        public Object execute(ExecutionEvent event) throws ExecutionException {
            IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
            String str = getTextSelection();
            searchInHelp(str);

            return null;
        }
    }

最佳答案

ISearchEngine2 用于实际实现帮助系统的引擎。

想要使用帮助系统的插件使用IWorkbenchHelpSystem接口(interface):

IWorkbenchHelpSystem help = PlatformUI.getWorkbench().getHelpSystem();

help.search("help search expression");

关于java - 用于自动帮助搜索所选文本的 Eclipse 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31831931/

相关文章:

java - StackedXYAreaChart - 始终显示错误的系列号

java - super 和extends 在通用通配符中是独占的吗?

eclipse - ubuntu中的apache Tomcat安装目录/在eclipse + ubuntu中配置Tomcat

java - 从 Eclipse 插件中的文件读取

eclipse - Eclipse SVN客户端(Subclipse)未在文件上显示状态图标

java - 如何将 Drool 规则显示到 Eclipse View 中

java - Android NativeActivity : AttachCurrentThread JNIInvokeInterface is not a structure or union

java - 如何在 JUnit 中测试测试 Delete(),如何实际测试 J-Unit

java - 如何创建 Restful 服务并将其部署到 OSGi 容器中?

eclipse - Scala IDE 和 Apache Spark——在构建路径中发现不同的 Scala 库版本