Skip to content

Commit dd5c178

Browse files
matthijskooijmanfacchinm
authored andcommitted
Move isModified() from SketchController to Sketch
Also, update any code that uses it, removing the dependency on SketchController entirely if possible.
1 parent 629953e commit dd5c178

File tree

5 files changed

+34
-20
lines changed

5 files changed

+34
-20
lines changed

app/src/processing/app/Base.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,8 @@ protected void storeSketches() {
542542
Collections.reverse(reversedEditors);
543543
int index = 0;
544544
for (Editor editor : reversedEditors) {
545-
SketchController sketch = editor.getSketchController();
546-
String path = sketch.getSketch().getMainFilePath();
545+
Sketch sketch = editor.getSketch();
546+
String path = sketch.getMainFilePath();
547547
// Skip untitled sketches if they do not contains changes.
548548
if (path.startsWith(untitledPath) && !sketch.isModified()) {
549549
continue;

app/src/processing/app/Editor.java

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

88-
private static class ShouldSaveIfModified implements Predicate<SketchController> {
88+
private static class ShouldSaveIfModified
89+
implements Predicate<SketchController> {
8990

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

@@ -1838,7 +1844,8 @@ public void internalCloseRunner() {
18381844
* @return false if canceling the close/quit operation
18391845
*/
18401846
protected boolean checkModified() {
1841-
if (!sketchController.isModified()) return true;
1847+
if (!sketch.isModified())
1848+
return true;
18421849

18431850
// As of Processing 1.0.10, this always happens immediately.
18441851
// http://dev.processing.org/bugs/show_bug.cgi?id=1456
@@ -2169,7 +2176,11 @@ private boolean serialPrompt() {
21692176
*/
21702177
synchronized public void handleExport(final boolean usingProgrammer) {
21712178
if (PreferencesData.getBoolean("editor.save_on_verify")) {
2172-
if (sketchController.isModified() && !sketchController.isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
2179+
if (sketch.isModified()
2180+
&& !sketchController.isReadOnly(
2181+
BaseNoGui.librariesIndexer
2182+
.getInstalledLibraries(),
2183+
BaseNoGui.getExamplesPath())) {
21732184
handleSave(true);
21742185
}
21752186
}

app/src/processing/app/SketchController.java

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

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

465465

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

475467
/**
476468
* Save all code in the current sketch.
@@ -896,7 +888,7 @@ private String build(String buildPath, boolean verbose, boolean save) throws Run
896888

897889
boolean deleteTemp = false;
898890
String pathToSketch = sketch.getMainFilePath();
899-
if (isModified()) {
891+
if (sketch.isModified()) {
900892
// If any files are modified, make a copy of the sketch with the changes
901893
// saved, so arduino-builder will see the modifications.
902894
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)