diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index c124ec28a..b7afdf66e 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -103,8 +103,8 @@ public class Base { private Mode coreMode; // TODO can these be Set objects, or are they expected to be in order? - protected List contribModes; - protected List contribExamples; + private List contribModes; + private List contribExamples; /** These aren't even dynamically loaded, they're hard-wired here. */ private List internalTools; @@ -716,16 +716,9 @@ public class Base { } - /** - * Instantiates and adds new contributed modes to the contribModes list. - * Checks for duplicates so the same mode isn't instantiates twice. Does not - * remove modes because modes can't be removed once they are instantiated. - */ void rebuildContribExamples() { - if (contribExamples == null) { - contribExamples = new ArrayList<>(); - } - ExamplesContribution.loadMissing(this); + contribExamples = + ExamplesContribution.loadAll(getSketchbookExamplesFolder()); } @@ -733,11 +726,11 @@ public class Base { /** - * Tools require an 'Editor' object when they're instantiated, but the - * activeEditor will be null when the first Editor that opens is creating - * its Tools menu. This will temporarily set the activeEditor to the one - * that's opening so that we don't go all NPE on startup. If there's already - * an active editor, then this does nothing. + * Tools require an 'Editor' object when they're instantiated, but + * the activeEditor will be null when the first Editor that opens is + * creating its Tools menu. This will temporarily set the activeEditor + * to the one that's opening so that we don't go all NPE on startup. + * If there's already an active editor, then this does nothing. */ public void checkFirstEditor(Editor editor) { if (activeEditor == null) { @@ -831,20 +824,16 @@ public class Base { } - public List getToolContribs() { + public List getContribTools() { +// if (contribTools == null) { +// contribTools = ToolContribution.loadAll(Base.getSketchbookToolsFolder()); +// } return contribTools; } - /* - public void removeToolContrib(ToolContribution tc) { - contribTools.remove(tc); - } - */ - - public void rebuildToolList() { - // Only do this once because the list of internal tools will never change + // Only do these once because the list of internal tools will never change if (internalTools == null) { internalTools = new ArrayList<>(); @@ -860,7 +849,7 @@ public class Base { //initInternalTool("processing.app.tools.UpdateTheme"); } - // No need to reload these either + // Only init() these the first time they're loaded if (coreTools == null) { coreTools = ToolContribution.loadAll(Base.getToolsFolder()); for (Tool tool : coreTools) { @@ -868,7 +857,7 @@ public class Base { } } - // Rebuilt when new tools installed, etc + // Reset the contributed tools and re-init() all of them. contribTools = ToolContribution.loadAll(Base.getSketchbookToolsFolder()); for (Tool tool : contribTools) { try { @@ -1048,7 +1037,7 @@ public class Base { // For 4.1.2, not reloading all the tools here. Just in case it causes a // regression b/c it's not clear why it was written that way. [fry 230110] - contributions.addAll(contribTools); + contributions.addAll(getContribTools()); contributions.addAll(getContribExamples()); return contributions; diff --git a/app/src/processing/app/Mode.java b/app/src/processing/app/Mode.java index 21fabc209..29e9ad6d3 100644 --- a/app/src/processing/app/Mode.java +++ b/app/src/processing/app/Mode.java @@ -73,7 +73,9 @@ public abstract class Mode { public List coreLibraries; public List contribLibraries; - public List foundationLibraries; + + // Initialize to empty b/c these may not exist for contributed Mode classes. + public List foundationLibraries = new ArrayList<>(); /** Library folder for core. (Used for OpenGL in particular.) */ protected Library coreLibrary; @@ -768,7 +770,7 @@ public abstract class Mode { * Returns the appropriate file extension to use for auxiliary source * files in a sketch. For example, in a Java-mode sketch, auxiliary files * can be named "Foo.java"; in Python mode, they should be named "foo.py". - * + *

* Modes that do not override this function will get the * default behavior of returning the default extension. */ diff --git a/app/src/processing/app/contrib/ContributionListing.java b/app/src/processing/app/contrib/ContributionListing.java index 4bec1b6b3..abc2d0683 100644 --- a/app/src/processing/app/contrib/ContributionListing.java +++ b/app/src/processing/app/contrib/ContributionListing.java @@ -345,7 +345,7 @@ public class ContributionListing { } } } - for (ToolContribution tc : base.getToolContribs()) { + for (ToolContribution tc : base.getContribTools()) { if (hasUpdates(tc)) { count++; } diff --git a/app/src/processing/app/contrib/ContributionTab.java b/app/src/processing/app/contrib/ContributionTab.java index 6592824de..af74897e5 100644 --- a/app/src/processing/app/contrib/ContributionTab.java +++ b/app/src/processing/app/contrib/ContributionTab.java @@ -323,7 +323,7 @@ public class ContributionTab extends JPanel { // List tools = base.getToolContribs(); // contributions.addAll(tools); - contributions.addAll(base.getToolContribs()); + contributions.addAll(base.getContribTools()); // List modes = base.getModeContribs(); // contributions.addAll(modes); diff --git a/app/src/processing/app/contrib/ContributionType.java b/app/src/processing/app/contrib/ContributionType.java index 6c6ff7eac..971838b4a 100644 --- a/app/src/processing/app/contrib/ContributionType.java +++ b/app/src/processing/app/contrib/ContributionType.java @@ -182,7 +182,7 @@ public enum ContributionType { } break; case TOOL: - contribs.addAll(base.getToolContribs()); + contribs.addAll(base.getContribTools()); break; case MODE: contribs.addAll(base.getModeContribs()); diff --git a/app/src/processing/app/contrib/ExamplesContribution.java b/app/src/processing/app/contrib/ExamplesContribution.java index e264d7da0..3607438c6 100644 --- a/app/src/processing/app/contrib/ExamplesContribution.java +++ b/app/src/processing/app/contrib/ExamplesContribution.java @@ -1,19 +1,43 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Processing project - https://processing.org + + Copyright (c) 2014-23 The Processing Foundation + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ package processing.app.contrib; import java.io.File; -import java.util.HashMap; +import java.util.ArrayList; +import java.util.Comparator; import java.util.List; -import java.util.Map; import processing.app.Base; import processing.app.Mode; import processing.data.StringDict; import processing.data.StringList; + import static processing.app.contrib.ContributionType.EXAMPLES; public class ExamplesContribution extends LocalContribution { - private StringList modeList; + + private ExamplesContribution(File folder) { + super(folder); + } static public ExamplesContribution load(File folder) { @@ -21,12 +45,18 @@ public class ExamplesContribution extends LocalContribution { } - private ExamplesContribution(File folder) { - super(folder); - - if (properties != null) { - modeList = parseModeList(properties); + static public List loadAll(File examplesFolder) { + List outgoing = new ArrayList<>(); + File[] potential = EXAMPLES.listCandidates(examplesFolder); + // If examplesFolder does not exist or is inaccessible (stranger things + // have happened, and are reported as bugs) the list will come back null. + if (potential != null) { + for (File folder : potential) { + outgoing.add(load(folder)); + } } + outgoing.sort(Comparator.comparing(Contribution::getName)); + return outgoing; } @@ -54,45 +84,8 @@ public class ExamplesContribution extends LocalContribution { } - static public boolean isCompatible(Base base, File exampleFolder) { - StringDict props = loadProperties(exampleFolder, EXAMPLES); - if (props != null) { - return isCompatible(base, props); - } - // Require a proper .properties file to show up - return false; - } - - - - static public void loadMissing(Base base) { - File examplesFolder = Base.getSketchbookExamplesFolder(); - List contribExamples = base.getContribExamples(); - - Map existing = new HashMap<>(); - for (ExamplesContribution contrib : contribExamples) { - existing.put(contrib.getFolder(), contrib); - } - File[] potential = EXAMPLES.listCandidates(examplesFolder); - // If modesFolder does not exist or is inaccessible (folks might like to - // mess with folders then report it as a bug) 'potential' will be null. - if (potential != null) { - for (File folder : potential) { - if (!existing.containsKey(folder)) { - contribExamples.add(new ExamplesContribution(folder)); - } - } - } - } - - @Override public ContributionType getType() { return EXAMPLES; } - - - public StringList getModeList() { - return modeList; - } } diff --git a/app/src/processing/app/contrib/ToolContribution.java b/app/src/processing/app/contrib/ToolContribution.java index 955220cc2..660d76bbb 100644 --- a/app/src/processing/app/contrib/ToolContribution.java +++ b/app/src/processing/app/contrib/ToolContribution.java @@ -3,7 +3,7 @@ /* Part of the Processing project - https://processing.org - Copyright (c) 2013-22 The Processing Foundation + Copyright (c) 2013-23 The Processing Foundation Copyright (c) 2011-12 Ben Fry and Casey Reas This program is free software; you can redistribute it and/or modify @@ -30,7 +30,7 @@ import processing.app.Messages; import processing.app.tools.Tool; -public class ToolContribution extends LocalContribution implements Tool, Comparable { +public class ToolContribution extends LocalContribution implements Tool { private Tool tool; final private File referenceFile; // shortname/reference/index.html @@ -84,9 +84,9 @@ public class ToolContribution extends LocalContribution implements Tool, Compara static public List loadAll(File toolsFolder) { File[] list = ContributionType.TOOL.listCandidates(toolsFolder); - ArrayList outgoing = new ArrayList<>(); + List outgoing = new ArrayList<>(); // If toolsFolder does not exist or is inaccessible (stranger things have - // happened, and are reported as bugs) list will come back null. + // happened, and are reported as bugs) the list will come back null. if (list != null) { for (File folder : list) { try { @@ -99,7 +99,7 @@ public class ToolContribution extends LocalContribution implements Tool, Compara } } } - Collections.sort(outgoing); + outgoing.sort(Comparator.comparing(ToolContribution::getMenuTitle)); return outgoing; } @@ -140,10 +140,4 @@ public class ToolContribution extends LocalContribution implements Tool, Compara public boolean hasReference() { return referenceFile.exists(); } - - - @Override - public int compareTo(ToolContribution o) { - return getMenuTitle().compareTo(o.getMenuTitle()); - } } diff --git a/java/src/processing/mode/java/JavaEditor.java b/java/src/processing/mode/java/JavaEditor.java index 253efcdd1..fe215e723 100644 --- a/java/src/processing/mode/java/JavaEditor.java +++ b/java/src/processing/mode/java/JavaEditor.java @@ -358,7 +358,7 @@ public class JavaEditor extends Editor { boolean coreToolMenuItemAdded; boolean contribToolMenuItemAdded; - List contribTools = base.getToolContribs(); + List contribTools = base.getContribTools(); // Adding this in in case a reference folder is added for MovieMaker, or in case // other core tools are introduced later coreToolMenuItemAdded = addToolReferencesToSubMenu(base.getCoreTools(), toolRefSubmenu); diff --git a/todo.txt b/todo.txt index 7e062acbb..672295c46 100755 --- a/todo.txt +++ b/todo.txt @@ -1,10 +1,7 @@ 1290 (4.1.2?) -X add foundation libraries to the stats (https://download.processing.org/stats/) -X make foundationLibraries a class var, and then access it when calling download() -X also removed the "new ArrayList()" wrapping in getInstalledContribs() -X seemed extraneous, perhaps dates to that being an array instead of a List? -contrib + +contributed X “Cannot find a class or type named ‘PApplet’” error X https://github.com/processing/processing4/issues/626 X https://github.com/processing/processing4/pull/635 @@ -12,6 +9,18 @@ X cannot use @Override and @Deprecated in static mode X https://github.com/processing/processing4/issues/619 X https://github.com/processing/processing4/pull/622 +manager +X add foundation libraries to the stats (https://download.processing.org/stats/) +X make foundationLibraries a class var, and then access it when calling download() +X also removed the "new ArrayList()" wrapping in getInstalledContribs() +X seemed extraneous, perhaps dates to that being an array instead of a List? +X rewrite of half of ExamplesContribution +X cleaning up methods for initializing various contribs in Base +X replace getToolContribs() with getContribTools() for consistency +_ Mode manager window is empty +_ https://github.com/processing/processing4/issues/613 +_ Cannot invoke "javax.swing.JProgressBar.setVisible(boolean)" because "this.progressBar" is null +_ https://github.com/processing/processing4/issues/618 _ make ctrl-g work inside the find window