diff --git a/app/PdeSketchbook.java b/app/PdeSketchbook.java index 17a736974..b23f51992 100644 --- a/app/PdeSketchbook.java +++ b/app/PdeSketchbook.java @@ -76,7 +76,12 @@ public class PdeSketchbook { sketchbookFolder.mkdirs(); } - sketchbookPath = sketchbookFolder.getCanonicalPath(); + try { + sketchbookPath = sketchbookFolder.getCanonicalPath(); + } catch (IOException e) { + sketchbookPath = sketchbookFolder.getPath(); + e.printStackTrace(); + } } else { sketchbookFolder = new File(sketchbookPath); @@ -115,16 +120,176 @@ public class PdeSketchbook { public JMenu rebuildMenu() { menu.removeAll(); - File prey = new File(sketchbookFolder, entries[j]); - File pde = new File(prey, entries[j] + ".pde"); - // make sure this is actually a sketch folder with a .pde, - // not a .DS_Store file or another random user folder - if (pde.exists()) { - if (PdeBase.calcFolderSize(prey) == 0) { - //System.out.println("i want to remove " + prey); - PdeBase.removeDir(prey); + try { + //MenuItem newSketchItem = new MenuItem("New Sketch"); + //newSketchItem.addActionListener(this); + //menu.add(newSkechItem); + //menu.addSeparator(); + + addSketches(menu, sketchbookFolder); + + // TODO add examples folder here too + + /* + // files for the current user (for now, most likely 'default') + + // header knows what the current user is + String userPath = sketchbookPath + + File.separator + editor.userName; + + File userFolder = new File(userPath); + if (!userFolder.exists()) { + System.err.println("sketchbook folder for '" + editor.userName + + "' doesn't exist, creating a new one"); + userFolder.mkdirs(); + } + */ + + /* + SketchbookMenuListener userMenuListener = + new SketchbookMenuListener(userPath); + + String entries[] = new File(userPath).list(); + boolean added = false; + for (int j = 0; j < entries.length; j++) { + if (entries[j].equals(".") || + entries[j].equals("..") || + entries[j].equals("CVS")) continue; + //entries[j].equals(".cvsignore")) continue; + added = true; + if (new File(userPath, entries[j] + File.separator + + entries[j] + ".pde").exists()) { + MenuItem item = new MenuItem(entries[j]); + item.addActionListener(userMenuListener); + menu.add(item); + } + //submenu.add(entries[j]); + } + if (!added) { + MenuItem item = new MenuItem("No sketches"); + item.setEnabled(false); + menu.add(item); + } + menu.addSeparator(); + */ + + /* + if (addSketches(menu, userFolder, false)) { + menu.addSeparator(); + } + if (!addSketches(menu, sketchbookFolder, true)) { + JMenuItem item = new JMenuItem("No sketches"); + item.setEnabled(false); + menu.add(item); + } + */ + + /* + // doesn't seem that refresh is worthy of its own menu item + // people can stop and restart p5 if they want to muck with it + menu.addSeparator(); + MenuItem item = new MenuItem("Refresh"); + item.addActionListener(this); + menu.add(item); + */ + + } catch (IOException e) { + e.printStackTrace(); + } + return menu; + } + + + protected boolean addSketches(JMenu menu, File folder) throws IOException { + // skip .DS_Store files, etc + if (!folder.isDirectory()) return false; + + String list[] = folder.list(); + SketchbookMenuListener listener = + new SketchbookMenuListener(folder.getAbsolutePath()); + + boolean ifound = false; + + for (int i = 0; i < list.length; i++) { + //if (list[i].equals(editor.userName) && root) continue; + + if (list[i].equals(".") || + list[i].equals("..") || + list[i].equals("CVS")) continue; + + File subfolder = new File(folder, list[i]); + if (new File(subfolder, list[i] + ".pde").exists()) { + JMenuItem item = new JMenuItem(list[i]); + item.addActionListener(listener); + menu.add(item); + ifound = true; + + } else { // might contain other dirs, get recursive + JMenu submenu = new JMenu(list[i]); + // needs to be separate var + // otherwise would set ifound to false + boolean found = addSketches(submenu, subfolder); //, false); + if (found) { + menu.add(submenu); + ifound = true; + } + } + } + return ifound; + } + + + /** + * clear out projects that are empty + */ + public void clean() { + if (!PdePreferences.getBoolean("sketchbook.auto_clean")) return; + + //String userPath = base.sketchbookPath + File.separator + userName; + //File userFolder = new File(userPath); + File sketchbookFolder = new File(PdePreferences.get("sketchbook.path")); + + //System.out.println("auto cleaning"); + if (sketchbookFolder.exists()) { + //String entries[] = new File(userPath).list(); + String entries[] = sketchbookFolder.list(); + if (entries != null) { + for (int j = 0; j < entries.length; j++) { + //System.out.println(entries[j] + " " + entries.length); + + if ((entries[j].equals(".")) || + (entries[j].equals(".."))) continue; + + //File prey = new File(userPath, entries[j]); + File prey = new File(sketchbookFolder, entries[j]); + File pde = new File(prey, entries[j] + ".pde"); + + // make sure this is actually a sketch folder with a .pde, + // not a .DS_Store file or another random user folder + + if (pde.exists()) { + if (PdeBase.calcFolderSize(prey) == 0) { + //System.out.println("i want to remove " + prey); + PdeBase.removeDir(prey); + //} else { + //System.out.println("not removign because size is " + + // calcFolderSize(prey)); + } } + + //File prey = new File(preyDir, entries[j] + ".pde"); + //if (prey.exists()) { + //if (prey.length() == 0) { + // this is a candidate for deletion, but make sure + // that the user hasn't added anything else to the folder + + //System.out.println("remove: " + prey); + // removeDir(preyDir); + //} + //} else { + //System.out.println(prey + " doesn't exist.. weird"); + //} } } } diff --git a/build/macosx/make.sh b/build/macosx/make.sh index 9f34b5bd5..5829fb32f 100755 --- a/build/macosx/make.sh +++ b/build/macosx/make.sh @@ -147,6 +147,7 @@ echo Building PDE for JDK 1.3 CLASSPATH=../build/macosx/work/classes:../build/macosx/work/lib/kjc.jar:../build/macosx/work/lib/antlr.jar:../build/macosx/work/lib/oro.jar:../build/macosx/work/lib/RXTXcomm.jar:$CLASSPATH perl ../bagel/buzz.pl "../build/macosx/work/jikes +D -classpath $CLASSPATH -d ../build/macosx/work/classes" -dJDK13 -dMACOS -dRXTX *.java jeditsyntax/*.java preprocessor/*.java +#perl ../bagel/buzz.pl "javac -classpath $CLASSPATH -d ../build/macosx/work/classes" -dJDK13 -dMACOS -dRXTX *.java jeditsyntax/*.java preprocessor/*.java cd ../build/macosx/work/classes rm -f ../lib/pde.jar