1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-17 22:23:10 +03:00

By using syntax like file://./docs/index.html, editor will open file index.html stored in folder SKETCH_FOLDER/docs/. Fixes #224

This commit is contained in:
Federico Fissore
2015-06-08 14:39:11 +02:00
parent 8465202264
commit ccd7fdc0a3
4 changed files with 59 additions and 75 deletions

View File

@ -34,11 +34,14 @@ import processing.app.legacy.PApplet;
import processing.app.legacy.PConstants;
import java.awt.*;
import java.io.*;
import java.lang.reflect.Method;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;
import java.util.*;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
@ -98,45 +101,13 @@ public class Platform extends processing.app.Platform {
public void openURL(String url) throws Exception {
if (PApplet.javaVersion < 1.6f) {
if (url.startsWith("http")) {
// formerly com.apple.eio.FileManager.openURL(url);
// but due to deprecation, instead loading dynamically
try {
Class<?> eieio = Class.forName("com.apple.eio.FileManager");
Method openMethod =
eieio.getMethod("openURL", new Class[] { String.class });
openMethod.invoke(null, new Object[] { url });
} catch (Exception e) {
e.printStackTrace();
}
} else {
// Assume this is a file instead, and just open it.
// Extension of http://dev.processing.org/bugs/show_bug.cgi?id=1010
PApplet.open(url);
}
Desktop desktop = Desktop.getDesktop();
if (url.startsWith("http") || url.startsWith("file:")) {
desktop.browse(new URI(url));
} else {
try {
Class<?> desktopClass = Class.forName("java.awt.Desktop");
Method getMethod = desktopClass.getMethod("getDesktop");
Object desktop = getMethod.invoke(null, new Object[] { });
// for Java 1.6, replacing with java.awt.Desktop.browse()
// and java.awt.Desktop.open()
if (url.startsWith("http")) { // browse to a location
Method browseMethod =
desktopClass.getMethod("browse", new Class[] { URI.class });
browseMethod.invoke(desktop, new Object[] { new URI(url) });
} else { // open a file
Method openMethod =
desktopClass.getMethod("open", new Class[] { File.class });
openMethod.invoke(desktop, new Object[] { new File(url) });
}
} catch (Exception e) {
e.printStackTrace();
}
}
desktop.open(new File(url));
}
}
public boolean openFolderAvailable() {