forked from combinatorial/AppCodeDashSearch
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
invoke Dash.app without resigning focus
resolves #41
- Loading branch information
Showing
3 changed files
with
63 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters