mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
platform-wide protocol handler
This commit is contained in:
@@ -327,6 +327,29 @@ binding.setVariable("layoutMacApp", { String path, String ch, Map args ->
|
||||
|
||||
String classPath = classPathLibs.collect {"\$APP_PACKAGE/lib/${it}" }.join(":")
|
||||
|
||||
String urlSchemes = ""
|
||||
if (args.urlSchemes != null) {
|
||||
urlSchemes += """
|
||||
<key>CFBundleURLTypes</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>Editor</string>
|
||||
<key>CFBundleURLName</key>
|
||||
<string>Stacktrace</string>
|
||||
<key>CFBundleURLSchemes</key>
|
||||
<array>
|
||||
"""
|
||||
args.urlSchemes.each { scheme ->
|
||||
urlSchemes += " <string>${scheme}</string>"
|
||||
}
|
||||
urlSchemes += """
|
||||
</array>
|
||||
</dict>
|
||||
</array>
|
||||
"""
|
||||
}
|
||||
|
||||
ant.replace(file: "$path/Contents/Info.plist") {
|
||||
replacefilter(token: "@@build@@", value: args.buildNumber)
|
||||
replacefilter(token: "@@doc_types@@", value: ifNull(args.doc_types, ""))
|
||||
@@ -340,7 +363,7 @@ binding.setVariable("layoutMacApp", { String path, String ch, Map args ->
|
||||
replacefilter(token: "@@idea_properties@@", value: coreProperties)
|
||||
replacefilter(token: "@@class_path@@", value: classPath)
|
||||
replacefilter(token: "@@help_id@@", value: helpId)
|
||||
replacefilter(token: "@@url_schemes@@", value: ifNull(args.urlSchemes, ""))
|
||||
replacefilter(token: "@@url_schemes@@", value: urlSchemes)
|
||||
}
|
||||
|
||||
if (executable != "idea") {
|
||||
|
||||
@@ -16,26 +16,17 @@
|
||||
package com.intellij.ui;
|
||||
|
||||
import com.intellij.ide.CommandLineProcessor;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.util.io.URLUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Dennis.Ushakov
|
||||
*/
|
||||
public abstract class CustomProtocolHandler {
|
||||
public static final ExtensionPointName<CustomProtocolHandler> EP_NAME = ExtensionPointName.create("com.intellij.customProtocolHandler");
|
||||
private final String myScheme;
|
||||
|
||||
protected CustomProtocolHandler(String scheme) {
|
||||
myScheme = scheme;
|
||||
}
|
||||
|
||||
public class CustomProtocolHandler {
|
||||
public boolean openLink(@NotNull URI uri) {
|
||||
final List<String> args = getOpenArgs(uri);
|
||||
return !args.isEmpty() && CommandLineProcessor.processExternalCommandLine(args, null) != null;
|
||||
@@ -44,40 +35,30 @@ public abstract class CustomProtocolHandler {
|
||||
@NotNull
|
||||
public List<String> getOpenArgs(URI uri) {
|
||||
final List<String> args = new ArrayList<String>();
|
||||
if (myScheme.equals(uri.getScheme())) {
|
||||
final String query = uri.getQuery();
|
||||
String file = null;
|
||||
String line = null;
|
||||
if (query != null) {
|
||||
for (String param : query.split("&")) {
|
||||
String[] pair = param.split("=");
|
||||
String key = decode(pair[0]);
|
||||
if (pair.length > 1) {
|
||||
if ("file".equals(key)) {
|
||||
file = decode(pair[1]);
|
||||
} else if ("line".equals(key)) {
|
||||
line = decode(pair[1]);
|
||||
}
|
||||
final String query = uri.getQuery();
|
||||
String file = null;
|
||||
String line = null;
|
||||
if (query != null) {
|
||||
for (String param : query.split("&")) {
|
||||
String[] pair = param.split("=");
|
||||
String key = URLUtil.unescapePercentSequences(pair[0]);
|
||||
if (pair.length > 1) {
|
||||
if ("file".equals(key)) {
|
||||
file = URLUtil.unescapePercentSequences(pair[1]);
|
||||
} else if ("line".equals(key)) {
|
||||
line = URLUtil.unescapePercentSequences(pair[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (file != null) {
|
||||
}
|
||||
|
||||
if (line != null) {
|
||||
args.add("--line");
|
||||
args.add(line);
|
||||
}
|
||||
args.add(file);
|
||||
if (file != null) {
|
||||
if (line != null) {
|
||||
args.add("--line");
|
||||
args.add(line);
|
||||
}
|
||||
args.add(file);
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
private static String decode(String s) {
|
||||
try {
|
||||
return URLDecoder.decode(s, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +111,7 @@ public class MacMainFrameDecorator implements UISettingsListener, Disposable {
|
||||
|
||||
private static Runnable CURRENT_SETTER = null;
|
||||
private static Function<Object, Boolean> CURRENT_GETTER = null;
|
||||
private static CustomProtocolHandler ourProtocolHandler = null;
|
||||
|
||||
private boolean myInFullScreen;
|
||||
private IdeFrameImpl myFrame;
|
||||
@@ -206,23 +207,22 @@ public class MacMainFrameDecorator implements UISettingsListener, Disposable {
|
||||
invoke(pool, "release");
|
||||
}
|
||||
|
||||
// install uri handler
|
||||
final ID mainBundle = invoke("NSBundle", "mainBundle");
|
||||
final ID urlTypes = invoke(mainBundle, "objectForInfoDictionaryKey:", Foundation.nsString("CFBundleURLTypes"));
|
||||
if (urlTypes.equals(ID.NIL)) {
|
||||
LOG.warn("no url bundle present");
|
||||
return;
|
||||
}
|
||||
Application.getApplication().setOpenURIHandler(new OpenURIHandler() {
|
||||
if (ourProtocolHandler == null) {
|
||||
// install uri handler
|
||||
final ID mainBundle = invoke("NSBundle", "mainBundle");
|
||||
final ID urlTypes = invoke(mainBundle, "objectForInfoDictionaryKey:", Foundation.nsString("CFBundleURLTypes"));
|
||||
if (urlTypes.equals(ID.NIL)) {
|
||||
LOG.warn("no url bundle present");
|
||||
return;
|
||||
}
|
||||
ourProtocolHandler = new CustomProtocolHandler();
|
||||
Application.getApplication().setOpenURIHandler(new OpenURIHandler() {
|
||||
@Override
|
||||
public void openURI(AppEvent.OpenURIEvent event) {
|
||||
for (CustomProtocolHandler handler : CustomProtocolHandler.EP_NAME.getExtensions()) {
|
||||
if (handler.openLink(event.getURI())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
ourProtocolHandler.openLink(event.getURI());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
|
||||
@@ -167,7 +167,6 @@
|
||||
<extensionPoint name="statistics.usagesCollector" interface="com.intellij.internal.statistic.UsagesCollector"/>
|
||||
|
||||
<extensionPoint name="xmlRpcHandler" beanClass="com.intellij.ide.XmlRpcHandlerBean"/>
|
||||
<extensionPoint name="customProtocolHandler" interface="com.intellij.ui.CustomProtocolHandler"/>
|
||||
|
||||
<extensionPoint name="editorHighlighterProvider" beanClass="com.intellij.openapi.fileTypes.FileTypeExtensionPoint">
|
||||
<with attribute="implementationClass" implements="com.intellij.openapi.fileTypes.EditorHighlighterProvider"/>
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.intellij.ui;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Dennis.Ushakov
|
||||
*/
|
||||
public class CustomProtocolHandlerTest extends TestCase {
|
||||
public void testOpenOurLink() throws URISyntaxException, MalformedURLException {
|
||||
final URI uri = new URI("x-mine://open?file=/Users/denofevil/RubymineProjects/JRubyRails/app/assets/javascripts/application.js.coffee&line=2");
|
||||
final List<String> args = new CustomProtocolHandler().getOpenArgs(uri);
|
||||
assertTrue(args.contains("--line"));
|
||||
assertTrue(args.contains("2"));
|
||||
assertTrue(args.contains("/Users/denofevil/RubymineProjects/JRubyRails/app/assets/javascripts/application.js.coffee"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user