diff --git a/app/src/processing/app/Mode.java b/app/src/processing/app/Mode.java index 86db49269..31b82fc56 100644 --- a/app/src/processing/app/Mode.java +++ b/app/src/processing/app/Mode.java @@ -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> importToLibraryTable = new HashMap<>(); + Map> 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. diff --git a/app/src/processing/app/contrib/ExamplesContribution.java b/app/src/processing/app/contrib/ExamplesContribution.java index be4782e4b..c922eea9a 100644 --- a/app/src/processing/app/contrib/ExamplesContribution.java +++ b/app/src/processing/app/contrib/ExamplesContribution.java @@ -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)) { diff --git a/app/src/processing/app/ui/ExamplesFrame.java b/app/src/processing/app/ui/ExamplesFrame.java index de13a4c24..105858a87 100644 --- a/app/src/processing/app/ui/ExamplesFrame.java +++ b/app/src/processing/app/ui/ExamplesFrame.java @@ -342,8 +342,7 @@ public class ExamplesFrame extends JFrame { e.printStackTrace(); } - DefaultMutableTreeNode contributedExamplesNode = - buildContribTree(); + DefaultMutableTreeNode contributedExamplesNode = buildContribTree(); if (contributedExamplesNode.getChildCount() > 0) { root.add(contributedExamplesNode); } diff --git a/todo.txt b/todo.txt index 652544458..667f90556 100755 --- a/todo.txt +++ b/todo.txt @@ -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