@@ -133,7 +133,7 @@ public void handleNewCode() {
133
133
ensureExistence ();
134
134
135
135
// if read-only, give an error
136
- if (isReadOnly ()) {
136
+ if (isReadOnly (BaseNoGui . getLibrariesPath (), BaseNoGui . getExamplesPath () )) {
137
137
// if the files are read-only, need to first do a "save as".
138
138
Base .showMessage (tr ("Sketch is Read-Only" ),
139
139
tr ("Some files are marked \" read-only\" , so you'll\n " +
@@ -162,7 +162,7 @@ public void handleRenameCode() {
162
162
}
163
163
164
164
// if read-only, give an error
165
- if (isReadOnly ()) {
165
+ if (isReadOnly (BaseNoGui . getLibrariesPath (), BaseNoGui . getExamplesPath () )) {
166
166
// if the files are read-only, need to first do a "save as".
167
167
Base .showMessage (tr ("Sketch is Read-Only" ),
168
168
tr ("Some files are marked \" read-only\" , so you'll\n " +
@@ -432,7 +432,7 @@ public void handleDeleteCode() {
432
432
ensureExistence ();
433
433
434
434
// if read-only, give an error
435
- if (isReadOnly ()) {
435
+ if (isReadOnly (BaseNoGui . getLibrariesPath (), BaseNoGui . getExamplesPath () )) {
436
436
// if the files are read-only, need to first do a "save as".
437
437
Base .showMessage (tr ("Sketch is Read-Only" ),
438
438
tr ("Some files are marked \" read-only\" , so you'll\n " +
@@ -558,7 +558,7 @@ public boolean save() throws IOException {
558
558
// don't do anything if not actually modified
559
559
//if (!modified) return false;
560
560
561
- if (isReadOnly ()) {
561
+ if (isReadOnly (BaseNoGui . getLibrariesPath (), BaseNoGui . getExamplesPath () )) {
562
562
// if the files are read-only, need to first do a "save as".
563
563
Base .showMessage (tr ("Sketch is read-only" ),
564
564
tr ("Some files are marked \" read-only\" , so you'll\n " +
@@ -637,7 +637,7 @@ private boolean renameCodeToInoExtension(File pdeFile) {
637
637
protected boolean saveAs () throws IOException {
638
638
// get new name for folder
639
639
FileDialog fd = new FileDialog (editor , tr ("Save sketch folder as..." ), FileDialog .SAVE );
640
- if (isReadOnly () || isUntitled ()) {
640
+ if (isReadOnly (BaseNoGui . getLibrariesPath (), BaseNoGui . getExamplesPath () ) || isUntitled ()) {
641
641
// default to the sketchbook folder
642
642
fd .setDirectory (BaseNoGui .getSketchbookFolder ().getAbsolutePath ());
643
643
} else {
@@ -772,7 +772,7 @@ public void handleAddFile() {
772
772
ensureExistence ();
773
773
774
774
// if read-only, give an error
775
- if (isReadOnly ()) {
775
+ if (isReadOnly (BaseNoGui . getLibrariesPath (), BaseNoGui . getExamplesPath () )) {
776
776
// if the files are read-only, need to first do a "save as".
777
777
Base .showMessage (tr ("Sketch is Read-Only" ),
778
778
tr ("Some files are marked \" read-only\" , so you'll\n " +
@@ -1223,25 +1223,27 @@ private void ensureExistence() {
1223
1223
* Returns true if this is a read-only sketch. Used for the
1224
1224
* examples directory, or when sketches are loaded from read-only
1225
1225
* volumes or folders without appropriate permissions.
1226
+ * @param librariesPaths
1227
+ * @param examplesPath
1226
1228
*/
1227
- public boolean isReadOnly () {
1229
+ public boolean isReadOnly (List < File > librariesPaths , String examplesPath ) {
1228
1230
String apath = data .getFolder ().getAbsolutePath ();
1229
- for (File folder : BaseNoGui . getLibrariesPath () ) {
1230
- if (apath .startsWith (folder .getAbsolutePath ()))
1231
+ for (File folder : librariesPaths ) {
1232
+ if (apath .startsWith (folder .getAbsolutePath ())) {
1231
1233
return true ;
1232
- }
1233
- if (apath .startsWith (BaseNoGui .getExamplesPath ()) ||
1234
- apath .startsWith (Base .getSketchbookLibrariesPath ())) {
1235
- return true ;
1234
+ }
1236
1235
}
1237
1236
1238
- // canWrite() doesn't work on directories
1239
- // } else if (!folder.canWrite()) {
1237
+ return sketchIsSystemExample (apath , examplesPath ) || sketchFilesAreReadOnly ();
1238
+ }
1239
+
1240
+ private boolean sketchIsSystemExample (String apath , String examplesPath ) {
1241
+ return apath .startsWith (examplesPath );
1242
+ }
1240
1243
1241
- // check to see if each modified code file can be written to
1244
+ private boolean sketchFilesAreReadOnly () {
1242
1245
for (SketchCode code : data .getCodes ()) {
1243
1246
if (code .isModified () && code .fileReadOnly () && code .fileExists ()) {
1244
- // System.err.println("found a read-only file " + code[i].file);
1245
1247
return true ;
1246
1248
}
1247
1249
}
0 commit comments