Skip to content

Commit

Permalink
invoke Dash.app without resigning focus
Browse files Browse the repository at this point in the history
resolves #41
  • Loading branch information
gdelmas committed Apr 12, 2015
1 parent a7dc4e4 commit a9037d3
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/de/dreamlab/dash/launcher/AbstractLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ public abstract class AbstractLauncher {

public static AbstractLauncher createInstance()
{
if ( SystemUtil.isIsOSLinux() ) {
if ( SystemUtil.isIsOSMac() ) {
return new DashLauncher();
}
else if ( SystemUtil.isIsOSLinux() ) {
return new ZealLauncher();
}
else {
return new DashSchemeLauncher();
return new DashPluginSchemeLauncher();
}
}

Expand Down
56 changes: 56 additions & 0 deletions src/de/dreamlab/dash/launcher/DashLauncher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Created by gerard on 12.04.15.
*/

package de.dreamlab.dash.launcher;

import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;

import java.awt.*;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.util.List;

public class DashLauncher extends AbstractLauncher {

public void search(List<String> keywords, String query)
{
try {
String request = "dash-plugin://";

// keywords
if ( keywords.size() > 0 ) {
request += "keys=" + keywordString(keywords) + "&";
}

// query
request += "query=" + urlEncode(query);

openUri(request);
}
catch ( Throwable e ) {
Notifications.Bus.notify(new Notification("Dash Plugin Error", "Dash Plugin Error", e.getMessage(), NotificationType.ERROR));
}
}

private void openUri(String uriStr) throws ExecutionException
{
final GeneralCommandLine commandLine = new GeneralCommandLine("open");
commandLine.addParameter("-g");
commandLine.addParameter(uriStr);
commandLine.createProcess();
}

private String urlEncode(String s) throws UnsupportedEncodingException
{
return URLEncoder.encode(s, "UTF-8").replace("+", "%20");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import java.net.URLEncoder;
import java.util.List;

public class DashSchemeLauncher extends AbstractLauncher {
public class DashPluginSchemeLauncher extends AbstractLauncher {

public DashSchemeLauncher() {
public DashPluginSchemeLauncher() {
}

public void search(List<String> keywords, String query)
Expand Down

0 comments on commit a9037d3

Please sign in to comment.