@@ -1207,7 +1207,7 @@ public void handleNew() {
1207
1207
}
1208
1208
1209
1209
String path = newbieFile .getAbsolutePath ();
1210
- handleOpen (path , true );
1210
+ handleOpenUntitled (path );
1211
1211
1212
1212
} catch (IOException e ) {
1213
1213
Messages .showWarning ("That's new to me" ,
@@ -1307,7 +1307,7 @@ private Editor openSketchBundle(String path) {
1307
1307
if (fileList .length == 1 ) {
1308
1308
File sketchFile = Sketch .findMain (fileList [0 ], getModeList ());
1309
1309
if (sketchFile != null ) {
1310
- return handleOpen (sketchFile .getAbsolutePath (), true );
1310
+ return handleOpenUntitled (sketchFile .getAbsolutePath ());
1311
1311
}
1312
1312
} else {
1313
1313
System .err .println ("Expecting one folder inside " +
@@ -1441,6 +1441,7 @@ private File moveLikeSketchFolder(File pdeFile, String baseName) throws IOExcept
1441
1441
return null ;
1442
1442
}
1443
1443
1444
+
1444
1445
/**
1445
1446
* Open a sketch from the path specified. Do not use for untitled sketches.
1446
1447
* Note that the user may have selected/double-clicked any .pde in a sketch.
@@ -1516,11 +1517,11 @@ public Editor handleOpen(String path) {
1516
1517
// for now, post a warning if the main was different
1517
1518
System .out .println (path + " selected, but main is " + mainPath );
1518
1519
}
1519
- return handleOpen (mainPath , false );
1520
+ return handleOpenInternal (mainPath , false );
1520
1521
1521
1522
} else {
1522
1523
// if no main specified, use the passed-in path as the main
1523
- return handleOpen (path , false );
1524
+ return handleOpenInternal (path , false );
1524
1525
}
1525
1526
} else {
1526
1527
// No properties file, so do some checks to make sure the file
@@ -1603,7 +1604,7 @@ public Editor handleOpen(String path) {
1603
1604
nextMode = mode;
1604
1605
}
1605
1606
*/
1606
- handleOpen (pdeFile .getAbsolutePath (), false );
1607
+ handleOpenInternal (pdeFile .getAbsolutePath (), false );
1607
1608
}
1608
1609
} catch (IOException e ) {
1609
1610
Messages .showWarning ("sketch.properties" ,
@@ -1614,84 +1615,36 @@ public Editor handleOpen(String path) {
1614
1615
1615
1616
1616
1617
/**
1617
- * Open a sketch in a new window.
1618
- * @param path Path to the pde file for the sketch in question
1619
- * @return the Editor object, so that properties (like 'untitled')
1620
- * can be set by the caller
1618
+ * Open a (vetted) sketch location using a particular Mode. Used by the
1619
+ * Examples window, because Modes like Python and Android do not have
1620
+ * "sketch.properties" files in each example folder.
1621
1621
*/
1622
- protected Editor handleOpen (String path , boolean untitled ) {
1623
- return handleOpen (path , untitled , EditorState .nextEditor (editors ));
1622
+ public Editor handleOpen (String path , Mode mode ) {
1623
+ nextMode = mode ;
1624
+ return handleOpenInternal (path , false );
1624
1625
}
1625
1626
1626
1627
1627
- protected Editor handleOpen (String path , boolean untitled ,
1628
- EditorState state ) {
1629
- /*
1630
- return handleOpen(path, untitled, state, nextMode);
1628
+ /**
1629
+ * Open the sketch associated with this .pde file in a new window
1630
+ * as an "Untitled" sketch.
1631
+ * @param path Path to the pde file for the sketch in question
1632
+ * @return the Editor object, so that properties (like 'untitled')
1633
+ * can be set by the caller
1634
+ */
1635
+ protected Editor handleOpenUntitled (String path ) {
1636
+ return handleOpenInternal (path , true );
1631
1637
}
1632
1638
1633
- protected Editor handleOpen(String path, boolean untitled,
1634
- EditorState state, Mode mode) {
1635
- try {
1636
- final File file = new File(path);
1637
- if (!file.exists()) {
1638
- return null;
1639
- }
1640
-
1641
- // Cycle through open windows to make sure that it's not already open.
1642
- for (Editor editor : editors) {
1643
- // User may have double-clicked any PDE in the sketch folder,
1644
- // so we have to check each open tab (not just the main one).
1645
- // https://github.com/processing/processing/issues/2506
1646
- for (SketchCode tab : editor.getSketch().getCode()) {
1647
- if (tab.getFile().equals(file)) {
1648
- editor.toFront();
1649
- // move back to the top of the recent list
1650
- Recent.append(editor);
1651
- return editor;
1652
- }
1653
- }
1654
- }
1655
-
1656
- // read the sketch.properties file if it exists
1657
- File parentFolder = new File(path).getParentFile();
1658
- Settings props = loadSketchProperties(parentFolder);
1659
-
1660
- // if the Mode is set in this file, use that to determine next
1661
- if (props != null) {
1662
- String modeIdentifier = props.get("mode.id");
1663
- if (modeIdentifier != null) {
1664
- Mode mode = findMode(modeIdentifier);
1665
- if (mode != null) {
1666
- nextMode = mode;
1667
- } else {
1668
- Messages.showWarning("Missing Mode",
1669
- "You must first install " + props.get("mode") + " Mode to use this sketch.");
1670
- ContributionManager.openModes();
1671
- return null;
1672
- }
1673
- }
1674
- }
1675
-
1676
- if (!Sketch.isSanitaryName(file.getName())) {
1677
- Messages.showWarning("You're tricky, but not tricky enough",
1678
- file.getName() + " is not a valid name for a sketch.\n" +
1679
- "Better to stick to ASCII, no spaces, and make sure\n" +
1680
- "it doesn't start with a number.", null);
1681
- return null;
1682
- }
1683
-
1684
- if (!nextMode.canEdit(file)) {
1685
- final Mode mode = selectMode(file);
1686
- if (mode == null) {
1687
- return null;
1688
- }
1689
- nextMode = mode;
1690
- }
1691
- */
1692
1639
1640
+ /**
1641
+ * Internal function to actually open the sketch. At this point, the
1642
+ * sketch file/folder must have been vetted, and nextMode set properly.
1643
+ */
1644
+ protected Editor handleOpenInternal (String path , boolean untitled ) {
1693
1645
try {
1694
1646
try {
1647
+ EditorState state = EditorState .nextEditor (editors );
1695
1648
Editor editor = nextMode .createEditor (this , path , state );
1696
1649
1697
1650
// opened successfully, let's go to work
0 commit comments