From 9e3cd0b6a9e880ed2388fbef7898bf2bc4f0dbee Mon Sep 17 00:00:00 2001 From: benfry Date: Sun, 12 Sep 2004 22:57:27 +0000 Subject: [PATCH] more library and menu work --- processing/app/PdeCompiler.java | 2 +- processing/app/PdeEditor.java | 4 +++ processing/app/PdeRuntime.java | 7 +++-- processing/app/PdeSketch.java | 11 ++++---- processing/app/PdeSketchbook.java | 44 ++++++++++++++++++++++++++----- processing/todo.txt | 3 ++- 6 files changed, 55 insertions(+), 16 deletions(-) diff --git a/processing/app/PdeCompiler.java b/processing/app/PdeCompiler.java index de7ff54c3..83609fa27 100644 --- a/processing/app/PdeCompiler.java +++ b/processing/app/PdeCompiler.java @@ -370,7 +370,7 @@ public class PdeCompiler implements PdeMessageConsumer { e.printStackTrace(); // this would be odd } //System.out.println("included path is " + abuffer.toString()); - packageListFromClassPath(abuffer.toString()); + packageListFromClassPath(abuffer.toString()); // WHY? return abuffer.toString(); } diff --git a/processing/app/PdeEditor.java b/processing/app/PdeEditor.java index 705239952..e5dcfe75a 100644 --- a/processing/app/PdeEditor.java +++ b/processing/app/PdeEditor.java @@ -511,6 +511,7 @@ implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler menu.add(item); menu.add(sketchbook.rebuildMenu()); + menu.add(sketchbook.getExamplesMenu()); saveMenuItem = newJMenuItem("Save", 'S'); saveMenuItem.addActionListener(new ActionListener() { @@ -670,6 +671,8 @@ implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler JMenuItem item; item = new JMenuItem("Help"); + item.setEnabled(false); + /* item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { PdeBase.openURL(System.getProperty("user.dir") + File.separator + @@ -677,6 +680,7 @@ implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler File.separator + "index.html"); } }); + */ menu.add(item); item = new JMenuItem("Reference"); diff --git a/processing/app/PdeRuntime.java b/processing/app/PdeRuntime.java index 53890a67a..879533b1a 100644 --- a/processing/app/PdeRuntime.java +++ b/processing/app/PdeRuntime.java @@ -90,9 +90,12 @@ public class PdeRuntime implements PdeMessageConsumer { String command[] = new String[] { "java", - "-Djava.library.path=" + sketch.libraryPath, // might be "" + "-Djava.library.path=" + + // sketch.libraryPath might be "" + // librariesClassPath will always have sep char prepended + sketch.libraryPath + PdeSketchbook.librariesClassPath, "-cp", - sketch.classPath, + sketch.classPath + PdeSketchbook.librariesClassPath, "processing.core.PApplet", location, PApplet.EXT_SKETCH_FOLDER + sketch.folder.getAbsolutePath(), diff --git a/processing/app/PdeSketch.java b/processing/app/PdeSketch.java index ab93f6aa0..9ac491c72 100644 --- a/processing/app/PdeSketch.java +++ b/processing/app/PdeSketch.java @@ -980,7 +980,7 @@ public class PdeSketch { protected String build(String buildPath, String suggestedClassName) throws PdeException { - String importPackageList[] = null; + //String importPackageList[] = null; String javaClassPath = System.getProperty("java.class.path"); // remove quotes if any.. this is an annoying thing on windows @@ -988,7 +988,9 @@ public class PdeSketch { javaClassPath = javaClassPath.substring(1, javaClassPath.length() - 1); } - classPath = buildPath + File.pathSeparator + javaClassPath; + classPath = buildPath + + File.pathSeparator + PdeSketchbook.librariesClassPath + + File.pathSeparator + javaClassPath; //System.out.println("cp = " + classPath); // figure out the contents of the code folder to see if there @@ -998,12 +1000,11 @@ public class PdeSketch { externalRuntime = true; classPath += File.pathSeparator + PdeCompiler.contentsToClassPath(codeFolder); - importPackageList = PdeCompiler.packageListFromClassPath(classPath); - //libraryPath = codeFolder.getCanonicalPath(); + //importPackageList = PdeCompiler.packageListFromClassPath(classPath); libraryPath = codeFolder.getAbsolutePath(); } else { externalRuntime = (codeCount > 1); // may still be set true later - importPackageList = null; + //importPackageList = null; libraryPath = ""; } diff --git a/processing/app/PdeSketchbook.java b/processing/app/PdeSketchbook.java index e3f4c8325..32fe33d8a 100644 --- a/processing/app/PdeSketchbook.java +++ b/processing/app/PdeSketchbook.java @@ -41,8 +41,9 @@ import com.apple.mrj.*; public class PdeSketchbook { PdeEditor editor; - JMenu menu; JMenu popup; + JMenu menu; + JMenu examples; JMenu addlib; // set to true after the first time it's built. @@ -64,6 +65,11 @@ public class PdeSketchbook { static File librariesFolder; static String librariesPath; + // classpath for all known libraries for p5 + // (both those in the p5/libs folder and those with lib subfolders + // found in the sketchbook) + static String librariesClassPath; + public PdeSketchbook(PdeEditor editor) { this.editor = editor; @@ -325,9 +331,14 @@ public class PdeSketchbook { boolean sketches = addSketches(popup, new File(PdePreferences.get("sketchbook.path"))); if (sketches) popup.addSeparator(); - JMenu examples = new JMenu("Examples"); - addSketches(examples, examplesFolder); - popup.add(examples); + JMenu ex = new JMenu("Examples"); + addSketches(ex, examplesFolder); + popup.add(ex); + if (PdePreferences.getBoolean("export.library")) { + JMenu m = new JMenu("Libraries"); + addSketches(m, librariesFolder); + popup.add(m); + } // disable error messages while loading builtOnce = true; @@ -336,6 +347,7 @@ public class PdeSketchbook { // rebuild the open menu menu.removeAll(); + /* if (sketches) { addSketches(menu, new File(PdePreferences.get("sketchbook.path"))); menu.addSeparator(); @@ -343,14 +355,22 @@ public class PdeSketchbook { examples = new JMenu("Examples"); addSketches(examples, examplesFolder); menu.add(examples); + */ + if (sketches) { + addSketches(menu, new File(PdePreferences.get("sketchbook.path"))); + } + examples = new JMenu("Examples"); + addSketches(examples, examplesFolder); + //menu.add(examples); - - // rebuild the "add library" menu + // rebuild the "import library" menu addlib.removeAll(); + librariesClassPath = ""; boolean libs = addLibraries(addlib, new File(PdePreferences.get("sketchbook.path"))); - if (libs) menu.addSeparator(); + if (libs) addlib.addSeparator(); addLibraries(addlib, librariesFolder); + //System.out.println("libraries cp is now " + librariesClassPath); } catch (IOException e) { PdeBase.showWarning("Problem while building sketchbook menu", @@ -362,6 +382,11 @@ public class PdeSketchbook { } + protected JMenu getExamplesMenu() { + return examples; + } + + protected boolean addSketches(JMenu menu, File folder) throws IOException { // skip .DS_Store files, etc if (!folder.isDirectory()) return false; @@ -494,6 +519,11 @@ public class PdeSketchbook { continue; } + // grab all jars and classes from this folder, + // and append them to the library classpath + librariesClassPath += File.pathSeparatorChar + + PdeCompiler.contentsToClassPath(exported); + JMenuItem item = new JMenuItem(list[i]); item.addActionListener(listener); item.setActionCommand(entry.getAbsolutePath()); diff --git a/processing/todo.txt b/processing/todo.txt index 7e722790c..6877e1b77 100644 --- a/processing/todo.txt +++ b/processing/todo.txt @@ -54,7 +54,8 @@ X several menu changes as discussed with casey X (capitalization, export/export app, tools) X add preference for showing library stuff _ figure out why user libraries not being added -_ show internal libraries as part of the 'open' menu (in lib mode) +_ in lib mode, show internal libraries as part of the 'open' menu +_ make a note that p5 has to be restarted for libs _ after export of library, rebuild "import library" menu _ import all libraries into classpath _ all libs found during sketchbook build + all libs in libraries