Show contributed examples in the Examples window (fixes #3420)

This commit is contained in:
Ben Fry
2015-08-09 12:39:42 -04:00
parent c9dc9a72c3
commit d0d9acdf3e
5 changed files with 40 additions and 40 deletions
+23 -23
View File
@@ -661,7 +661,6 @@ public abstract class Mode {
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Examples");
try {
File[] examples = getExampleCategoryFolders();
for (File subFolder : examples) {
@@ -706,7 +705,7 @@ public abstract class Mode {
DefaultMutableTreeNode contributedExamplesNode =
buildContributedExamplesTrees();
if(contributedExamplesNode.getChildCount() > 0){
if (contributedExamplesNode.getChildCount() > 0) {
root.add(contributedExamplesNode);
}
@@ -721,27 +720,28 @@ public abstract class Mode {
try {
File[] subfolders =
ContributionType.EXAMPLES.listCandidates(examplesContribFolder);
if (subfolders == null) {
subfolders = new File[0]; //empty array
}
for (File sub : subfolders) {
if (!ExamplesContribution.isCompatible(base, sub))
continue;
DefaultMutableTreeNode subNode =
new DefaultMutableTreeNode(sub.getName());
if (base.addSketches(subNode, sub)) {
contribExamplesNode.add(subNode);
int exampleNodeNumber = -1;
for (int y = 0; y < subNode.getChildCount(); y++)
if (subNode.getChildAt(y).toString().equals("examples"))
exampleNodeNumber = y;
if (exampleNodeNumber == -1)
continue;
TreeNode exampleNode = subNode.getChildAt(exampleNodeNumber);
subNode.remove(exampleNodeNumber);
int count = exampleNode.getChildCount();
for (int x = 0; x < count; x++) {
subNode.add((DefaultMutableTreeNode) exampleNode.getChildAt(0));
if (subfolders != null) {
for (File sub : subfolders) {
if (ExamplesContribution.isCompatible(base, sub)) {
DefaultMutableTreeNode subNode =
new DefaultMutableTreeNode(sub.getName());
if (base.addSketches(subNode, sub)) {
contribExamplesNode.add(subNode);
int exampleNodeNumber = -1;
for (int y = 0; y < subNode.getChildCount(); y++) {
if (subNode.getChildAt(y).toString().equals("examples")) {
exampleNodeNumber = y;
}
}
if (exampleNodeNumber != -1) {
TreeNode exampleNode = subNode.getChildAt(exampleNodeNumber);
subNode.remove(exampleNodeNumber);
int count = exampleNode.getChildCount();
for (int x = 0; x < count; x++) {
subNode.add((DefaultMutableTreeNode) exampleNode.getChildAt(0));
}
}
}
}
}
}
@@ -239,8 +239,9 @@ public class AvailableContribution extends Contribution {
StringDict properties = Util.readSettings(propFile);
String name = properties.get("name");
if (name == null || name.isEmpty())
if (name == null || name.isEmpty()) {
name = getName();
}
String category;
StringList categoryList = parseCategories(properties);
@@ -248,15 +249,6 @@ public class AvailableContribution extends Contribution {
categoryList.get(0).equals(UNKNOWN_CATEGORY)) {
category = getCategoryStr();
} else {
/*
StringBuilder sb = new StringBuilder();
for (String cat : categories) {
sb.append(cat);
sb.append(',');
}
sb.deleteCharAt(sb.length() - 1);
category = sb.toString();
*/
category = categoryList.join(",");
}
@@ -299,7 +291,6 @@ public class AvailableContribution extends Contribution {
prettyVersion = getPrettyVersion();
String compatibleContribsList = null;
if (getType() == ContributionType.EXAMPLES) {
compatibleContribsList = properties.get(MODES_PROPERTY);
}
@@ -352,7 +343,9 @@ public class AvailableContribution extends Contribution {
writer.println("imports=" + importsList.join(","));
}
if (getType() == ContributionType.EXAMPLES) {
writer.println(MODES_PROPERTY + "=" + compatibleContribsList);
if (compatibleContribsList != null) {
writer.println(MODES_PROPERTY + "=" + compatibleContribsList);
}
}
writer.flush();
@@ -31,11 +31,8 @@ import processing.app.Language;
abstract public class Contribution {
static final String IMPORTS_PROPERTY = "imports";
// static final String CATEGORIES_PROPERTY = "category";
static final String CATEGORIES_PROPERTY = "categories";
//static final String MODES_PROPERTY = "compatibleModesList";
static final String MODES_PROPERTY = "modes";
//static final String AUTHORS_PROPERTY = "authorList";
static final String AUTHORS_PROPERTY = "authors";
static final String SPECIAL_CATEGORY = "Starred";
@@ -33,6 +33,13 @@ 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, ',')));
@@ -51,14 +58,15 @@ public class ExamplesContribution extends LocalContribution {
* active editor
*/
static public boolean isCompatible(Base base, File exampleFolder) {
String currentIdentifier = base.getActiveEditor().getMode().getIdentifier();
String currentIdentifier =
base.getActiveEditor().getMode().getIdentifier();
File propertiesFile =
new File(exampleFolder, EXAMPLES.getPropertiesName());
if (propertiesFile.exists()) {
StringList compatibleList =
parseModeList(Util.readSettings(propertiesFile));
if (compatibleList.size() == 0) {
return true; // if no mode specified, just include everywhere
return true; // if no mode specified, assume compatible everywhere
}
for (String c : compatibleList) {
if (c.equals(currentIdentifier)) {
+2
View File
@@ -12,6 +12,8 @@ X Initialize the Find dialog with the current selection
X https://github.com/processing/processing/issues/3457
X Links in error bar are not selectable nor clickable
X https://github.com/processing/processing/issues/3471
X Show contributed examples in the Examples window
X https://github.com/processing/processing/issues/3420
export
X save export settings to preferences