diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 1c573cccc..e8d4bf155 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -542,8 +542,8 @@ public class Base { Collections.reverse(reversedEditors); int index = 0; for (Editor editor : reversedEditors) { - SketchController sketch = editor.getSketchController(); - String path = sketch.getSketch().getMainFilePath(); + Sketch sketch = editor.getSketch(); + String path = sketch.getMainFilePath(); // Skip untitled sketches if they do not contains changes. if (path.startsWith(untitledPath) && !sketch.isModified()) { continue; diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index a1fa4f5a7..e7749b67c 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -85,11 +85,17 @@ public class Editor extends JFrame implements RunnerListener { private ArrayList tabs = new ArrayList<>(); private int currentTabIndex = -1; - private static class ShouldSaveIfModified implements Predicate { + private static class ShouldSaveIfModified + implements Predicate { @Override - public boolean test(SketchController sketch) { - return PreferencesData.getBoolean("editor.save_on_verify") && sketch.isModified() && !sketch.isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath()); + public boolean test(SketchController controller) { + return PreferencesData.getBoolean("editor.save_on_verify") + && controller.getSketch().isModified() + && !controller.isReadOnly( + BaseNoGui.librariesIndexer + .getInstalledLibraries(), + BaseNoGui.getExamplesPath()); } } @@ -1838,7 +1844,8 @@ public class Editor extends JFrame implements RunnerListener { * @return false if canceling the close/quit operation */ protected boolean checkModified() { - if (!sketchController.isModified()) return true; + if (!sketch.isModified()) + return true; // As of Processing 1.0.10, this always happens immediately. // http://dev.processing.org/bugs/show_bug.cgi?id=1456 @@ -2169,7 +2176,11 @@ public class Editor extends JFrame implements RunnerListener { */ synchronized public void handleExport(final boolean usingProgrammer) { if (PreferencesData.getBoolean("editor.save_on_verify")) { - if (sketchController.isModified() && !sketchController.isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) { + if (sketch.isModified() + && !sketchController.isReadOnly( + BaseNoGui.librariesIndexer + .getInstalledLibraries(), + BaseNoGui.getExamplesPath())) { handleSave(true); } } diff --git a/app/src/processing/app/SketchController.java b/app/src/processing/app/SketchController.java index 5d96c8bdb..738a90e46 100644 --- a/app/src/processing/app/SketchController.java +++ b/app/src/processing/app/SketchController.java @@ -456,21 +456,13 @@ public class SketchController { if (OSUtils.isMacOS()) { // http://developer.apple.com/qa/qa2001/qa1146.html - Object modifiedParam = isModified() ? Boolean.TRUE : Boolean.FALSE; + Object modifiedParam = sketch.isModified() ? Boolean.TRUE : Boolean.FALSE; editor.getRootPane().putClientProperty("windowModified", modifiedParam); editor.getRootPane().putClientProperty("Window.documentModified", modifiedParam); } } - public boolean isModified() { - for (SketchCode code : sketch.getCodes()) { - if (code.isModified()) - return true; - } - return false; - } - /** * Save all code in the current sketch. @@ -896,7 +888,7 @@ public class SketchController { boolean deleteTemp = false; String pathToSketch = sketch.getMainFilePath(); - if (isModified()) { + if (sketch.isModified()) { // If any files are modified, make a copy of the sketch with the changes // saved, so arduino-builder will see the modifications. pathToSketch = saveSketchInTempFolder(); diff --git a/app/src/processing/app/tools/FixEncoding.java b/app/src/processing/app/tools/FixEncoding.java index 58621254f..3ee5d0554 100644 --- a/app/src/processing/app/tools/FixEncoding.java +++ b/app/src/processing/app/tools/FixEncoding.java @@ -49,7 +49,7 @@ public class FixEncoding implements Tool { public void run() { - SketchController sketch = editor.getSketchController(); + Sketch sketch = editor.getSketch(); //SketchCode code = sketch.current; if (sketch.isModified()) { @@ -65,8 +65,8 @@ public class FixEncoding implements Tool { } } try { - for (int i = 0; i < sketch.getSketch().getCodeCount(); i++) { - SketchCode code = sketch.getSketch().getCode(i); + for (int i = 0; i < sketch.getCodeCount(); i++) { + SketchCode code = sketch.getCode(i); editor.findTab(code).setText(loadWithLocalEncoding(code.getFile())); } } catch (IOException e) { diff --git a/arduino-core/src/processing/app/Sketch.java b/arduino-core/src/processing/app/Sketch.java index 87546fb74..90e3964a3 100644 --- a/arduino-core/src/processing/app/Sketch.java +++ b/arduino-core/src/processing/app/Sketch.java @@ -214,4 +214,15 @@ public class Sketch { public File getDataFolder() { return dataFolder; } + + /** + * Is any of the files in this sketch modified? + */ + public boolean isModified() { + for (SketchCode code : codes) { + if (code.isModified()) + return true; + } + return false; + } }