diff --git a/app/src/processing/app/contrib/Contribution.java b/app/src/processing/app/contrib/Contribution.java index 65b6ec09c..4b01c106e 100644 --- a/app/src/processing/app/contrib/Contribution.java +++ b/app/src/processing/app/contrib/Contribution.java @@ -316,6 +316,27 @@ abstract public class Contribution { } + /** + * Helper function that creates a StringList of the compatible Modes + * for this Contribution. + */ + static StringList parseModeList(StringDict properties) { + String unparsedModes = properties.get(MODES_PROPERTY); + + // Workaround for 3.0 alpha/beta bug for 3.0b2 + if ("null".equals(unparsedModes)) { + properties.remove(MODES_PROPERTY); + unparsedModes = null; + } + + StringList outgoing = new StringList(); + if (unparsedModes != null) { + outgoing.append(PApplet.trim(PApplet.split(unparsedModes, ','))); + } + return outgoing; + } + + static private String translateCategory(String cat) { // Converts Other to other, I/O to i_o, Video & Vision to video_vision String cleaned = cat.replaceAll("[\\W]+", "_").toLowerCase(); diff --git a/app/src/processing/app/contrib/ExamplesContribution.java b/app/src/processing/app/contrib/ExamplesContribution.java index c922eea9a..2e091c721 100644 --- a/app/src/processing/app/contrib/ExamplesContribution.java +++ b/app/src/processing/app/contrib/ExamplesContribution.java @@ -7,7 +7,6 @@ import java.util.Map; import processing.app.Base; import processing.app.Mode; -import processing.core.PApplet; import processing.data.StringDict; import processing.data.StringList; import static processing.app.contrib.ContributionType.EXAMPLES; @@ -31,34 +30,17 @@ public class ExamplesContribution extends LocalContribution { } - static private StringList parseModeList(StringDict properties) { - String unparsedModes = properties.get(MODES_PROPERTY); - - // Workaround for 3.0 alpha/beta bug for 3.0b2 - if ("null".equals(unparsedModes)) { - properties.remove(MODES_PROPERTY); - unparsedModes = null; - } - - StringList outgoing = new StringList(); - if (unparsedModes != null) { - outgoing.append(PApplet.trim(PApplet.split(unparsedModes, ','))); - } - return outgoing; + static public boolean isCompatible(Base base, StringDict props) { + return isCompatible(base.getActiveEditor().getMode(), props); } /** * Function to determine whether or not the example present in the * exampleLocation directory is compatible with the current mode. - * - * @param base - * @param props - * @return true if the example is compatible with the mode of the currently - * active editor + * @return true if compatible with the Mode of the currently active editor */ - static public boolean isCompatible(Base base, StringDict props) { - Mode mode = base.getActiveEditor().getMode(); + static public boolean isCompatible(Mode mode, StringDict props) { String currentIdentifier = mode.getIdentifier(); StringList compatibleList = parseModeList(props); if (compatibleList.size() == 0) { @@ -69,12 +51,7 @@ public class ExamplesContribution extends LocalContribution { // if no Mode specified, assume compatible everywhere return true; } - for (String c : compatibleList) { - if (c.equals(currentIdentifier)) { - return true; - } - } - return false; + return compatibleList.hasValue(currentIdentifier); }