diff --git a/.gitignore b/.gitignore index de63549..939767f 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ *.jar *.war *.ear +/bin/ diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF index 83c3179..278e1c6 100644 --- a/META-INF/MANIFEST.MF +++ b/META-INF/MANIFEST.MF @@ -2,11 +2,12 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: DashLookup Bundle-SymbolicName: com.jkb.dashlookup;singleton:=true -Bundle-Version: 1.0.5 +Bundle-Version: 1.0.6 Bundle-Activator: dashlookup.Activator Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Import-Package: org.eclipse.jface.text +Import-Package: org.eclipse.jface.text, + org.eclipse.ui.texteditor Bundle-Vendor: Quaerendo Games diff --git a/README.md b/README.md index eda9afc..af068fa 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,9 @@ Eclipse plugin to enable lookups in Dash.app for selected text # Instructions -Clone, import the project into Eclipse workspace, export it as deployable plugin and choose install into host. - -After restarting, under Keys in preferences, bind the "Lookup in Dash" command to whatever you desire. +* Clone or download this repo +* Import the project into Eclipse workspace (File > Import > General > Existing Projects into Workspace) +* Export it as deployable plugin (File > Export > Plug-in Development > Deployable Plug-ins and Fragments) and choose install into host + * Note: If you don't see a "Plug-in Development" option in File > Export, you need to install the "Eclipse Plug-in Development Environment" which can be done by going to Help > Install New Software > General Purpose Tools > Eclipse Plug-in Development Environment +* Restart Eclipse +* Go to Preferences > General > Keys and bind the "Lookup in Dash" command to whatever you desire diff --git a/src/dashlookup/handlers/DashLookupHandler.java b/src/dashlookup/handlers/DashLookupHandler.java index 63146a6..01b3fb6 100644 --- a/src/dashlookup/handlers/DashLookupHandler.java +++ b/src/dashlookup/handlers/DashLookupHandler.java @@ -3,12 +3,12 @@ import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.program.Program; import org.eclipse.ui.ISelectionService; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.handlers.HandlerUtil; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.ISelection; /** * Our sample handler extends AbstractHandler, an IHandler base class. @@ -29,16 +29,38 @@ public DashLookupHandler() { @Override public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); - ISelectionService service = window.getSelectionService(); - if (service != null) { - ISelection selection = service.getSelection(); - if (selection instanceof ITextSelection) { - String selectedText = ((ITextSelection) selection).getText(); - if (!selectedText.isEmpty()) - Program.launch("dash://" + selectedText); - } + String selectedText = getSelectedText(window); + + if (selectedText.isEmpty() && window.getActivePage() != null) { + selectedText = getTextFromSelection(window.getActivePage().getSelection()); + } + + if (!selectedText.isEmpty()) { + Program.launch("dash://" + selectedText); } + return null; } + + private String getTextFromSelection(ISelection selection) { + String selectedText = ""; + if (selection instanceof ITextSelection) { + selectedText = ((ITextSelection) selection).getText(); + } + + return selectedText; + } + + private String getSelectedText(IWorkbenchWindow window) { + String selectedText = ""; + final ISelectionService service = window.getSelectionService(); + + if (service != null) { + selectedText = getTextFromSelection(service.getSelection()); + } + + return selectedText; + } + }