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

Eclipse plugin for automatic help search of a selected text

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

现在,我已经制作了 Binding->Command->Handler 和文本 selection,方法是 returns selected 文本作为字符串,我得到了坚持如何通过我的代码打开 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接口:

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

help.search("help search expression");