diff --git a/.idea/misc.xml b/.idea/misc.xml index 43b1638895..81750cd50f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,7 +1,7 @@ - + \ No newline at end of file diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index b5aa599b98..5eaa1b2c09 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -563,9 +563,31 @@ public Base(String[] args) throws Exception { // Create a new empty window (will be replaced with any files to be opened) if (!opened) { - Messages.log("Calling handleNew() to open a new window"); - handleNew(); - } else { + System.out.println("Preferences file location: " + Base.getSettingsFile("preferences.txt").getAbsolutePath()); + String lastPath = Preferences.get("last.sketch.path"); + Messages.log("DEBUG: last.sketch.path = " + lastPath); + + if (lastPath != null) { + File sketchFolder = new File(lastPath); + if (sketchFolder.exists()) { + Messages.log("Restoring last sketch at: " + lastPath); + File mainSketchFile = Sketch.findMain(sketchFolder, getModeList()); + if (mainSketchFile != null) { + handleOpen(mainSketchFile.getAbsolutePath()); + } else { + Messages.log("Could not find main sketch file in folder, falling back to new sketch"); + handleNew(); + } + } else { + Messages.log("Last sketch path not found, falling back to new sketch"); + handleNew(); + } + } else { + Messages.log("No saved sketch path, opening new sketch"); + handleNew(); + } + + } else { Messages.log("No handleNew(), something passed on the command line"); } @@ -1456,6 +1478,10 @@ public Editor handleOpen(String path) { } File parentFolder = pdeFile.getParentFile(); + Preferences.set("last.sketch.path", parentFolder.getAbsolutePath()); + Preferences.save(); // force write to disk + System.out.println("Preferences file location: " + Base.getSettingsFile("preferences.txt").getAbsolutePath()); + System.out.println("Saved last sketch path: " + parentFolder.getAbsolutePath()); try { // read the sketch.properties file or get an empty Settings object diff --git a/core/methods/src/PAppletMethods.java b/core/methods/src/PAppletMethods.java index 41ea29ef2f..e3b5ab7855 100644 --- a/core/methods/src/PAppletMethods.java +++ b/core/methods/src/PAppletMethods.java @@ -9,7 +9,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.tools.ant.BuildException; +import org.apache.tools.ant + .BuildException; import org.apache.tools.ant.Task;