mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
prevent examples from showing in the sketchbook window
This commit is contained in:
@@ -1344,14 +1344,24 @@ public class Base {
|
||||
}
|
||||
|
||||
|
||||
protected boolean addSketches(DefaultMutableTreeNode node, File folder) throws IOException {
|
||||
protected boolean addSketches(DefaultMutableTreeNode node,
|
||||
File folder,
|
||||
boolean examples) throws IOException {
|
||||
// skip .DS_Store files, etc (this shouldn't actually be necessary)
|
||||
if (!folder.isDirectory()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't look inside the 'libraries' folders in the sketchbook
|
||||
if (folder.getName().equals("libraries")) {
|
||||
return false; // let's not go there
|
||||
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")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String[] fileList = folder.list();
|
||||
@@ -1363,35 +1373,12 @@ public class Base {
|
||||
// Alphabetize the list, since it's not always alpha order
|
||||
Arrays.sort(fileList, String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
// ActionListener listener = new ActionListener() {
|
||||
// public void actionPerformed(ActionEvent e) {
|
||||
// String path = e.getActionCommand();
|
||||
// if (new File(path).exists()) {
|
||||
// handleOpen(path);
|
||||
// } else {
|
||||
// showWarning("Sketch Disappeared",
|
||||
// "The selected sketch no longer exists.\n" +
|
||||
// "You may need to restart Processing to update\n" +
|
||||
// "the sketchbook menu.", null);
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// offers no speed improvement
|
||||
//menu.addActionListener(listener);
|
||||
|
||||
boolean found = false;
|
||||
for (String name : fileList) {
|
||||
//Skip hidden files
|
||||
if (name.charAt(0) == '.') {
|
||||
if (name.charAt(0) == '.') { // Skip hidden files
|
||||
continue;
|
||||
}
|
||||
|
||||
// JTree tree = null;
|
||||
// TreePath[] a = tree.getSelectionPaths();
|
||||
// for (TreePath path : a) {
|
||||
// Object[] o = path.getPath();
|
||||
// }
|
||||
|
||||
File subfolder = new File(folder, name);
|
||||
if (subfolder.isDirectory()) {
|
||||
File entry = checkSketchFolder(subfolder, name);
|
||||
@@ -1406,7 +1393,7 @@ public class Base {
|
||||
// not a sketch folder, but maybe a subfolder containing sketches
|
||||
DefaultMutableTreeNode subnode = new DefaultMutableTreeNode(name);
|
||||
// needs to be separate var otherwise would set ifound to false
|
||||
boolean anything = addSketches(subnode, subfolder);
|
||||
boolean anything = addSketches(subnode, subfolder, examples);
|
||||
if (anything) {
|
||||
node.add(subnode);
|
||||
found = true;
|
||||
|
||||
@@ -661,11 +661,13 @@ public abstract class Mode {
|
||||
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Examples");
|
||||
|
||||
try {
|
||||
// Get the list of Mode-specific examples, in the order the Mode wants
|
||||
// to present them (i.e. Basics, then Topics, then Demos...)
|
||||
File[] examples = getExampleCategoryFolders();
|
||||
|
||||
for (File subFolder : examples) {
|
||||
DefaultMutableTreeNode subNode = new DefaultMutableTreeNode(subFolder.getName());
|
||||
if (base.addSketches(subNode, subFolder)) {
|
||||
if (base.addSketches(subNode, subFolder, true)) {
|
||||
root.add(subNode);
|
||||
}
|
||||
}
|
||||
@@ -677,11 +679,12 @@ public abstract class Mode {
|
||||
for (Library lib : coreLibraries) {
|
||||
if (lib.hasExamples()) {
|
||||
DefaultMutableTreeNode libNode = new DefaultMutableTreeNode(lib.getName());
|
||||
if (base.addSketches(libNode, lib.getExamplesFolder()))
|
||||
if (base.addSketches(libNode, lib.getExamplesFolder(), true)) {
|
||||
foundationLibraries.add(libNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(foundationLibraries.getChildCount() > 0) {
|
||||
if (foundationLibraries.getChildCount() > 0) {
|
||||
root.add(foundationLibraries);
|
||||
}
|
||||
|
||||
@@ -692,11 +695,11 @@ public abstract class Mode {
|
||||
if (lib.hasExamples()) {
|
||||
DefaultMutableTreeNode libNode =
|
||||
new DefaultMutableTreeNode(lib.getName());
|
||||
base.addSketches(libNode, lib.getExamplesFolder());
|
||||
base.addSketches(libNode, lib.getExamplesFolder(), true);
|
||||
contributedLibExamples.add(libNode);
|
||||
}
|
||||
}
|
||||
if(contributedLibExamples.getChildCount() > 0){
|
||||
if (contributedLibExamples.getChildCount() > 0) {
|
||||
root.add(contributedLibExamples);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@@ -725,7 +728,7 @@ public abstract class Mode {
|
||||
if (ExamplesContribution.isCompatible(base, sub)) {
|
||||
DefaultMutableTreeNode subNode =
|
||||
new DefaultMutableTreeNode(sub.getName());
|
||||
if (base.addSketches(subNode, sub)) {
|
||||
if (base.addSketches(subNode, sub, true)) {
|
||||
contribExamplesNode.add(subNode);
|
||||
int exampleNodeNumber = -1;
|
||||
for (int y = 0; y < subNode.getChildCount(); y++) {
|
||||
@@ -1010,7 +1013,7 @@ public abstract class Mode {
|
||||
DefaultMutableTreeNode sbNode =
|
||||
new DefaultMutableTreeNode(Language.text("sketchbook.tree"));
|
||||
try {
|
||||
base.addSketches(sbNode, Base.getSketchbookFolder());
|
||||
base.addSketches(sbNode, Base.getSketchbookFolder(), false);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -1064,16 +1067,17 @@ public abstract class Mode {
|
||||
});
|
||||
|
||||
tree.addKeyListener(new KeyAdapter() {
|
||||
// ESC doesn't fire keyTyped(), so we have to catch it on keyPressed
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { // doesn't fire keyTyped()
|
||||
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
|
||||
sketchbookFrame.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void keyTyped(KeyEvent e) {
|
||||
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
|
||||
DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree
|
||||
.getLastSelectedPathComponent();
|
||||
DefaultMutableTreeNode node =
|
||||
(DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
|
||||
if (node != null && node.isLeaf()) {
|
||||
SketchReference sketch = (SketchReference) node.getUserObject();
|
||||
base.handleOpen(sketch.getPath());
|
||||
|
||||
@@ -3,7 +3,7 @@ X don't show breakpoints when debugger is off
|
||||
X https://github.com/processing/processing/issues/3093
|
||||
X no setting breakpoints when debugger is off
|
||||
X https://github.com/processing/processing/issues/3306
|
||||
_ 'examples' shows as a folder in the sketchbook window
|
||||
X 'examples' shows as a folder in the sketchbook window
|
||||
|
||||
cleaning/earlier
|
||||
X move to launch4j 3.7 http://launch4j.sourceforge.net/
|
||||
|
||||
Reference in New Issue
Block a user