Skip to content

Commit f712c65

Browse files
committed
add Mode.requireCompatibility() and clear up shadowing field
1 parent 4207712 commit f712c65

File tree

4 files changed

+31
-22
lines changed

4 files changed

+31
-22
lines changed

app/src/processing/app/Mode.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,11 @@ public File getReferenceFolder() {
345345
public void rebuildLibraryList() {
346346
//new Exception("Rebuilding library list").printStackTrace(System.out);
347347
// reset the table mapping imports to libraries
348-
HashMap<String, List<Library>> importToLibraryTable = new HashMap<>();
348+
Map<String, List<Library>> newTable = new HashMap<>();
349349

350350
Library core = getCoreLibrary();
351351
if (core != null) {
352-
core.addPackageList(importToLibraryTable);
352+
core.addPackageList(newTable);
353353
}
354354

355355
coreLibraries = Library.list(librariesFolder);
@@ -367,28 +367,16 @@ public void rebuildLibraryList() {
367367
coreLibraries.addAll(foundationLibraries);
368368
contribLibraries.removeAll(foundationLibraries);
369369

370-
/*
371-
File sketchbookLibs = Base.getSketchbookLibrariesFolder();
372-
File videoFolder = new File(sketchbookLibs, "video");
373-
if (videoFolder.exists()) {
374-
coreLibraries.add(new Library(videoFolder));
375-
}
376-
File soundFolder = new File(sketchbookLibs, "sound");
377-
if (soundFolder.exists()) {
378-
coreLibraries.add(new Library(soundFolder));
379-
}
380-
*/
381-
382370
for (Library lib : coreLibraries) {
383-
lib.addPackageList(importToLibraryTable);
371+
lib.addPackageList(newTable);
384372
}
385373

386374
for (Library lib : contribLibraries) {
387-
lib.addPackageList(importToLibraryTable);
375+
lib.addPackageList(newTable);
388376
}
389377

390378
// Make this Map thread-safe
391-
this.importToLibraryTable = Collections.unmodifiableMap(importToLibraryTable);
379+
importToLibraryTable = Collections.unmodifiableMap(newTable);
392380

393381
if (base != null) {
394382
base.getEditors().forEach(Editor::librariesChanged);
@@ -630,6 +618,18 @@ public void actionPerformed(ActionEvent e) {
630618
}
631619

632620

621+
/**
622+
* Require examples to explicitly state that they're compatible with this
623+
* Mode before they're included. Helpful for Modes like p5js or Python
624+
* where the .java examples cannot be used.
625+
* @since 3.2
626+
* @return true if an examples package must list this Mode's identifier
627+
*/
628+
public boolean requireExampleCompatibility() {
629+
return false;
630+
}
631+
632+
633633
/**
634634
* Override this to control the order of the first set of example folders
635635
* and how they appear in the examples window.

app/src/processing/app/contrib/ExamplesContribution.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.Map;
77

88
import processing.app.Base;
9+
import processing.app.Mode;
910
import processing.core.PApplet;
1011
import processing.data.StringDict;
1112
import processing.data.StringList;
@@ -57,11 +58,16 @@ static private StringList parseModeList(StringDict properties) {
5758
* active editor
5859
*/
5960
static public boolean isCompatible(Base base, StringDict props) {
60-
String currentIdentifier =
61-
base.getActiveEditor().getMode().getIdentifier();
61+
Mode mode = base.getActiveEditor().getMode();
62+
String currentIdentifier = mode.getIdentifier();
6263
StringList compatibleList = parseModeList(props);
6364
if (compatibleList.size() == 0) {
64-
return true; // if no mode specified, assume compatible everywhere
65+
if (mode.requireExampleCompatibility()) {
66+
// for p5js (and maybe Python), examples must specify that they work
67+
return false;
68+
}
69+
// if no Mode specified, assume compatible everywhere
70+
return true;
6571
}
6672
for (String c : compatibleList) {
6773
if (c.equals(currentIdentifier)) {

app/src/processing/app/ui/ExamplesFrame.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,7 @@ protected DefaultMutableTreeNode buildTree() {
342342
e.printStackTrace();
343343
}
344344

345-
DefaultMutableTreeNode contributedExamplesNode =
346-
buildContribTree();
345+
DefaultMutableTreeNode contributedExamplesNode = buildContribTree();
347346
if (contributedExamplesNode.getChildCount() > 0) {
348347
root.add(contributedExamplesNode);
349348
}

todo.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ o saying "no" to save changes is the same as "cancel" on windows?
2020
X can't reproduce
2121
X add printStackTrace() method that can be overridden
2222
X https://github.com/processing/processing/issues/222
23+
X write preferences.txt using a temporary file
24+
X also save the previous version as preferences.old
25+
X https://github.com/processing/processing/issues/4614
2326
_ update launch4j to 3.9
2427
_ https://sourceforge.net/projects/launch4j/files/launch4j-3/3.9/
2528

@@ -41,6 +44,7 @@ X implement templates
4144
_ write short docs
4245
_ https://github.com/processing/processing/issues/4306
4346
_ https://github.com/processing/processing/issues/4352
47+
X add Mode.requireExampleCompatibility()
4448

4549
contrib
4650
X use HTML to print

0 commit comments

Comments
 (0)