add Mode.requireCompatibility() and clear up shadowing field

This commit is contained in:
Ben Fry
2016-08-13 17:54:12 -04:00
parent 66b18b1c0d
commit 0d8e26bb11
4 changed files with 31 additions and 22 deletions

View File

@@ -345,11 +345,11 @@ public abstract class Mode {
public void rebuildLibraryList() {
//new Exception("Rebuilding library list").printStackTrace(System.out);
// reset the table mapping imports to libraries
HashMap<String, List<Library>> importToLibraryTable = new HashMap<>();
Map<String, List<Library>> newTable = new HashMap<>();
Library core = getCoreLibrary();
if (core != null) {
core.addPackageList(importToLibraryTable);
core.addPackageList(newTable);
}
coreLibraries = Library.list(librariesFolder);
@@ -367,28 +367,16 @@ public abstract class Mode {
coreLibraries.addAll(foundationLibraries);
contribLibraries.removeAll(foundationLibraries);
/*
File sketchbookLibs = Base.getSketchbookLibrariesFolder();
File videoFolder = new File(sketchbookLibs, "video");
if (videoFolder.exists()) {
coreLibraries.add(new Library(videoFolder));
}
File soundFolder = new File(sketchbookLibs, "sound");
if (soundFolder.exists()) {
coreLibraries.add(new Library(soundFolder));
}
*/
for (Library lib : coreLibraries) {
lib.addPackageList(importToLibraryTable);
lib.addPackageList(newTable);
}
for (Library lib : contribLibraries) {
lib.addPackageList(importToLibraryTable);
lib.addPackageList(newTable);
}
// Make this Map thread-safe
this.importToLibraryTable = Collections.unmodifiableMap(importToLibraryTable);
importToLibraryTable = Collections.unmodifiableMap(newTable);
if (base != null) {
base.getEditors().forEach(Editor::librariesChanged);
@@ -630,6 +618,18 @@ public abstract class Mode {
}
/**
* Require examples to explicitly state that they're compatible with this
* Mode before they're included. Helpful for Modes like p5js or Python
* where the .java examples cannot be used.
* @since 3.2
* @return true if an examples package must list this Mode's identifier
*/
public boolean requireExampleCompatibility() {
return false;
}
/**
* Override this to control the order of the first set of example folders
* and how they appear in the examples window.

View File

@@ -6,6 +6,7 @@ import java.util.List;
import java.util.Map;
import processing.app.Base;
import processing.app.Mode;
import processing.core.PApplet;
import processing.data.StringDict;
import processing.data.StringList;
@@ -57,11 +58,16 @@ public class ExamplesContribution extends LocalContribution {
* active editor
*/
static public boolean isCompatible(Base base, StringDict props) {
String currentIdentifier =
base.getActiveEditor().getMode().getIdentifier();
Mode mode = base.getActiveEditor().getMode();
String currentIdentifier = mode.getIdentifier();
StringList compatibleList = parseModeList(props);
if (compatibleList.size() == 0) {
return true; // if no mode specified, assume compatible everywhere
if (mode.requireExampleCompatibility()) {
// for p5js (and maybe Python), examples must specify that they work
return false;
}
// if no Mode specified, assume compatible everywhere
return true;
}
for (String c : compatibleList) {
if (c.equals(currentIdentifier)) {

View File

@@ -342,8 +342,7 @@ public class ExamplesFrame extends JFrame {
e.printStackTrace();
}
DefaultMutableTreeNode contributedExamplesNode =
buildContribTree();
DefaultMutableTreeNode contributedExamplesNode = buildContribTree();
if (contributedExamplesNode.getChildCount() > 0) {
root.add(contributedExamplesNode);
}

View File

@@ -20,6 +20,9 @@ o saying "no" to save changes is the same as "cancel" on windows?
X can't reproduce
X add printStackTrace() method that can be overridden
X https://github.com/processing/processing/issues/222
X write preferences.txt using a temporary file
X also save the previous version as preferences.old
X https://github.com/processing/processing/issues/4614
_ update launch4j to 3.9
_ https://sourceforge.net/projects/launch4j/files/launch4j-3/3.9/
@@ -41,6 +44,7 @@ X implement templates
_ write short docs
_ https://github.com/processing/processing/issues/4306
_ https://github.com/processing/processing/issues/4352
X add Mode.requireExampleCompatibility()
contrib
X use HTML to print