|
30 | 30 | import processing.app.forms.PasswordAuthorizationDialog;
|
31 | 31 | import processing.app.helpers.OSUtils;
|
32 | 32 | import processing.app.helpers.PreferencesMapException;
|
| 33 | +import processing.app.packages.LibraryList; |
33 | 34 | import processing.app.packages.UserLibrary;
|
34 | 35 |
|
35 | 36 | import javax.swing.*;
|
|
39 | 40 | import java.util.Arrays;
|
40 | 41 | import java.util.LinkedList;
|
41 | 42 | import java.util.List;
|
| 43 | +import java.util.Optional; |
42 | 44 |
|
43 | 45 | import static processing.app.I18n.tr;
|
44 | 46 |
|
@@ -133,7 +135,7 @@ public void handleNewCode() {
|
133 | 135 | ensureExistence();
|
134 | 136 |
|
135 | 137 | // if read-only, give an error
|
136 |
| - if (isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath())) { |
| 138 | + if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) { |
137 | 139 | // if the files are read-only, need to first do a "save as".
|
138 | 140 | Base.showMessage(tr("Sketch is Read-Only"),
|
139 | 141 | tr("Some files are marked \"read-only\", so you'll\n" +
|
@@ -162,7 +164,7 @@ public void handleRenameCode() {
|
162 | 164 | }
|
163 | 165 |
|
164 | 166 | // if read-only, give an error
|
165 |
| - if (isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath())) { |
| 167 | + if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) { |
166 | 168 | // if the files are read-only, need to first do a "save as".
|
167 | 169 | Base.showMessage(tr("Sketch is Read-Only"),
|
168 | 170 | tr("Some files are marked \"read-only\", so you'll\n" +
|
@@ -432,7 +434,7 @@ public void handleDeleteCode() {
|
432 | 434 | ensureExistence();
|
433 | 435 |
|
434 | 436 | // if read-only, give an error
|
435 |
| - if (isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath())) { |
| 437 | + if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) { |
436 | 438 | // if the files are read-only, need to first do a "save as".
|
437 | 439 | Base.showMessage(tr("Sketch is Read-Only"),
|
438 | 440 | tr("Some files are marked \"read-only\", so you'll\n" +
|
@@ -558,7 +560,7 @@ public boolean save() throws IOException {
|
558 | 560 | // don't do anything if not actually modified
|
559 | 561 | //if (!modified) return false;
|
560 | 562 |
|
561 |
| - if (isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath())) { |
| 563 | + if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) { |
562 | 564 | // if the files are read-only, need to first do a "save as".
|
563 | 565 | Base.showMessage(tr("Sketch is read-only"),
|
564 | 566 | tr("Some files are marked \"read-only\", so you'll\n" +
|
@@ -637,7 +639,7 @@ private boolean renameCodeToInoExtension(File pdeFile) {
|
637 | 639 | protected boolean saveAs() throws IOException {
|
638 | 640 | // get new name for folder
|
639 | 641 | FileDialog fd = new FileDialog(editor, tr("Save sketch folder as..."), FileDialog.SAVE);
|
640 |
| - if (isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath()) || isUntitled()) { |
| 642 | + if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath()) || isUntitled()) { |
641 | 643 | // default to the sketchbook folder
|
642 | 644 | fd.setDirectory(BaseNoGui.getSketchbookFolder().getAbsolutePath());
|
643 | 645 | } else {
|
@@ -772,7 +774,7 @@ public void handleAddFile() {
|
772 | 774 | ensureExistence();
|
773 | 775 |
|
774 | 776 | // if read-only, give an error
|
775 |
| - if (isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath())) { |
| 777 | + if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) { |
776 | 778 | // if the files are read-only, need to first do a "save as".
|
777 | 779 | Base.showMessage(tr("Sketch is Read-Only"),
|
778 | 780 | tr("Some files are marked \"read-only\", so you'll\n" +
|
@@ -1226,12 +1228,12 @@ private void ensureExistence() {
|
1226 | 1228 | * @param librariesPaths
|
1227 | 1229 | * @param examplesPath
|
1228 | 1230 | */
|
1229 |
| - public boolean isReadOnly(List<File> librariesPaths, String examplesPath) { |
| 1231 | + public boolean isReadOnly(LibraryList libraries, String examplesPath) { |
1230 | 1232 | String apath = data.getFolder().getAbsolutePath();
|
1231 |
| - for (File folder : librariesPaths) { |
1232 |
| - if (apath.startsWith(folder.getAbsolutePath())) { |
1233 |
| - return true; |
1234 |
| - } |
| 1233 | + |
| 1234 | + Optional<UserLibrary> libraryThatIncludesSketch = libraries.stream().filter(lib -> apath.startsWith(lib.getInstalledFolder().getAbsolutePath())).findFirst(); |
| 1235 | + if (libraryThatIncludesSketch.isPresent() && !libraryThatIncludesSketch.get().onGoingDevelopment()) { |
| 1236 | + return true; |
1235 | 1237 | }
|
1236 | 1238 |
|
1237 | 1239 | return sketchIsSystemExample(apath, examplesPath) || sketchFilesAreReadOnly();
|
|
0 commit comments