我目前正在尝试制作一个 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/