From 3e75d02fed9c78caa18101bf150bca2676194efa Mon Sep 17 00:00:00 2001 From: benfry Date: Tue, 20 Jan 2004 17:45:01 +0000 Subject: [PATCH] getting new sketchbook and examples under control --- processing/app/PdeEditor.java | 100 +++++++----------------------- processing/app/PdeSketch.java | 2 +- processing/app/PdeSketchbook.java | 94 ++++++++++++++++++++++++++-- processing/build/macosx/make.sh | 5 +- processing/todo.txt | 4 +- 5 files changed, 117 insertions(+), 88 deletions(-) diff --git a/processing/app/PdeEditor.java b/processing/app/PdeEditor.java index 589669d78..62cbb40e4 100644 --- a/processing/app/PdeEditor.java +++ b/processing/app/PdeEditor.java @@ -60,16 +60,13 @@ public class PdeEditor extends JFrame " " + " "; - static final int SK_NEW = 1; - static final int SK_OPEN = 2; - static final int DO_OPEN = 3; - static final int DO_QUIT = 4; + static final int NEW = 1; + static final int OPEN = 2; + static final int QUIT = 3; int checking; String openingPath; String openingName; - PdeEditorListener listener; - PdeEditorButtons buttons; PdeEditorHeader header; PdeEditorStatus status; @@ -79,6 +76,7 @@ public class PdeEditor extends JFrame JPanel consolePanel; JEditTextArea textarea; + PdeEditorListener listener; // currently opened program PdeSketch sketch; @@ -308,7 +306,9 @@ public class PdeEditor extends JFrame } - // hack for #@#)$(* macosx + /** + * Hack for #@#)$(* Mac OS X. + */ public Dimension getMinimumSize() { return new Dimension(500, 500); } @@ -1027,7 +1027,7 @@ public class PdeEditor extends JFrame public void setModified(boolean what) { //header.sketchModified = what; - sketch.setModified(what); + sketch.setCurrentModified(what); header.repaint(); //sketchModified = what; } @@ -1048,7 +1048,7 @@ public class PdeEditor extends JFrame if (sketch.isModified()) { String prompt = "Save changes to " + sketch.name + "? "; - if (checking != DO_QUIT) { + if (checking != HANDLE_QUIT) { // if the user is not quitting, then use the nicer // dialog that's actually inside the p5 window. status.prompt(prompt); @@ -1114,18 +1114,21 @@ public class PdeEditor extends JFrame public void checkModified2() { switch (checking) { - case SK_NEW: skNew2(false); break; - case SK_OPEN: skOpen2(openingPath, openingName); break; - case DO_QUIT: doQuit2(); break; + case NEW: handleNew2(false); break; + case OPEN: skOpen2(openingPath, openingName); break; + case QUIT: handleQuit2(); break; } checking = 0; } - // local vars prevent sketchName from being set - public void skNew() { + /** + * New was called (by buttons or by menu), first check modified + * and if things work out ok, handleNew2() will be called. + */ + public void handleNew() { doStop(); - checkModified(SK_NEW); + checkModified(NEW); } @@ -1134,71 +1137,10 @@ public class PdeEditor extends JFrame * then calls handleOpen to load it up. * @param startup true if the app is starting (auto-create a sketch) */ - protected void skNew2(boolean startup) { + protected void handleNew2(boolean startup) { try { - File newbieDir = null; - String newbieName = null; - - if (PdePreferences.getBoolean("sketchbook.prompt") && !startup) { - // prompt for the filename and location for the new sketch - - FileDialog fd = new FileDialog(new Frame(), - "Create new sketch named", - FileDialog.SAVE); - fd.setDirectory(PdePreferences.get("sketchbook.path")); - fd.show(); - - String newbieParentDir = fd.getDirectory(); - newbieName = fd.getFile(); - if (newbieName == null) return; - - newbieDir = new File(newbieParentDir, newbieName); - - } else { - // use a generic name like sketch_031008a, the date plus a char - String newbieParentDir = PdePreferences.get("sketchbook.path"); - - int index = 0; - SimpleDateFormat formatter = new SimpleDateFormat("yyMMdd"); - String purty = formatter.format(new Date()); - do { - newbieName = "sketch_" + purty + ((char) ('a' + index)); - newbieDir = new File(newbieParentDir, newbieName); - index++; - } while (newbieDir.exists()); - } - - // mkdir for new project name - newbieDir.mkdirs(); - - //new File(sketchDir, "data").mkdirs(); - - // make empty pde file - File newbieFile = new File(newbieDir, newbieName + ".pde"); - new FileOutputStream(newbieFile); - -#ifdef MACOS - // thank you apple, for changing this @#$)(* - //com.apple.eio.setFileTypeAndCreator(String filename, int, int); - - // jdk13 on osx, or jdk11 - // though apparently still available for 1.4 - if ((PdeBase.platform == PdeBase.MACOS9) || - (PdeBase.platform == PdeBase.MACOSX)) { - MRJFileUtils.setFileTypeAndCreator(newbieFile, - MRJOSType.kTypeTEXT, - new MRJOSType("Pde1")); - } -#endif - - // make 'data' 'applet' dirs inside that - // actually, don't, that way can avoid too much extra mess - - // rebuild the menu here - sketchbook.rebuildMenu(); - - // now open it up - handleOpen(newbieName, newbieFile, newbieDir); + PdeSketch newSketch = sketchbook.handleNew(); + if (newSketch != null) handleOpen2(newSketch); } catch (IOException e) { // NEED TO DO SOME ERROR REPORTING HERE *** diff --git a/processing/app/PdeSketch.java b/processing/app/PdeSketch.java index cb34fce00..1dca07ca4 100644 --- a/processing/app/PdeSketch.java +++ b/processing/app/PdeSketch.java @@ -53,10 +53,10 @@ public class PdeSketch { PdeCode hidden[]; // all these set each time build() is called - boolean externalRuntime; String mainClassName; String classPath; String libraryPath; + boolean externalRuntime; /** diff --git a/processing/app/PdeSketchbook.java b/processing/app/PdeSketchbook.java index b23f51992..55a8f5969 100644 --- a/processing/app/PdeSketchbook.java +++ b/processing/app/PdeSketchbook.java @@ -39,8 +39,8 @@ public class PdeSketchbook { PdeEditor editor; JMenu menu; - File sketchbookFolder; - String sketchbookPath; // canonical path + //File sketchbookFolder; + //String sketchbookPath; // canonical path File examplesFolder; String examplesPath; // canonical path (for comparison) @@ -49,7 +49,10 @@ public class PdeSketchbook { public PdeSketchbook(PdeEditor editor) { this.editor = editor; - sketchbookPath = PdePreferences.get("sketchbook.path"); + examplesFolder = new File(System.getProperty("user.dir"), "examples"); + examplesPath = examplesFolder.getCanonicalPath(); + + String sketchbookPath = PdePreferences.get("sketchbook.path"); if (sketchbookPath == null) { // by default, set default sketchbook path to the user's @@ -68,7 +71,7 @@ public class PdeSketchbook { String folderName = PdePreferences.get("sketchbook.name.default"); //System.out.println("home = " + home); //System.out.println("fname = " + folderName); - sketchbookFolder = new File(home, folderName); + File sketchbookFolder = new File(home, folderName); PdePreferences.set("sketchbook.path", sketchbookFolder.getAbsolutePath()); @@ -91,6 +94,86 @@ public class PdeSketchbook { } + /** + * Handle creating a sketch folder, return its base .pde file + * or null if the operation was cancelled. + */ + public String handleNew() throws IOException { + File newbieDir = null; + String newbieName = null; + + // no sketch has been started, don't prompt for the name if it's + // starting up, just make the farker. otherwise if the person hits + // 'cancel' i'd have to add a thing to make p5 quit, which is silly. + // instead give them an empty sketch, and they can look at examples. + // i hate it when imovie makes you start with that goofy dialog box. + // unless, ermm, they user tested it and people preferred that as + // a way to get started. shite. now i hate myself. + // + if (PdePreferences.getBoolean("sketchbook.prompt") && !startup) { + // prompt for the filename and location for the new sketch + + FileDialog fd = new FileDialog(new Frame(), + "Create new sketch named", + FileDialog.SAVE); + fd.setDirectory(PdePreferences.get("sketchbook.path")); + fd.show(); + + String newbieParentDir = fd.getDirectory(); + newbieName = fd.getFile(); + if (newbieName == null) return null; + + newbieDir = new File(newbieParentDir, newbieName); + + } else { + // use a generic name like sketch_031008a, the date plus a char + String newbieParentDir = PdePreferences.get("sketchbook.path"); + + int index = 0; + SimpleDateFormat formatter = new SimpleDateFormat("yyMMdd"); + String purty = formatter.format(new Date()); + do { + newbieName = "sketch_" + purty + ((char) ('a' + index)); + newbieDir = new File(newbieParentDir, newbieName); + index++; + } while (newbieDir.exists()); + } + + // make the directory for the new sketch + newbieDir.mkdirs(); + + // make an empty pde file + File newbieFile = new File(newbieDir, newbieName + ".pde"); + new FileOutputStream(newbieFile); // create the file + +#ifdef MACOS + // thank you apple, for changing this @#$)(* + //com.apple.eio.setFileTypeAndCreator(String filename, int, int); + + // TODO this wouldn't be needed if i could figure out how to + // associate document icons via a dot-extension/mime-type scenario + // help me steve jobs. you're my only hope + + // jdk13 on osx, or jdk11 + // though apparently still available for 1.4 + if ((PdeBase.platform == PdeBase.MACOS9) || + (PdeBase.platform == PdeBase.MACOSX)) { + MRJFileUtils.setFileTypeAndCreator(newbieFile, + MRJOSType.kTypeTEXT, + new MRJOSType("Pde1")); + } +#endif + + // make a note of a newly added sketch in the sketchbook menu + rebuildMenu(); + + // now open it up + //handleOpen(newbieName, newbieFile, newbieDir); + //return newSketch; + return newbieFile.getCanonicalPath(); + } + + // listener for sketchbk items uses getParent() to figure out // the directories above it @@ -129,6 +212,9 @@ public class PdeSketchbook { addSketches(menu, sketchbookFolder); + menu.addSeparator(); + addSketches(menu, examplesFolder); + // TODO add examples folder here too /* diff --git a/processing/build/macosx/make.sh b/processing/build/macosx/make.sh index 31339f384..99e2ee6af 100755 --- a/processing/build/macosx/make.sh +++ b/processing/build/macosx/make.sh @@ -31,11 +31,10 @@ else cp -r ../shared work echo Extracting examples... - #cd work/sketchbook - cd work/lib + cd work unzip -q examples.zip rm examples.zip - cd ../.. + cd .. echo Extracting reference... cd work diff --git a/processing/todo.txt b/processing/todo.txt index f18f23268..540f33981 100644 --- a/processing/todo.txt +++ b/processing/todo.txt @@ -85,7 +85,9 @@ _ fix command keys for menus (broken since switching to swing) _ PdeRuntime isn't properly handling messages from all classes in project _ get things up and running, and see how it looks -_ fix make.sh and dist.sh for all platforms to include new export setup +_ fix make.sh and dist.sh for all platforms +_ changes to the export setup and making the bagel jar files +_ change of location for examples.zip and where they extract to _ re-implement history (disabled for 68) _ history: "archive this version"