Skip to content

Commit 8b43317

Browse files
Move isModified() from SketchController to Sketch
Also, update any code that uses it, removing the dependency on SketchController entirely if possible.
1 parent 32a97b2 commit 8b43317

File tree

5 files changed

+33
-19
lines changed

5 files changed

+33
-19
lines changed

app/src/processing/app/Base.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ protected void storeSketches() {
570570
String path = editor.getSketch().getMainFilePath();
571571
// In case of a crash, save untitled sketches if they contain changes.
572572
// (Added this for release 0158, may not be a good idea.)
573-
if (path.startsWith(untitledPath) && !editor.getSketchController().isModified()) {
573+
if (path.startsWith(untitledPath) && !editor.getSketch().isModified()) {
574574
continue;
575575
}
576576
PreferencesData.set("last.sketch" + index + ".path", path);

app/src/processing/app/Editor.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,17 @@ public class Editor extends JFrame implements RunnerListener {
8484
private ArrayList<EditorTab> tabs = new ArrayList<>();
8585
private int currentTabIndex = -1;
8686

87-
private static class ShouldSaveIfModified implements Predicate<SketchController> {
87+
private static class ShouldSaveIfModified
88+
implements Predicate<SketchController> {
8889

8990
@Override
90-
public boolean test(SketchController sketch) {
91-
return PreferencesData.getBoolean("editor.save_on_verify") && sketch.isModified() && !sketch.isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath());
91+
public boolean test(SketchController controller) {
92+
return PreferencesData.getBoolean("editor.save_on_verify")
93+
&& controller.getSketch().isModified()
94+
&& !controller.isReadOnly(
95+
BaseNoGui.librariesIndexer
96+
.getInstalledLibraries(),
97+
BaseNoGui.getExamplesPath());
9298
}
9399
}
94100

@@ -1846,7 +1852,8 @@ public void internalCloseRunner() {
18461852
* @return false if canceling the close/quit operation
18471853
*/
18481854
protected boolean checkModified() {
1849-
if (!sketchController.isModified()) return true;
1855+
if (!sketch.isModified())
1856+
return true;
18501857

18511858
// As of Processing 1.0.10, this always happens immediately.
18521859
// http://dev.processing.org/bugs/show_bug.cgi?id=1456
@@ -2177,7 +2184,11 @@ private boolean serialPrompt() {
21772184
*/
21782185
synchronized public void handleExport(final boolean usingProgrammer) {
21792186
if (PreferencesData.getBoolean("editor.save_on_verify")) {
2180-
if (sketchController.isModified() && !sketchController.isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
2187+
if (sketch.isModified()
2188+
&& !sketchController.isReadOnly(
2189+
BaseNoGui.librariesIndexer
2190+
.getInstalledLibraries(),
2191+
BaseNoGui.getExamplesPath())) {
21812192
handleSave(true);
21822193
}
21832194
}

app/src/processing/app/SketchController.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -457,21 +457,13 @@ public void calcModified() {
457457

458458
if (OSUtils.isMacOS()) {
459459
// http://developer.apple.com/qa/qa2001/qa1146.html
460-
Object modifiedParam = isModified() ? Boolean.TRUE : Boolean.FALSE;
460+
Object modifiedParam = sketch.isModified() ? Boolean.TRUE : Boolean.FALSE;
461461
editor.getRootPane().putClientProperty("windowModified", modifiedParam);
462462
editor.getRootPane().putClientProperty("Window.documentModified", modifiedParam);
463463
}
464464
}
465465

466466

467-
public boolean isModified() {
468-
for (SketchCode code : sketch.getCodes()) {
469-
if (code.isModified())
470-
return true;
471-
}
472-
return false;
473-
}
474-
475467

476468
/**
477469
* Save all code in the current sketch.
@@ -897,7 +889,7 @@ private String build(String buildPath, boolean verbose, boolean save) throws Run
897889

898890
boolean deleteTemp = false;
899891
String pathToSketch = sketch.getMainFilePath();
900-
if (isModified()) {
892+
if (sketch.isModified()) {
901893
// If any files are modified, make a copy of the sketch with the changes
902894
// saved, so arduino-builder will see the modifications.
903895
pathToSketch = saveSketchInTempFolder();

app/src/processing/app/tools/FixEncoding.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void init(Editor editor) {
4949

5050

5151
public void run() {
52-
SketchController sketch = editor.getSketchController();
52+
Sketch sketch = editor.getSketch();
5353
//SketchCode code = sketch.current;
5454

5555
if (sketch.isModified()) {
@@ -65,8 +65,8 @@ public void run() {
6565
}
6666
}
6767
try {
68-
for (int i = 0; i < sketch.getSketch().getCodeCount(); i++) {
69-
SketchCode code = sketch.getSketch().getCode(i);
68+
for (int i = 0; i < sketch.getCodeCount(); i++) {
69+
SketchCode code = sketch.getCode(i);
7070
editor.findTab(code).setText(loadWithLocalEncoding(code.getFile()));
7171
}
7272
} catch (IOException e) {

arduino-core/src/processing/app/Sketch.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,15 @@ public File getFolder() {
214214
public File getDataFolder() {
215215
return dataFolder;
216216
}
217+
218+
/**
219+
* Is any of the files in this sketch modified?
220+
*/
221+
public boolean isModified() {
222+
for (SketchCode code : codes) {
223+
if (code.isModified())
224+
return true;
225+
}
226+
return false;
227+
}
217228
}

0 commit comments

Comments
 (0)