From ae01eac3b2b0eb1a1a041d26fa2bba3ecd12b45a Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Tue, 11 Aug 2015 10:20:14 -0400 Subject: [PATCH] show pretty name for libraries (fixes #3574) --- app/src/processing/app/Base.java | 14 +++++- app/src/processing/app/Mode.java | 48 ++++++++++++------- app/src/processing/app/SketchReference.java | 12 ++--- .../processing/app/contrib/Contribution.java | 17 +++++++ .../app/contrib/ExamplesContribution.java | 33 +++++++------ core/todo.txt | 4 ++ todo.txt | 11 +++++ 7 files changed, 101 insertions(+), 38 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index d6293522d..5a154a371 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1352,18 +1352,28 @@ public class Base { return false; } + final String folderName = folder.getName(); + // Don't look inside the 'libraries' folders in the sketchbook - if (folder.getName().equals("libraries")) { + if (folderName.equals("libraries")) { return false; } // When building the sketchbook, don't show the contributed 'examples' // like it's a subfolder. But when loading examples, allow the folder // to be named 'examples'. - if (!examples && folder.getName().equals("examples")) { + if (!examples && folderName.equals("examples")) { return false; } +// // Conversely, when looking for examples, ignore the other folders +// // (to avoid going through hoops with the tree node setup). +// if (examples && !folderName.equals("examples")) { +// return false; +// } +// // Doesn't quite work because the parent will be 'examples', and we want +// // to walk inside that, but the folder itself will have a different name + String[] fileList = folder.list(); // If a bad folder or unreadable or whatever, this will come back null if (fileList == null) { diff --git a/app/src/processing/app/Mode.java b/app/src/processing/app/Mode.java index 86772b02d..5f47e2d12 100644 --- a/app/src/processing/app/Mode.java +++ b/app/src/processing/app/Mode.java @@ -38,6 +38,7 @@ import javax.swing.event.TreeExpansionEvent; import javax.swing.event.TreeExpansionListener; import javax.swing.tree.*; +import processing.app.contrib.Contribution; import processing.app.contrib.ContributionType; import processing.app.contrib.ExamplesContribution; import processing.app.syntax.*; @@ -46,6 +47,7 @@ import processing.app.ui.EditorState; import processing.app.ui.Toolkit; import processing.core.PApplet; import processing.core.PConstants; +import processing.data.StringDict; public abstract class Mode { @@ -747,24 +749,38 @@ public abstract class Mode { ContributionType.EXAMPLES.listCandidates(examplesContribFolder); if (subfolders != null) { for (File sub : subfolders) { - if (ExamplesContribution.isCompatible(base, sub)) { - DefaultMutableTreeNode subNode = - new DefaultMutableTreeNode(sub.getName()); - if (base.addSketches(subNode, sub, true)) { - contribExamplesNode.add(subNode); - int exampleNodeNumber = -1; - for (int y = 0; y < subNode.getChildCount(); y++) { - if (subNode.getChildAt(y).toString().equals("examples")) { - exampleNodeNumber = y; + StringDict props = + Contribution.loadProperties(sub, ContributionType.EXAMPLES); + if (props != null) { + if (ExamplesContribution.isCompatible(base, props)) { + DefaultMutableTreeNode subNode = + new DefaultMutableTreeNode(props.get("name")); + if (base.addSketches(subNode, sub, true)) { + contribExamplesNode.add(subNode); + + // TODO there has to be a simpler way of handling this along + // with addSketches() as well [fry 150811] + int exampleNodeNumber = -1; + // The contrib may have other items besides the examples folder + for (int i = 0; i < subNode.getChildCount(); i++) { + if (subNode.getChildAt(i).toString().equals("examples")) { + exampleNodeNumber = i; + } } - } - 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)); + if (exampleNodeNumber != -1) { + TreeNode exampleNode = subNode.getChildAt(exampleNodeNumber); + subNode.remove(exampleNodeNumber); + int count = exampleNode.getChildCount(); + for (int j = 0; j < count; j++) { + subNode.add((DefaultMutableTreeNode) exampleNode.getChildAt(0)); + } } + +// if (subNode.getChildCount() != 1) { +// System.err.println("more children than expected when one is enough"); +// } +// TreeNode exampleNode = subNode.getChildAt(0); +// subNode.add((DefaultMutableTreeNode) exampleNode.getChildAt(0)); } } } diff --git a/app/src/processing/app/SketchReference.java b/app/src/processing/app/SketchReference.java index 7e55f2321..f87fc23f7 100644 --- a/app/src/processing/app/SketchReference.java +++ b/app/src/processing/app/SketchReference.java @@ -6,19 +6,19 @@ import java.io.File; public class SketchReference { String name; File pde; - - + + public SketchReference(String name, File pde) { this.name = name; this.pde = pde; } - - + + public String getPath() { return pde.getAbsolutePath(); } - - + + public String toString() { return name; } diff --git a/app/src/processing/app/contrib/Contribution.java b/app/src/processing/app/contrib/Contribution.java index ac7142394..ddd2cf537 100644 --- a/app/src/processing/app/contrib/Contribution.java +++ b/app/src/processing/app/contrib/Contribution.java @@ -21,6 +21,7 @@ */ package processing.app.contrib; +import java.io.File; import java.util.Arrays; import java.util.List; @@ -28,6 +29,8 @@ import processing.core.PApplet; import processing.data.StringDict; import processing.data.StringList; import processing.app.Language; +import processing.app.Util; + abstract public class Contribution { static final String IMPORTS_PROPERTY = "imports"; @@ -241,6 +244,20 @@ abstract public class Contribution { } + public StringDict loadProperties(File contribFolder) { + return loadProperties(contribFolder, getType()); + } + + + static public StringDict loadProperties(File contribFolder, + ContributionType type) { + File propertiesFile = new File(contribFolder, type.getPropertiesName()); + if (propertiesFile.exists()) { + return Util.readSettings(propertiesFile); + } + return null; + } + /** * @return a single element list with "Unknown" as the category. */ diff --git a/app/src/processing/app/contrib/ExamplesContribution.java b/app/src/processing/app/contrib/ExamplesContribution.java index fb547646b..aa7a14fb7 100644 --- a/app/src/processing/app/contrib/ExamplesContribution.java +++ b/app/src/processing/app/contrib/ExamplesContribution.java @@ -6,7 +6,6 @@ import java.util.List; import java.util.Map; import processing.app.Base; -import processing.app.Util; import processing.core.PApplet; import processing.data.StringDict; import processing.data.StringList; @@ -57,27 +56,33 @@ public class ExamplesContribution extends LocalContribution { * @return true if the example is compatible with the mode of the currently * active editor */ - static public boolean isCompatible(Base base, File exampleFolder) { + static public boolean isCompatible(Base base, StringDict props) { 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, assume compatible everywhere - } - for (String c : compatibleList) { - if (c.equals(currentIdentifier)) { - return true; - } + StringList compatibleList = parseModeList(props); + if (compatibleList.size() == 0) { + return true; // if no mode specified, assume compatible everywhere + } + for (String c : compatibleList) { + if (c.equals(currentIdentifier)) { + return true; } } return false; } + 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.getExampleContribs(); diff --git a/core/todo.txt b/core/todo.txt index 688609a4c..bd0c4be45 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -4,6 +4,10 @@ opengl _ `focused` variable always false in P2D/P3D _ https://github.com/processing/processing/issues/3564 +_ Use PBOs for async texture copy +_ https://github.com/processing/processing/issues/3569 +_ filter(PShader) broken in HiDPI mode +_ https://github.com/processing/processing/issues/3577 _ implement strip(), lstrip(), rstrip? diff --git a/todo.txt b/todo.txt index b32a3e9d0..63e9924cb 100644 --- a/todo.txt +++ b/todo.txt @@ -8,12 +8,23 @@ X Foundation library examples should appear under "Core" or "Foundation" X https://github.com/processing/processing/issues/3524 X Use ctrl-pageup/down on Linux for prev/next tab X https://github.com/processing/processing/issues/3416 +_ Library names not showing up correctly ("pdf" instead of "PDF Export") +_ https://github.com/processing/processing/issues/3574 +_ Contributed examples not using the 'name' field from their properties file +_ seen in Dan's contrib examples +_ Invalid code signature on OS X +_ https://github.com/processing/processing/issues/3575 cleaning/earlier X move to launch4j 3.7 http://launch4j.sourceforge.net/ X actually upgraded to 3.8 X make examples pull/build automatic during dist +gsoc +X Breakpoints don't 'jump' after hitting Enter on blank line +X https://github.com/processing/processing/issues/3552 +X https://github.com/processing/processing/pull/3571 + known issues _ launch4j doesn't work from folders with non-native charsets