Skip to content

Commit 59dfede

Browse files
author
Federico Fissore
committed
Libraries with a .development file in their root are flagged as "OnDevelopment".
This allows users to edit and save those libraries examples: they won't be flagged as read-only any more
1 parent 52fd384 commit 59dfede

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed

Diff for: app/src/processing/app/Editor.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ private static class ShouldSaveIfModified implements Predicate<Sketch> {
9393

9494
@Override
9595
public boolean test(Sketch sketch) {
96-
return PreferencesData.getBoolean("editor.save_on_verify") && sketch.isModified() && !sketch.isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath());
96+
return PreferencesData.getBoolean("editor.save_on_verify") && sketch.isModified() && !sketch.isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath());
9797
}
9898
}
9999

100100
private static class ShouldSaveReadOnly implements Predicate<Sketch> {
101101

102102
@Override
103103
public boolean test(Sketch sketch) {
104-
return sketch.isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath());
104+
return sketch.isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath());
105105
}
106106
}
107107

@@ -2282,7 +2282,7 @@ private boolean handleSave2() {
22822282
statusNotice(tr("Saving..."));
22832283
boolean saved = false;
22842284
try {
2285-
boolean wasReadOnly = sketch.isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath());
2285+
boolean wasReadOnly = sketch.isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath());
22862286
String previousMainFilePath = sketch.getMainFilePath();
22872287
saved = sketch.save();
22882288
if (saved) {
@@ -2395,7 +2395,7 @@ private boolean serialPrompt() {
23952395
*/
23962396
synchronized public void handleExport(final boolean usingProgrammer) {
23972397
if (PreferencesData.getBoolean("editor.save_on_verify")) {
2398-
if (sketch.isModified() && !sketch.isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath())) {
2398+
if (sketch.isModified() && !sketch.isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
23992399
handleSave(true);
24002400
}
24012401
}

Diff for: app/src/processing/app/Sketch.java

+13-11
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import processing.app.forms.PasswordAuthorizationDialog;
3131
import processing.app.helpers.OSUtils;
3232
import processing.app.helpers.PreferencesMapException;
33+
import processing.app.packages.LibraryList;
3334
import processing.app.packages.UserLibrary;
3435

3536
import javax.swing.*;
@@ -39,6 +40,7 @@
3940
import java.util.Arrays;
4041
import java.util.LinkedList;
4142
import java.util.List;
43+
import java.util.Optional;
4244

4345
import static processing.app.I18n.tr;
4446

@@ -133,7 +135,7 @@ public void handleNewCode() {
133135
ensureExistence();
134136

135137
// if read-only, give an error
136-
if (isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath())) {
138+
if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
137139
// if the files are read-only, need to first do a "save as".
138140
Base.showMessage(tr("Sketch is Read-Only"),
139141
tr("Some files are marked \"read-only\", so you'll\n" +
@@ -162,7 +164,7 @@ public void handleRenameCode() {
162164
}
163165

164166
// if read-only, give an error
165-
if (isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath())) {
167+
if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
166168
// if the files are read-only, need to first do a "save as".
167169
Base.showMessage(tr("Sketch is Read-Only"),
168170
tr("Some files are marked \"read-only\", so you'll\n" +
@@ -432,7 +434,7 @@ public void handleDeleteCode() {
432434
ensureExistence();
433435

434436
// if read-only, give an error
435-
if (isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath())) {
437+
if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
436438
// if the files are read-only, need to first do a "save as".
437439
Base.showMessage(tr("Sketch is Read-Only"),
438440
tr("Some files are marked \"read-only\", so you'll\n" +
@@ -558,7 +560,7 @@ public boolean save() throws IOException {
558560
// don't do anything if not actually modified
559561
//if (!modified) return false;
560562

561-
if (isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath())) {
563+
if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
562564
// if the files are read-only, need to first do a "save as".
563565
Base.showMessage(tr("Sketch is read-only"),
564566
tr("Some files are marked \"read-only\", so you'll\n" +
@@ -637,7 +639,7 @@ private boolean renameCodeToInoExtension(File pdeFile) {
637639
protected boolean saveAs() throws IOException {
638640
// get new name for folder
639641
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()) {
641643
// default to the sketchbook folder
642644
fd.setDirectory(BaseNoGui.getSketchbookFolder().getAbsolutePath());
643645
} else {
@@ -772,7 +774,7 @@ public void handleAddFile() {
772774
ensureExistence();
773775

774776
// if read-only, give an error
775-
if (isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath())) {
777+
if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
776778
// if the files are read-only, need to first do a "save as".
777779
Base.showMessage(tr("Sketch is Read-Only"),
778780
tr("Some files are marked \"read-only\", so you'll\n" +
@@ -1226,12 +1228,12 @@ private void ensureExistence() {
12261228
* @param librariesPaths
12271229
* @param examplesPath
12281230
*/
1229-
public boolean isReadOnly(List<File> librariesPaths, String examplesPath) {
1231+
public boolean isReadOnly(LibraryList libraries, String examplesPath) {
12301232
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;
12351237
}
12361238

12371239
return sketchIsSystemExample(apath, examplesPath) || sketchFilesAreReadOnly();

Diff for: arduino-core/src/cc/arduino/Constants.java

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public class Constants {
4242
public static final List<String> PROTECTED_PACKAGE_NAMES = Arrays.asList("arduino", "Intel");
4343
public static final String PACKAGE_INDEX_URL;
4444

45+
public static final String LIBRARY_DEVELOPMENT_FLAG_FILE = ".development";
46+
4547
static {
4648
String extenalPackageIndexUrl = System.getProperty("PACKAGE_INDEX_URL");
4749
if (extenalPackageIndexUrl != null && !"".equals(extenalPackageIndexUrl)) {

Diff for: arduino-core/src/processing/app/packages/UserLibrary.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@
2828
*/
2929
package processing.app.packages;
3030

31+
import cc.arduino.Constants;
3132
import cc.arduino.contributions.libraries.ContributedLibrary;
3233
import cc.arduino.contributions.libraries.ContributedLibraryReference;
3334
import processing.app.helpers.FileUtils;
3435
import processing.app.helpers.PreferencesMap;
3536

3637
import java.io.File;
3738
import java.io.IOException;
39+
import java.nio.file.Files;
40+
import java.nio.file.Paths;
3841
import java.util.ArrayList;
3942
import java.util.Arrays;
4043
import java.util.LinkedList;
@@ -54,6 +57,7 @@ public class UserLibrary extends ContributedLibrary {
5457
private List<String> architectures;
5558
private List<String> types;
5659
private List<String> declaredTypes;
60+
private boolean onGoingDevelopment;
5761

5862
private static final List<String> MANDATORY_PROPERTIES = Arrays
5963
.asList("name", "version", "author", "maintainer",
@@ -124,7 +128,7 @@ public static UserLibrary create(File libFolder) throws IOException {
124128
String architectures = properties.get("architectures");
125129
if (architectures == null)
126130
architectures = "*"; // defaults to "any"
127-
List<String> archs = new ArrayList<String>();
131+
List<String> archs = new ArrayList<>();
128132
for (String arch : architectures.split(","))
129133
archs.add(arch.trim());
130134

@@ -145,7 +149,7 @@ public static UserLibrary create(File libFolder) throws IOException {
145149
if (types == null) {
146150
types = "Contributed";
147151
}
148-
List<String> typesList = new LinkedList<String>();
152+
List<String> typesList = new LinkedList<>();
149153
for (String type : types.split(",")) {
150154
typesList.add(type.trim());
151155
}
@@ -165,6 +169,7 @@ public static UserLibrary create(File libFolder) throws IOException {
165169
res.architectures = archs;
166170
res.layout = layout;
167171
res.declaredTypes = typesList;
172+
res.onGoingDevelopment = Files.exists(Paths.get(libFolder.getAbsolutePath(), Constants.LIBRARY_DEVELOPMENT_FLAG_FILE));
168173
return res;
169174
}
170175

@@ -265,6 +270,10 @@ public List<String> getDeclaredTypes() {
265270
return declaredTypes;
266271
}
267272

273+
public boolean onGoingDevelopment() {
274+
return onGoingDevelopment;
275+
}
276+
268277
protected enum LibraryLayout {
269278
FLAT, RECURSIVE
270279
}

0 commit comments

Comments
 (0)