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
This commit is contained in:
Federico Fissore 2015-08-05 16:24:41 +02:00
parent 52fd3845ca
commit 59dfede5ac
4 changed files with 30 additions and 17 deletions

View File

@ -93,7 +93,7 @@ public class Editor extends JFrame implements RunnerListener {
@Override
public boolean test(Sketch sketch) {
return PreferencesData.getBoolean("editor.save_on_verify") && sketch.isModified() && !sketch.isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath());
return PreferencesData.getBoolean("editor.save_on_verify") && sketch.isModified() && !sketch.isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath());
}
}
@ -101,7 +101,7 @@ public class Editor extends JFrame implements RunnerListener {
@Override
public boolean test(Sketch sketch) {
return sketch.isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath());
return sketch.isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath());
}
}
@ -2282,7 +2282,7 @@ public class Editor extends JFrame implements RunnerListener {
statusNotice(tr("Saving..."));
boolean saved = false;
try {
boolean wasReadOnly = sketch.isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath());
boolean wasReadOnly = sketch.isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath());
String previousMainFilePath = sketch.getMainFilePath();
saved = sketch.save();
if (saved) {
@ -2395,7 +2395,7 @@ public class Editor extends JFrame implements RunnerListener {
*/
synchronized public void handleExport(final boolean usingProgrammer) {
if (PreferencesData.getBoolean("editor.save_on_verify")) {
if (sketch.isModified() && !sketch.isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath())) {
if (sketch.isModified() && !sketch.isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
handleSave(true);
}
}

View File

@ -30,6 +30,7 @@ import processing.app.debug.RunnerException;
import processing.app.forms.PasswordAuthorizationDialog;
import processing.app.helpers.OSUtils;
import processing.app.helpers.PreferencesMapException;
import processing.app.packages.LibraryList;
import processing.app.packages.UserLibrary;
import javax.swing.*;
@ -39,6 +40,7 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import static processing.app.I18n.tr;
@ -133,7 +135,7 @@ public class Sketch {
ensureExistence();
// if read-only, give an error
if (isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath())) {
if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
// if the files are read-only, need to first do a "save as".
Base.showMessage(tr("Sketch is Read-Only"),
tr("Some files are marked \"read-only\", so you'll\n" +
@ -162,7 +164,7 @@ public class Sketch {
}
// if read-only, give an error
if (isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath())) {
if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
// if the files are read-only, need to first do a "save as".
Base.showMessage(tr("Sketch is Read-Only"),
tr("Some files are marked \"read-only\", so you'll\n" +
@ -432,7 +434,7 @@ public class Sketch {
ensureExistence();
// if read-only, give an error
if (isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath())) {
if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
// if the files are read-only, need to first do a "save as".
Base.showMessage(tr("Sketch is Read-Only"),
tr("Some files are marked \"read-only\", so you'll\n" +
@ -558,7 +560,7 @@ public class Sketch {
// don't do anything if not actually modified
//if (!modified) return false;
if (isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath())) {
if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
// if the files are read-only, need to first do a "save as".
Base.showMessage(tr("Sketch is read-only"),
tr("Some files are marked \"read-only\", so you'll\n" +
@ -637,7 +639,7 @@ public class Sketch {
protected boolean saveAs() throws IOException {
// get new name for folder
FileDialog fd = new FileDialog(editor, tr("Save sketch folder as..."), FileDialog.SAVE);
if (isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath()) || isUntitled()) {
if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath()) || isUntitled()) {
// default to the sketchbook folder
fd.setDirectory(BaseNoGui.getSketchbookFolder().getAbsolutePath());
} else {
@ -772,7 +774,7 @@ public class Sketch {
ensureExistence();
// if read-only, give an error
if (isReadOnly(BaseNoGui.getLibrariesPath(), BaseNoGui.getExamplesPath())) {
if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
// if the files are read-only, need to first do a "save as".
Base.showMessage(tr("Sketch is Read-Only"),
tr("Some files are marked \"read-only\", so you'll\n" +
@ -1226,12 +1228,12 @@ public class Sketch {
* @param librariesPaths
* @param examplesPath
*/
public boolean isReadOnly(List<File> librariesPaths, String examplesPath) {
public boolean isReadOnly(LibraryList libraries, String examplesPath) {
String apath = data.getFolder().getAbsolutePath();
for (File folder : librariesPaths) {
if (apath.startsWith(folder.getAbsolutePath())) {
return true;
}
Optional<UserLibrary> libraryThatIncludesSketch = libraries.stream().filter(lib -> apath.startsWith(lib.getInstalledFolder().getAbsolutePath())).findFirst();
if (libraryThatIncludesSketch.isPresent() && !libraryThatIncludesSketch.get().onGoingDevelopment()) {
return true;
}
return sketchIsSystemExample(apath, examplesPath) || sketchFilesAreReadOnly();

View File

@ -42,6 +42,8 @@ public class Constants {
public static final List<String> PROTECTED_PACKAGE_NAMES = Arrays.asList("arduino", "Intel");
public static final String PACKAGE_INDEX_URL;
public static final String LIBRARY_DEVELOPMENT_FLAG_FILE = ".development";
static {
String extenalPackageIndexUrl = System.getProperty("PACKAGE_INDEX_URL");
if (extenalPackageIndexUrl != null && !"".equals(extenalPackageIndexUrl)) {

View File

@ -28,6 +28,7 @@
*/
package processing.app.packages;
import cc.arduino.Constants;
import cc.arduino.contributions.libraries.ContributedLibrary;
import cc.arduino.contributions.libraries.ContributedLibraryReference;
import processing.app.helpers.FileUtils;
@ -35,6 +36,8 @@ import processing.app.helpers.PreferencesMap;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
@ -54,6 +57,7 @@ public class UserLibrary extends ContributedLibrary {
private List<String> architectures;
private List<String> types;
private List<String> declaredTypes;
private boolean onGoingDevelopment;
private static final List<String> MANDATORY_PROPERTIES = Arrays
.asList("name", "version", "author", "maintainer",
@ -124,7 +128,7 @@ public class UserLibrary extends ContributedLibrary {
String architectures = properties.get("architectures");
if (architectures == null)
architectures = "*"; // defaults to "any"
List<String> archs = new ArrayList<String>();
List<String> archs = new ArrayList<>();
for (String arch : architectures.split(","))
archs.add(arch.trim());
@ -145,7 +149,7 @@ public class UserLibrary extends ContributedLibrary {
if (types == null) {
types = "Contributed";
}
List<String> typesList = new LinkedList<String>();
List<String> typesList = new LinkedList<>();
for (String type : types.split(",")) {
typesList.add(type.trim());
}
@ -165,6 +169,7 @@ public class UserLibrary extends ContributedLibrary {
res.architectures = archs;
res.layout = layout;
res.declaredTypes = typesList;
res.onGoingDevelopment = Files.exists(Paths.get(libFolder.getAbsolutePath(), Constants.LIBRARY_DEVELOPMENT_FLAG_FILE));
return res;
}
@ -265,6 +270,10 @@ public class UserLibrary extends ContributedLibrary {
return declaredTypes;
}
public boolean onGoingDevelopment() {
return onGoingDevelopment;
}
protected enum LibraryLayout {
FLAT, RECURSIVE
}