Eclipse plugin to automatically search for help on selected text
I am currently trying to create an Eclipse plugin where you select text from the editor, press the shortcut (in my case, it is alt + F1) and the Eclipse help search will open and automatically search for the selected text.
Now I have already created a Binding-> Command-> Handler and a text in a method that returns the selected text as a string and I am stuck on how to open an Eclipse help search and query for that specific string through my code.
I searched a bit and found ISearchEngine2 from org.eclipse.help.search that could help me do what I am trying to do, but since I'm new to Eclipse plugin development I really don't know how to implement it.
Can anyone help me with this?
Currently my code looks like this:
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;
}
}
+3
source to share
1 answer