From e17d85e601587ad50b63da0771e6bc64f0e59989 Mon Sep 17 00:00:00 2001 From: benfry Date: Sun, 1 May 2005 23:36:48 +0000 Subject: [PATCH] working on save as and rename --- processing/app/Editor.java | 4 +- processing/app/Sketch.java | 104 +++++++++++++++++++++++++++++++------ processing/todo.txt | 48 ++++++++--------- 3 files changed, 116 insertions(+), 40 deletions(-) diff --git a/processing/app/Editor.java b/processing/app/Editor.java index 5ba63d830..2c506b048 100644 --- a/processing/app/Editor.java +++ b/processing/app/Editor.java @@ -238,9 +238,11 @@ public class Editor extends JFrame /** * Hack for #@#)$(* Mac OS X. + * This appears to only be required on OS X 10.2, and this code + * isn't even being hit on OS X 10.3 or Windows. */ public Dimension getMinimumSize() { - System.out.println("getting minimum size"); + //System.out.println("getting minimum size"); return new Dimension(500, 550); } diff --git a/processing/app/Sketch.java b/processing/app/Sketch.java index 2fc557359..8b612e133 100644 --- a/processing/app/Sketch.java +++ b/processing/app/Sketch.java @@ -276,7 +276,9 @@ public class Sketch { // ask for new name of file (internal to window) // TODO maybe just popup a text area? renamingCode = true; - editor.status.edit("New name for file:", current.name); + String prompt = (current == code[0]) ? + "New name for sketch:" : "New name for file:"; + editor.status.edit(prompt, current.name); } @@ -310,6 +312,7 @@ public class Sketch { String newFilename = null; int newFlavor = 0; + // separate into newName (no extension) and newFilename (with ext) // add .pde to file if it has no extension if (newName.endsWith(".pde")) { newFilename = newName; @@ -334,8 +337,8 @@ public class Sketch { newFlavor = PDE; } - // dots are allowed for the .pde and .java, but not in general - // so make sure the user didn't name things poo.time.pde + // dots are allowed for the .pde and .java, but not in the name + // make sure the user didn't name things poo.time.pde // or something like that (nothing against poo time) if (newName.indexOf('.') != -1) { newName = Sketchbook.sanitizedName(newName); @@ -351,43 +354,114 @@ public class Sketch { return; } - if (renamingCode) { - if (!current.file.renameTo(newFile)) { - Base.showWarning("Error", - "Could not rename \"" + current.file.getName() + - "\" to \"" + newFile.getName() + "\"", null); - return; - } + File newFileHidden = new File(folder, newFilename + ".x"); + if (newFileHidden.exists()) { + // don't let them get away with it if they try to create something + // with the same name as something hidden + Base.showMessage("No Way", + "A hidden tab with the same name already exists.\n" + + "Use \"Unhide\" to bring it back."); + return; + } + if (renamingCode) { if (current == code[0]) { - // if renaming the main class, now rename the folder and re-open + // unfortunately this can't be a "save as" because that + // only copies the sketch files and the data folder + // however this *will* first save the sketch, then rename + + // first get the contents of the editor text area + if (current.modified) { + current.program = editor.getText(); + try { + // save this new SketchCode + current.save(); + } catch (Exception e) { + Base.showWarning("Error", "Could not rename the sketch. (0)", e); + return; + } + } + + if (!current.file.renameTo(newFile)) { + Base.showWarning("Error", + "Could not rename \"" + current.file.getName() + + "\" to \"" + newFile.getName() + "\"", null); + return; + } + + // save each of the other tabs because this is gonna be re-opened + try { + for (int i = 1; i < codeCount; i++) { + //if (code[i].modified) code[i].save(); + code[i].save(); + } + } catch (Exception e) { + Base.showWarning("Error", "Could not rename the sketch. (1)", e); + return; + } + + // now rename the sketch folder and re-open File newFolder = new File(folder.getParentFile(), newName); boolean success = folder.renameTo(newFolder); if (!success) { - Base.showWarning("Error", - "Could not rename the sketch.", null); + Base.showWarning("Error", "Could not rename the sketch. (2)", null); return; } // if successful, set base properties for the sketch - folder = newFolder; + File mainFile = new File(newFolder, newName + ".pde"); mainFilename = mainFile.getAbsolutePath(); + // having saved everything and renamed the folder and the main .pde, + // use the editor to re-open the sketch to re-init state + // (unfortunately this will kill positions for carets etc) + editor.handleOpenUnchecked(mainFilename); + + /* + // backtrack and don't rename the sketch folder + success = newFolder.renameTo(folder); + if (!success) { + String msg = + "Started renaming sketch and then ran into\n" + + "nasty trouble. Try to salvage with Copy & Paste\n" + + "or attempt a \"Save As\" to see if that works."; + Base.showWarning("Serious Error", msg, null); + } + return; + } + */ + + /* // set the sketch name... used by the pde and whatnot. // the name is only set in the sketch constructor, // so it's important here name = newName; + code[0].name = newName; + code[0].file = mainFile; + code[0].program = editor.getText(); + code[0].save(); + + folder = newFolder; + // get the changes into the sketchbook menu editor.sketchbook.rebuildMenus(); // reload the sketch load(); + */ } else { + if (!current.file.renameTo(newFile)) { + Base.showWarning("Error", + "Could not rename \"" + current.file.getName() + + "\" to \"" + newFile.getName() + "\"", null); + return; + } + // just reopen the class itself - current.file = newFile; current.name = newName; + current.file = newFile; current.flavor = newFlavor; } diff --git a/processing/todo.txt b/processing/todo.txt index d7d8b13ba..13659ea79 100644 --- a/processing/todo.txt +++ b/processing/todo.txt @@ -35,8 +35,8 @@ X save caret position when switching tabs _ make simple tool for casey to rebuild all the examples at once _ need to rebuild with this release because of 1.3/1.4 issues -_ "are you trying to f-- with me" on quitting the app is super problem -_ look into canceling a quit instead? +X "are you trying to f-- with me" on quitting the app is super problem +o look into canceling a quit instead? _ "save as" not quite working http://processing.org/discourse/yabb_beta/YaBB.cgi?board=SoftwareBugs;action=display;num=1113944897;start=0 @@ -137,28 +137,6 @@ _ println() can hose the app for the first 20-30 frames _ need to figure out threading etc _ problem with it launching a new thread for every single update! -. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . - -_ set applet.frame on runner, so ppl can mess with the frame itself - -_ option to suppress warning dialogs -_ starting with the one about modifying the sketch name for spaces - -_ osx is swallowing exceptions on external apps -_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=SoftwareBugs;action=display;num=1114520230;start=5 - -_ sun.applet.Main is appletviewer - -_ settings.path.fallback not being used -_ can't find build dir on operating systems w/ non-ascii chars -_ or rather, when user accounts have non-ascii chars in the name -_ try setting up an account where this is the case - -_ info about getting started with building processing -_ also re: what about eclipse? what about antlr? - -_ update things for java 1.5 since it's inevitable - _ port buffering not working properly _ may just be a problem with thread starvation _ bufferUntil() fires an event but continues to fill up the buffer @@ -185,6 +163,28 @@ void serialEvent() { println(myPort.readString()); } +. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + +_ set applet.frame on runner, so ppl can mess with the frame itself + +_ option to suppress warning dialogs +_ starting with the one about modifying the sketch name for spaces + +_ osx is swallowing exceptions on external apps +_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=SoftwareBugs;action=display;num=1114520230;start=5 + +_ sun.applet.Main is appletviewer + +_ settings.path.fallback not being used +_ can't find build dir on operating systems w/ non-ascii chars +_ or rather, when user accounts have non-ascii chars in the name +_ try setting up an account where this is the case + +_ info about getting started with building processing +_ also re: what about eclipse? what about antlr? + +_ update things for java 1.5 since it's inevitable + . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .