diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index f4cea1d3d..c6df10207 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -1006,7 +1006,7 @@ public class Editor extends JFrame implements RunnerListener { @Override public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) { try { - platform.openURL(hyperlinkEvent.getURL().toExternalForm()); + platform.openURL(sketch.getFolder(), hyperlinkEvent.getURL().toExternalForm()); } catch (Exception e) { Base.showWarning(e.getMessage(), e.getMessage(), e); } diff --git a/arduino-core/src/processing/app/Platform.java b/arduino-core/src/processing/app/Platform.java index b2deee2f8..1d39b27eb 100644 --- a/arduino-core/src/processing/app/Platform.java +++ b/arduino-core/src/processing/app/Platform.java @@ -29,8 +29,12 @@ import processing.app.debug.TargetPlatform; import processing.app.legacy.PConstants; import javax.swing.*; -import java.io.*; -import java.util.*; +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; import static processing.app.I18n._; @@ -38,42 +42,42 @@ import static processing.app.I18n._; /** * Used by Base for platform-specific tweaking, for instance finding the * sketchbook location using the Windows registry, or OS X event handling. - * - * The methods in this implementation are used by default, and can be - * overridden by a subclass, if loaded by Base.main(). - * + *
+ * The methods in this implementation are used by default, and can be + * overridden by a subclass, if loaded by Base.main(). + * * These methods throw vanilla-flavored Exceptions, so that error handling - * occurs inside Base. - * - * There is currently no mechanism for adding new platforms, as the setup is - * not automated. We could use getProperty("os.arch") perhaps, but that's - * debatable (could be upper/lowercase, have spaces, etc.. basically we don't + * occurs inside Base. + * + * There is currently no mechanism for adding new platforms, as the setup is + * not automated. We could use getProperty("os.arch") perhaps, but that's + * debatable (could be upper/lowercase, have spaces, etc.. basically we don't * know if name is proper Java package syntax.) */ public class Platform { - - + + /** * Set the default L & F. While I enjoy the bounty of the sixteen possible - * exception types that this UIManager method might throw, I feel that in + * exception types that this UIManager method might throw, I feel that in * just this one particular case, I'm being spoiled by those engineers * at Sun, those Masters of the Abstractionverse. It leaves me feeling sad * and overweight. So instead, I'll pretend that I'm not offered eleven dozen * ways to report to the user exactly what went wrong, and I'll bundle them - * all into a single catch-all "Exception". Because in the end, all I really + * all into a single catch-all "Exception". Because in the end, all I really * care about is whether things worked or not. And even then, I don't care. - * + * * @throws Exception Just like I said. */ public void setLookAndFeel() throws Exception { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } - - + + public void init() throws IOException { } - - + + public File getSettingsFolder() throws Exception { // otherwise make a .processing directory int the user's home dir File home = new File(System.getProperty("user.home")); @@ -95,37 +99,46 @@ public class Platform { } */ } - + /** - * @return null if not overridden, which will cause a prompt to show instead. + * @return null if not overridden, which will cause a prompt to show instead. * @throws Exception */ public File getDefaultSketchbookFolder() throws Exception { return null; } - - + + public void openURL(File folder, String url) throws Exception { + if (!url.startsWith("file://./")) { + openURL(url); + return; + } + + url = url.replaceAll("file://./", folder.getCanonicalFile().toURI().toASCIIString()); + openURL(url); + } + public void openURL(String url) throws Exception { String launcher = PreferencesData.get("launcher"); if (launcher != null) { - Runtime.getRuntime().exec(new String[] { launcher, url }); + Runtime.getRuntime().exec(new String[]{launcher, url}); } else { showLauncherWarning(); - } + } } public boolean openFolderAvailable() { return PreferencesData.get("launcher") != null; } - - + + public void openFolder(File file) throws Exception { String launcher = PreferencesData.get("launcher"); if (launcher != null) { String folder = file.getAbsolutePath(); - Runtime.getRuntime().exec(new String[] { launcher, folder }); + Runtime.getRuntime().exec(new String[]{launcher, folder}); } else { showLauncherWarning(); } @@ -184,14 +197,14 @@ public class Platform { return PConstants.platformNames[PConstants.OTHER]; } - + // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . protected void showLauncherWarning() { - BaseNoGui.showWarning(_("No launcher available"), - _("Unspecified platform, no launcher available.\nTo enable opening URLs or folders, add a \n\"launcher=/path/to/app\" line to preferences.txt"), - null); + BaseNoGui.showWarning(_("No launcher available"), + _("Unspecified platform, no launcher available.\nTo enable opening URLs or folders, add a \n\"launcher=/path/to/app\" line to preferences.txt"), + null); } public List