From 2b02203f5d6d73e84e08195d15947a2b87432fd3 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sat, 5 Feb 2022 08:16:39 -0500 Subject: [PATCH] fix bug when changing the Mode between Java and Android --- app/src/processing/app/Base.java | 11 +++++++---- todo.txt | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 7340e0900..229d359b8 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -971,6 +971,7 @@ public class Base { */ private void saveModeSettings(final File sketchProps, final Mode mode) { try { + // Read the old sketch.properties file if it already exists final Settings settings = new Settings(sketchProps); settings.set("mode", mode.getTitle()); settings.set("mode.id", mode.getIdentifier()); @@ -982,6 +983,7 @@ public class Base { String getDefaultModeIdentifier() { + // Used to initialize coreModes, so cannot use coreModes[0].getIdentifier() return "processing.mode.java.JavaMode"; } @@ -1001,7 +1003,9 @@ public class Base { nextMode = mode; if (sketch.isModified()) { - handleNew(); // don't bother with error messages, just switch + // If sketch is modified, simpler to just open a new window. + // https://github.com/processing/processing4/issues/189 + handleNew(); return false; } else if (sketch.isUntitled()) { @@ -1013,10 +1017,9 @@ public class Base { } else { // If the current sketch contains file extensions that the new mode // can handle, then write a sketch.properties file with the new mode - // specified, and reopen. (Really only useful for Java <-> Android) - //if (isCompatible(sketch, mode)) { + // specified, and reopen. Currently, only used for Java <-> Android. if (mode.canEdit(sketch)) { - final File props = new File(sketch.getCodeFolder(), "sketch.properties"); + final File props = new File(sketch.getFolder(), "sketch.properties"); saveModeSettings(props, nextMode); handleClose(activeEditor, true); Editor editor = handleOpen(sketch.getMainFilePath()); diff --git a/todo.txt b/todo.txt index 18ffbc94c..8fc748b17 100755 --- a/todo.txt +++ b/todo.txt @@ -3,6 +3,10 @@ X update to Java 17.0.2+8 X move "Add Examples" to bottom of the Examples window X remove anachronistic Preferences.save() that happens after opening a sketch +modes and properties +X fix bug when changing the Mode between Java and Android +X appears that it would have been broken for a long time + . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .