@@ -133,7 +133,7 @@ public void handleNewCode() {
133133 ensureExistence ();
134134
135135 // if read-only, give an error
136- if (isReadOnly ()) {
136+ if (isReadOnly (BaseNoGui . getLibrariesPath (), BaseNoGui . getExamplesPath () )) {
137137 // if the files are read-only, need to first do a "save as".
138138 Base .showMessage (tr ("Sketch is Read-Only" ),
139139 tr ("Some files are marked \" read-only\" , so you'll\n " +
@@ -162,7 +162,7 @@ public void handleRenameCode() {
162162 }
163163
164164 // if read-only, give an error
165- if (isReadOnly ()) {
165+ if (isReadOnly (BaseNoGui . getLibrariesPath (), BaseNoGui . getExamplesPath () )) {
166166 // if the files are read-only, need to first do a "save as".
167167 Base .showMessage (tr ("Sketch is Read-Only" ),
168168 tr ("Some files are marked \" read-only\" , so you'll\n " +
@@ -432,7 +432,7 @@ public void handleDeleteCode() {
432432 ensureExistence ();
433433
434434 // if read-only, give an error
435- if (isReadOnly ()) {
435+ if (isReadOnly (BaseNoGui . getLibrariesPath (), BaseNoGui . getExamplesPath () )) {
436436 // if the files are read-only, need to first do a "save as".
437437 Base .showMessage (tr ("Sketch is Read-Only" ),
438438 tr ("Some files are marked \" read-only\" , so you'll\n " +
@@ -558,7 +558,7 @@ public boolean save() throws IOException {
558558 // don't do anything if not actually modified
559559 //if (!modified) return false;
560560
561- if (isReadOnly ()) {
561+ if (isReadOnly (BaseNoGui . getLibrariesPath (), BaseNoGui . getExamplesPath () )) {
562562 // if the files are read-only, need to first do a "save as".
563563 Base .showMessage (tr ("Sketch is read-only" ),
564564 tr ("Some files are marked \" read-only\" , so you'll\n " +
@@ -637,7 +637,7 @@ private boolean renameCodeToInoExtension(File pdeFile) {
637637 protected boolean saveAs () throws IOException {
638638 // get new name for folder
639639 FileDialog fd = new FileDialog (editor , tr ("Save sketch folder as..." ), FileDialog .SAVE );
640- if (isReadOnly () || isUntitled ()) {
640+ if (isReadOnly (BaseNoGui . getLibrariesPath (), BaseNoGui . getExamplesPath () ) || isUntitled ()) {
641641 // default to the sketchbook folder
642642 fd .setDirectory (BaseNoGui .getSketchbookFolder ().getAbsolutePath ());
643643 } else {
@@ -772,7 +772,7 @@ public void handleAddFile() {
772772 ensureExistence ();
773773
774774 // if read-only, give an error
775- if (isReadOnly ()) {
775+ if (isReadOnly (BaseNoGui . getLibrariesPath (), BaseNoGui . getExamplesPath () )) {
776776 // if the files are read-only, need to first do a "save as".
777777 Base .showMessage (tr ("Sketch is Read-Only" ),
778778 tr ("Some files are marked \" read-only\" , so you'll\n " +
@@ -1223,25 +1223,27 @@ private void ensureExistence() {
12231223 * Returns true if this is a read-only sketch. Used for the
12241224 * examples directory, or when sketches are loaded from read-only
12251225 * volumes or folders without appropriate permissions.
1226+ * @param librariesPaths
1227+ * @param examplesPath
12261228 */
1227- public boolean isReadOnly () {
1229+ public boolean isReadOnly (List < File > librariesPaths , String examplesPath ) {
12281230 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 ())) {
12311233 return true ;
1232- }
1233- if (apath .startsWith (BaseNoGui .getExamplesPath ()) ||
1234- apath .startsWith (Base .getSketchbookLibrariesPath ())) {
1235- return true ;
1234+ }
12361235 }
12371236
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+ }
12401243
1241- // check to see if each modified code file can be written to
1244+ private boolean sketchFilesAreReadOnly () {
12421245 for (SketchCode code : data .getCodes ()) {
12431246 if (code .isModified () && code .fileReadOnly () && code .fileExists ()) {
1244- // System.err.println("found a read-only file " + code[i].file);
12451247 return true ;
12461248 }
12471249 }
0 commit comments