Open a sketch from the path specified. Do not use for untitled sketches. Note that the user may have selected/double-clicked any .pde in a sketch.
(String path)
| 1404 | * Note that the user may have selected/double-clicked any .pde in a sketch. |
| 1405 | */ |
| 1406 | public Editor handleOpen(String path) { |
| 1407 | if (path.startsWith("pde://")) { |
| 1408 | return handleScheme(path); |
| 1409 | } |
| 1410 | |
| 1411 | if (path.endsWith(SKETCH_BUNDLE_EXT)) { |
| 1412 | return openSketchBundle(path); |
| 1413 | |
| 1414 | } else if (path.endsWith(CONTRIB_BUNDLE_EXT)) { |
| 1415 | openContribBundle(path); |
| 1416 | return null; // never returning an Editor for a contrib |
| 1417 | } |
| 1418 | |
| 1419 | File pdeFile = new File(path); |
| 1420 | if (!pdeFile.exists()) { |
| 1421 | System.err.println(path + " does not exist"); |
| 1422 | return null; |
| 1423 | } |
| 1424 | |
| 1425 | // Cycle through open windows to make sure that it's not already open. |
| 1426 | for (Editor editor : editors) { |
| 1427 | // User may have double-clicked any PDE in the sketch folder, |
| 1428 | // so we have to check each open tab (not just the main one). |
| 1429 | // https://github.com/processing/processing/issues/2506 |
| 1430 | for (SketchCode tab : editor.getSketch().getCode()) { |
| 1431 | if (tab.getFile().equals(pdeFile)) { |
| 1432 | editor.toFront(); |
| 1433 | // move back to the top of the recent list |
| 1434 | Recent.append(editor); |
| 1435 | return editor; |
| 1436 | } |
| 1437 | } |
| 1438 | } |
| 1439 | |
| 1440 | File parentFolder = pdeFile.getParentFile(); |
| 1441 | |
| 1442 | try { |
| 1443 | // read the sketch.properties file or get an empty Settings object |
| 1444 | Settings props = Sketch.loadProperties(parentFolder); |
| 1445 | if (!props.isEmpty()) { |
| 1446 | // First check for the Mode, because it may not even be available |
| 1447 | String modeIdentifier = props.get("mode.id"); |
| 1448 | if (modeIdentifier != null) { |
| 1449 | if (modeIdentifier.equals("galsasson.mode.tweak.TweakMode")) { |
| 1450 | // Tweak Mode has been built into Processing since 2015, |
| 1451 | // but there are some old sketch.properties files out there. |
| 1452 | // https://github.com/processing/processing4/issues/415 |
| 1453 | nextMode = getDefaultMode(); |
| 1454 | |
| 1455 | // Clean up sketch.properties and re-save or remove if necessary |
| 1456 | props.remove("mode"); |
| 1457 | props.remove("mode.id"); |
| 1458 | props.reckon(); |
| 1459 | |
| 1460 | } else { |
| 1461 | // sketch.properties specifies a Mode, see if it's available |
| 1462 | Mode mode = findMode(modeIdentifier); |
| 1463 | if (mode != null) { |
no test coverage detected