Skip to content

Commit 27b9986

Browse files
committed
Simplified SketchController.isReadOnly(..) method
Since the method is called everywhere with the following parameters isReadOnly( BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath()) ) the static calls to BaseNoGui have been inlined into isReadOnly() removing all the duplications around.
1 parent bf1b523 commit 27b9986

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

app/src/processing/app/Editor.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,15 @@ private static class ShouldSaveIfModified
9696
public boolean test(SketchController controller) {
9797
return PreferencesData.getBoolean("editor.save_on_verify")
9898
&& controller.getSketch().isModified()
99-
&& !controller.isReadOnly(
100-
BaseNoGui.librariesIndexer
101-
.getInstalledLibraries(),
102-
BaseNoGui.getExamplesPath());
99+
&& !controller.isReadOnly();
103100
}
104101
}
105102

106103
private static class ShouldSaveReadOnly implements Predicate<SketchController> {
107104

108105
@Override
109106
public boolean test(SketchController sketch) {
110-
return sketch.isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath());
107+
return sketch.isReadOnly();
111108
}
112109
}
113110

@@ -2043,7 +2040,7 @@ private boolean handleSave2() {
20432040
formatTool.run();
20442041
}
20452042

2046-
boolean wasReadOnly = sketchController.isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath());
2043+
boolean wasReadOnly = sketchController.isReadOnly();
20472044
String previousMainFilePath = sketch.getMainFilePath();
20482045
saved = sketchController.save();
20492046
if (saved) {
@@ -2161,11 +2158,7 @@ private boolean serialPrompt() {
21612158
*/
21622159
synchronized public void handleExport(final boolean usingProgrammer) {
21632160
if (PreferencesData.getBoolean("editor.save_on_verify")) {
2164-
if (sketch.isModified()
2165-
&& !sketchController.isReadOnly(
2166-
BaseNoGui.librariesIndexer
2167-
.getInstalledLibraries(),
2168-
BaseNoGui.getExamplesPath())) {
2161+
if (sketch.isModified() && !sketchController.isReadOnly()) {
21692162
handleSave(true);
21702163
}
21712164
}

app/src/processing/app/SketchController.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void handleNewCode() {
7575
ensureExistence();
7676

7777
// if read-only, give an error
78-
if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
78+
if (isReadOnly()) {
7979
// if the files are read-only, need to first do a "save as".
8080
Base.showMessage(tr("Sketch is Read-Only"),
8181
tr("Some files are marked \"read-only\", so you'll\n" +
@@ -107,7 +107,7 @@ public void handleRenameCode() {
107107
}
108108

109109
// if read-only, give an error
110-
if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
110+
if (isReadOnly()) {
111111
// if the files are read-only, need to first do a "save as".
112112
Base.showMessage(tr("Sketch is Read-Only"),
113113
tr("Some files are marked \"read-only\", so you'll\n" +
@@ -225,7 +225,7 @@ public void handleDeleteCode() throws IOException {
225225
ensureExistence();
226226

227227
// if read-only, give an error
228-
if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
228+
if (isReadOnly()) {
229229
// if the files are read-only, need to first do a "save as".
230230
Base.showMessage(tr("Sketch is Read-Only"),
231231
tr("Some files are marked \"read-only\", so you'll\n" +
@@ -303,7 +303,7 @@ public boolean save() throws IOException {
303303
// make sure the user didn't hide the sketch folder
304304
ensureExistence();
305305

306-
if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
306+
if (isReadOnly()) {
307307
Base.showMessage(tr("Sketch is read-only"),
308308
tr("Some files are marked \"read-only\", so you'll\n" +
309309
"need to re-save this sketch to another location."));
@@ -367,7 +367,7 @@ public boolean save() throws IOException {
367367
protected boolean saveAs() throws IOException {
368368
// get new name for folder
369369
FileDialog fd = new FileDialog(editor, tr("Save sketch folder as..."), FileDialog.SAVE);
370-
if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath()) || isUntitled()) {
370+
if (isReadOnly() || isUntitled()) {
371371
// default to the sketchbook folder
372372
fd.setDirectory(BaseNoGui.getSketchbookFolder().getAbsolutePath());
373373
} else {
@@ -456,7 +456,7 @@ public void handleAddFile() {
456456
ensureExistence();
457457

458458
// if read-only, give an error
459-
if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
459+
if (isReadOnly()) {
460460
// if the files are read-only, need to first do a "save as".
461461
Base.showMessage(tr("Sketch is Read-Only"),
462462
tr("Some files are marked \"read-only\", so you'll\n" +
@@ -791,7 +791,9 @@ private void ensureExistence() {
791791
* examples directory, or when sketches are loaded from read-only
792792
* volumes or folders without appropriate permissions.
793793
*/
794-
public boolean isReadOnly(LibraryList libraries, String examplesPath) {
794+
public boolean isReadOnly() {
795+
LibraryList libraries = BaseNoGui.librariesIndexer.getInstalledLibraries();
796+
String examplesPath = BaseNoGui.getExamplesPath();
795797
String apath = sketch.getFolder().getAbsolutePath();
796798

797799
Optional<UserLibrary> libraryThatIncludesSketch = libraries.stream().filter(lib -> apath.startsWith(lib.getInstalledFolder().getAbsolutePath())).findFirst();

0 commit comments

Comments
 (0)