Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*.jar
*.war
*.ear
/bin/
5 changes: 3 additions & 2 deletions META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
42 changes: 32 additions & 10 deletions src/dashlookup/handlers/DashLookupHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}

}