| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -161,7 +161,7 @@ public Base(String[] args) { | |||
| 161 | 161 | ||
| 162 | 162 | // If not path is set, get the default sketchbook folder for this platform | |
| 163 | 163 | if (sketchbookPath == null) { | |
| 164 | - File defaultFolder = Base.getDefaultSketchbookFolder(); | ||
| 164 | + File defaultFolder = getDefaultSketchbookFolder(); | ||
| 165 | 165 | Preferences.set("sketchbook.path", defaultFolder.getAbsolutePath()); | |
| 166 | 166 | if (!defaultFolder.exists()) { | |
| 167 | 167 | defaultFolder.mkdirs(); | |
@@ -310,11 +310,6 @@ public void storeSketch(Editor editor) { | |||
| 310 | 310 | // ................................................................. | |
| 311 | 311 | ||
| 312 | 312 | ||
| 313 | - static public File getSketchbookFolder() { | ||
| 314 | - return new File(Preferences.get("sketchbook.path")); | ||
| 315 | - } | ||
| 316 | - | ||
| 317 | - | ||
| 318 | 313 | // Because of variations in native windowing systems, no guarantees about | |
| 319 | 314 | // changes to the focused and active Windows can be made. Developers must | |
| 320 | 315 | // never assume that this Window is the focused or active Window until this | |
@@ -604,31 +599,6 @@ public boolean handleClose(Editor editor, boolean quitting) { | |||
| 604 | 599 | } | |
| 605 | 600 | } | |
| 606 | 601 | return true; | |
| 607 | - | ||
| 608 | - /* | ||
| 609 | - // If not canceled, check if this was the last open window. | ||
| 610 | - // If it was the last, could either do a new untitled window, | ||
| 611 | - // or could just quit the application. | ||
| 612 | - if (!quitting && (editorCount == 0)) { | ||
| 613 | - // This will store the sketch count as zero | ||
| 614 | - storeSketches(); | ||
| 615 | - | ||
| 616 | - // Save out the current prefs state | ||
| 617 | - Preferences.save(); | ||
| 618 | - | ||
| 619 | - // Clean out empty sketches | ||
| 620 | - Base.cleanSketchbook(); | ||
| 621 | - // can't do handleQuit(), would do weird recursive thing | ||
| 622 | - //handleQuit(); | ||
| 623 | - | ||
| 624 | - // Since this wasn't an actual Quit event, | ||
| 625 | - // System.exit() needs to be called for Mac OS X. | ||
| 626 | - //if (PApplet.platform == PConstants.MACOSX) { | ||
| 627 | - System.exit(0); | ||
| 628 | - //} | ||
| 629 | - } | ||
| 630 | - return true; | ||
| 631 | - */ | ||
| 632 | 602 | } | |
| 633 | 603 | ||
| 634 | 604 | ||
@@ -1088,24 +1058,15 @@ static public File createTempFolder(String name) { | |||
| 1088 | 1058 | } | |
| 1089 | 1059 | ||
| 1090 | 1060 | ||
| 1091 | - /* | ||
| 1092 | - static public void addBuildFolderToClassPath() { | ||
| 1093 | - String path = getBuildFolder().getAbsolutePath(); | ||
| 1094 | - String jcp = System.getProperty("java.class.path"); | ||
| 1095 | - if (jcp.indexOf(path) == -1) { | ||
| 1096 | - System.setProperty("java.class.path", path + File.pathSeparator + jcp); | ||
| 1097 | - //return new File(getProcessingDataFolder(), "build"); | ||
| 1098 | - System.out.println("jcp is now " + | ||
| 1099 | - System.getProperty("java.class.path")); | ||
| 1100 | - } | ||
| 1061 | + public File getSketchbookFolder() { | ||
| 1062 | + return new File(Preferences.get("sketchbook.path")); | ||
| 1101 | 1063 | } | |
| 1102 | - */ | ||
| 1103 | 1064 | ||
| 1104 | 1065 | ||
| 1105 | - static public File getDefaultSketchbookFolder() { | ||
| 1066 | + public File getDefaultSketchbookFolder() { | ||
| 1106 | 1067 | File sketchbookFolder = null; | |
| 1107 | 1068 | try { | |
| 1108 | - platform.getDefaultSketchbookFolder(); | ||
| 1069 | + sketchbookFolder = platform.getDefaultSketchbookFolder(); | ||
| 1109 | 1070 | } catch (Exception e) { } | |
| 1110 | 1071 | ||
| 1111 | 1072 | if (sketchbookFolder == null) { | |
@@ -1118,18 +1079,6 @@ static public File getDefaultSketchbookFolder() { | |||
| 1118 | 1079 | result = sketchbookFolder.mkdirs(); | |
| 1119 | 1080 | } | |
| 1120 | 1081 | ||
| 1121 | - /* | ||
| 1122 | - if (!result) { | ||
| 1123 | - // try the fallback location | ||
| 1124 | - System.out.println("Using fallback path for sketchbook."); | ||
| 1125 | - String fallback = Preferences.get("sketchbook.path.fallback"); | ||
| 1126 | - sketchbookFolder = new File(fallback); | ||
| 1127 | - if (!sketchbookFolder.exists()) { | ||
| 1128 | - result = sketchbookFolder.mkdirs(); | ||
| 1129 | - } | ||
| 1130 | - } | ||
| 1131 | - */ | ||
| 1132 | - | ||
| 1133 | 1082 | if (!result) { | |
| 1134 | 1083 | showError("You forgot your sketchbook", | |
| 1135 | 1084 | "Processing cannot run because it could not\n" + | |
@@ -1152,15 +1101,60 @@ static protected File promptSketchbookLocation() { | |||
| 1152 | 1101 | return folder; | |
| 1153 | 1102 | } | |
| 1154 | 1103 | ||
| 1155 | - folder = Base.selectFolder("Select (or create new) folder for sketches...", | ||
| 1156 | - null, null); | ||
| 1104 | + String prompt = "Select (or create new) folder for sketches..."; | ||
| 1105 | + folder = Base.selectFolder(prompt, null, null); | ||
| 1157 | 1106 | if (folder == null) { | |
| 1158 | 1107 | System.exit(0); | |
| 1159 | 1108 | } | |
| 1160 | 1109 | return folder; | |
| 1161 | 1110 | } | |
| 1162 | 1111 | ||
| 1163 | 1112 | ||
| 1113 | + // ................................................................. | ||
| 1114 | + | ||
| 1115 | + | ||
| 1116 | + /** | ||
| 1117 | + * Implements the cross-platform headache of opening URLs | ||
| 1118 | + * TODO This code should be replaced by PApplet.link(), | ||
| 1119 | + * however that's not a static method (because it requires | ||
| 1120 | + * an AppletContext when used as an applet), so it's mildly | ||
| 1121 | + * trickier than just removing this method. | ||
| 1122 | + */ | ||
| 1123 | + static public void openURL(String url) { | ||
| 1124 | + try { | ||
| 1125 | + platform.openURL(url); | ||
| 1126 | + | ||
| 1127 | + } catch (Exception e) { | ||
| 1128 | + showWarning("Problem Opening URL", | ||
| 1129 | + "Could not open the URL\n" + url, e); | ||
| 1130 | + } | ||
| 1131 | + } | ||
| 1132 | + | ||
| 1133 | + | ||
| 1134 | + /** | ||
| 1135 | + * Used to determine whether to disable the "Show Sketch Folder" option. | ||
| 1136 | + * @return true If a means of opening a folder is known to be available. | ||
| 1137 | + */ | ||
| 1138 | + static boolean openFolderAvailable() { | ||
| 1139 | + return platform.openFolderAvailable(); | ||
| 1140 | + } | ||
| 1141 | + | ||
| 1142 | + | ||
| 1143 | + /** | ||
| 1144 | + * Implements the other cross-platform headache of opening | ||
| 1145 | + * a folder in the machine's native file browser. | ||
| 1146 | + */ | ||
| 1147 | + static public void openFolder(File file) { | ||
| 1148 | + try { | ||
| 1149 | + platform.openFolder(file); | ||
| 1150 | + | ||
| 1151 | + } catch (Exception e) { | ||
| 1152 | + showWarning("Problem Opening Folder", | ||
| 1153 | + "Could not open the folder\n" + file.getAbsolutePath(), e); | ||
| 1154 | + } | ||
| 1155 | + } | ||
| 1156 | + | ||
| 1157 | + | ||
| 1164 | 1158 | // ................................................................. | |
| 1165 | 1159 | ||
| 1166 | 1160 | ||
@@ -1289,167 +1283,10 @@ static public void showTroubleshooting() { | |||
| 1289 | 1283 | showReference("troubleshooting" + File.separator + "index.html"); | |
| 1290 | 1284 | } | |
| 1291 | 1285 | ||
| 1292 | - | ||
| 1286 | + | ||
| 1293 | 1287 | // ................................................................. | |
| 1294 | 1288 | ||
| 1295 | 1289 | ||
| 1296 | - /** | ||
| 1297 | - * Implements the cross-platform headache of opening URLs | ||
| 1298 | - * TODO This code should be replaced by PApplet.link(), | ||
| 1299 | - * however that's not a static method (because it requires | ||
| 1300 | - * an AppletContext when used as an applet), so it's mildly | ||
| 1301 | - * trickier than just removing this method. | ||
| 1302 | - */ | ||
| 1303 | - static public void openURL(String url) { | ||
| 1304 | - //System.out.println("opening url " + url); | ||
| 1305 | - try { | ||
| 1306 | - if (Base.isWindows()) { | ||
| 1307 | - // this is not guaranteed to work, because who knows if the | ||
| 1308 | - // path will always be c:\progra~1 et al. also if the user has | ||
| 1309 | - // a different browser set as their default (which would | ||
| 1310 | - // include me) it'd be annoying to be dropped into ie. | ||
| 1311 | - //Runtime.getRuntime().exec("c:\\progra~1\\intern~1\\iexplore " | ||
| 1312 | - // + currentDir | ||
| 1313 | - | ||
| 1314 | - // the following uses a shell execute to launch the .html file | ||
| 1315 | - // note that under cygwin, the .html files have to be chmodded +x | ||
| 1316 | - // after they're unpacked from the zip file. i don't know why, | ||
| 1317 | - // and don't understand what this does in terms of windows | ||
| 1318 | - // permissions. without the chmod, the command prompt says | ||
| 1319 | - // "Access is denied" in both cygwin and the "dos" prompt. | ||
| 1320 | - //Runtime.getRuntime().exec("cmd /c " + currentDir + "\\reference\\" + | ||
| 1321 | - // referenceFile + ".html"); | ||
| 1322 | - if (url.startsWith("http://")) { | ||
| 1323 | - // open dos prompt, give it 'start' command, which will | ||
| 1324 | - // open the url properly. start by itself won't work since | ||
| 1325 | - // it appears to need cmd | ||
| 1326 | - Runtime.getRuntime().exec("cmd /c start " + url); | ||
| 1327 | - } else { | ||
| 1328 | - // just launching the .html file via the shell works | ||
| 1329 | - // but make sure to chmod +x the .html files first | ||
| 1330 | - // also place quotes around it in case there's a space | ||
| 1331 | - // in the user.dir part of the url | ||
| 1332 | - Runtime.getRuntime().exec("cmd /c \"" + url + "\""); | ||
| 1333 | - } | ||
| 1334 | - | ||
| 1335 | - } else if (Base.isMacOS()) { | ||
| 1336 | - //com.apple.eio.FileManager.openURL(url); | ||
| 1337 | - | ||
| 1338 | - if (!url.startsWith("http://")) { | ||
| 1339 | - // prepend file:// on this guy since it's a file | ||
| 1340 | - url = "file://" + url; | ||
| 1341 | - | ||
| 1342 | - // replace spaces with %20 for the file url | ||
| 1343 | - // otherwise the mac doesn't like to open it | ||
| 1344 | - // can't just use URLEncoder, since that makes slashes into | ||
| 1345 | - // %2F characters, which is no good. some might say "useless" | ||
| 1346 | - if (url.indexOf(' ') != -1) { | ||
| 1347 | - StringBuffer sb = new StringBuffer(); | ||
| 1348 | - char c[] = url.toCharArray(); | ||
| 1349 | - for (int i = 0; i < c.length; i++) { | ||
| 1350 | - if (c[i] == ' ') { | ||
| 1351 | - sb.append("%20"); | ||
| 1352 | - } else { | ||
| 1353 | - sb.append(c[i]); | ||
| 1354 | - } | ||
| 1355 | - } | ||
| 1356 | - url = sb.toString(); | ||
| 1357 | - } | ||
| 1358 | - } | ||
| 1359 | - com.apple.eio.FileManager.openURL(url); | ||
| 1360 | - | ||
| 1361 | - } else if (Base.isLinux()) { | ||
| 1362 | - // how's mozilla sound to ya, laddie? | ||
| 1363 | - //Runtime.getRuntime().exec(new String[] { "mozilla", url }); | ||
| 1364 | - //String browser = Preferences.get("browser"); | ||
| 1365 | - //Runtime.getRuntime().exec(new String[] { browser, url }); | ||
| 1366 | - String launcher = Preferences.get("launcher.linux"); | ||
| 1367 | - if (launcher != null) { | ||
| 1368 | - Runtime.getRuntime().exec(new String[] { launcher, url }); | ||
| 1369 | - } | ||
| 1370 | - } else { | ||
| 1371 | - String launcher = Preferences.get("launcher"); | ||
| 1372 | - if (launcher != null) { | ||
| 1373 | - Runtime.getRuntime().exec(new String[] { launcher, url }); | ||
| 1374 | - } else { | ||
| 1375 | - System.err.println("Unspecified platform, no launcher available."); | ||
| 1376 | - } | ||
| 1377 | - } | ||
| 1378 | - | ||
| 1379 | - } catch (IOException e) { | ||
| 1380 | - Base.showWarning("Could not open URL", | ||
| 1381 | - "An error occurred while trying to open\n" + url, e); | ||
| 1382 | - } | ||
| 1383 | - } | ||
| 1384 | - | ||
| 1385 | - | ||
| 1386 | - /** | ||
| 1387 | - * Used to determine whether to disable the "Show Sketch Folder" option. | ||
| 1388 | - * @return true If a means of opening a folder is known to be available. | ||
| 1389 | - */ | ||
| 1390 | - static boolean openFolderAvailable() { | ||
| 1391 | - if (Base.isWindows() || Base.isMacOS()) return true; | ||
| 1392 | - | ||
| 1393 | - if (Base.isLinux()) { | ||
| 1394 | - // Assume that this is set to something valid | ||
| 1395 | - if (Preferences.get("launcher.linux") != null) { | ||
| 1396 | - return true; | ||
| 1397 | - } | ||
| 1398 | - | ||
| 1399 | - // Attempt to use gnome-open | ||
| 1400 | - try { | ||
| 1401 | - Process p = Runtime.getRuntime().exec(new String[] { "gnome-open" }); | ||
| 1402 | - /*int result =*/ p.waitFor(); | ||
| 1403 | - // Not installed will throw an IOException (JDK 1.4.2, Ubuntu 7.04) | ||
| 1404 | - Preferences.set("launcher.linux", "gnome-open"); | ||
| 1405 | - return true; | ||
| 1406 | - } catch (Exception e) { } | ||
| 1407 | - | ||
| 1408 | - // Attempt with kde-open | ||
| 1409 | - try { | ||
| 1410 | - Process p = Runtime.getRuntime().exec(new String[] { "kde-open" }); | ||
| 1411 | - /*int result =*/ p.waitFor(); | ||
| 1412 | - Preferences.set("launcher.linux", "kde-open"); | ||
| 1413 | - return true; | ||
| 1414 | - } catch (Exception e) { } | ||
| 1415 | - } | ||
| 1416 | - return false; | ||
| 1417 | - } | ||
| 1418 | - | ||
| 1419 | - | ||
| 1420 | - /** | ||
| 1421 | - * Implements the other cross-platform headache of opening | ||
| 1422 | - * a folder in the machine's native file browser. | ||
| 1423 | - */ | ||
| 1424 | - static public void openFolder(File file) { | ||
| 1425 | - try { | ||
| 1426 | - String folder = file.getAbsolutePath(); | ||
| 1427 | - | ||
| 1428 | - if (Base.isWindows()) { | ||
| 1429 | - // doesn't work | ||
| 1430 | - //Runtime.getRuntime().exec("cmd /c \"" + folder + "\""); | ||
| 1431 | - | ||
| 1432 | - // works fine on winxp, prolly win2k as well | ||
| 1433 | - Runtime.getRuntime().exec("explorer \"" + folder + "\""); | ||
| 1434 | - | ||
| 1435 | - // not tested | ||
| 1436 | - //Runtime.getRuntime().exec("start explorer \"" + folder + "\""); | ||
| 1437 | - | ||
| 1438 | - } else if (Base.isMacOS()) { | ||
| 1439 | - openURL(folder); // handles char replacement, etc | ||
| 1440 | - | ||
| 1441 | - } else if (Base.isLinux()) { | ||
| 1442 | - String launcher = Preferences.get("launcher.linux"); | ||
| 1443 | - if (launcher != null) { | ||
| 1444 | - Runtime.getRuntime().exec(new String[] { launcher, folder }); | ||
| 1445 | - } | ||
| 1446 | - } | ||
| 1447 | - } catch (IOException e) { | ||
| 1448 | - e.printStackTrace(); | ||
| 1449 | - } | ||
| 1450 | - } | ||
| 1451 | - | ||
| 1452 | - | ||
| 1453 | 1290 | /** | |
| 1454 | 1291 | * "No cookie for you" type messages. Nothing fatal or all that | |
| 1455 | 1292 | * much of a bummer, but something to notify the user about. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -79,12 +79,50 @@ public File getSettingsFolder() throws Exception { | |||
| 79 | 79 | */ | |
| 80 | 80 | } | |
| 81 | 81 | ||
| 82 | - | ||
| 82 | + | ||
| 83 | 83 | /** | |
| 84 | 84 | * @return null if not overridden, which will cause a prompt to show instead. | |
| 85 | 85 | * @throws Exception | |
| 86 | 86 | */ | |
| 87 | 87 | public File getDefaultSketchbookFolder() throws Exception { | |
| 88 | 88 | return null; | |
| 89 | 89 | } | |
| 90 | + | ||
| 91 | + | ||
| 92 | + public void openURL(String url) throws Exception { | ||
| 93 | + String launcher = Preferences.get("launcher"); | ||
| 94 | + if (launcher != null) { | ||
| 95 | + Runtime.getRuntime().exec(new String[] { launcher, url }); | ||
| 96 | + } else { | ||
| 97 | + showLauncherWarning(); | ||
| 98 | + } | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + | ||
| 102 | + public boolean openFolderAvailable() { | ||
| 103 | + return Preferences.get("launcher") != null; | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + | ||
| 107 | + public void openFolder(File file) throws Exception { | ||
| 108 | + String launcher = Preferences.get("launcher"); | ||
| 109 | + if (launcher != null) { | ||
| 110 | + String folder = file.getAbsolutePath(); | ||
| 111 | + Runtime.getRuntime().exec(new String[] { launcher, folder }); | ||
| 112 | + } else { | ||
| 113 | + showLauncherWarning(); | ||
| 114 | + } | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + | ||
| 118 | + // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | ||
| 119 | + | ||
| 120 | + | ||
| 121 | + protected void showLauncherWarning() { | ||
| 122 | + Base.showWarning("No launcher available", | ||
| 123 | + "Unspecified platform, no launcher available.\n" + | ||
| 124 | + "To enable opening URLs or folders, add a \n" + | ||
| 125 | + "\"launcher=/path/to/app\" line to preferences.txt", | ||
| 126 | + null); | ||
| 127 | + } | ||
| 90 | 128 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments