diff --git a/app/PdeBase.java b/app/PdeBase.java index b59e0d789..3b3ab7d4e 100644 --- a/app/PdeBase.java +++ b/app/PdeBase.java @@ -425,13 +425,14 @@ public class PdeBase { static public void copyDir(File sourceDir, File targetDir) throws IOException { + targetDir.mkdirs(); String files[] = sourceDir.list(); for (int i = 0; i < files.length; i++) { if (files[i].equals(".") || files[i].equals("..")) continue; File source = new File(sourceDir, files[i]); File target = new File(targetDir, files[i]); if (source.isDirectory()) { - target.mkdirs(); + //target.mkdirs(); copyDir(source, target); #ifdef JDK13 target.setLastModified(source.lastModified()); diff --git a/app/PdeCode.java b/app/PdeCode.java index c8c3d2014..f605dfc0e 100644 --- a/app/PdeCode.java +++ b/app/PdeCode.java @@ -4,7 +4,7 @@ PdeCode - data class for a single file inside a sketch Part of the Processing project - http://processing.org - Except where noted, code is written by Ben Fry + Except where noted, code is written by Ben Fry and is Copyright (c) 2001-04 Massachusetts Institute of Technology This program is free software; you can redistribute it and/or modify diff --git a/app/PdeEditor.java b/app/PdeEditor.java index c27c45695..a43330f1c 100644 --- a/app/PdeEditor.java +++ b/app/PdeEditor.java @@ -502,7 +502,7 @@ public class PdeEditor extends JFrame saveMenuItem = newJMenuItem("Save", 'S'); saveMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - handleSave2(); + handleSave(); } }); menu.add(saveMenuItem); @@ -1144,7 +1144,7 @@ public class PdeEditor extends JFrame options[0]); if (result == JOptionPane.YES_OPTION) { - handleSave2(); + handleSave(); checkModified2(); } else if (result == JOptionPane.NO_OPTION) { @@ -1227,7 +1227,7 @@ public class PdeEditor extends JFrame // there is no handleSave1 since there's never a need to prompt - public void handleSave2() { + public void handleSave() { message("Saving..."); try { sketch.save(); @@ -1240,6 +1240,7 @@ public class PdeEditor extends JFrame // zero out the current action, // so that checkModified2 will just do nothing checkModifiedMode = 0; + // this is used when another operation calls a save } buttons.clear(); } @@ -1248,118 +1249,21 @@ public class PdeEditor extends JFrame public void handleSaveAs() { doStop(); - // probably need to do this stuff inside the sketch object itself - - // do a directory copy of contents of - // old sketch folder to new sketch folder - //copyDir(sketch.folder, new File(parentDir, sketchDir)); - //PdeBase.copyDir(null, null); - - // rename the main .pde file - - // needs to take the current state of the open files - // and save them to the new folder.. but not save over - // the old versions for the old sketch.. hrm.. - - //if (!PdePreferences.getBoolean("sketchbook.prompt")) { - //status.edit("Save sketch as...", sketch.name); - //} else { - //handleSaveAs2(null); - //} - //} - - //public void handleSaveAs2(String newSketchName) { - //if (newSketchName.equals(sketch.name)) { - // return; // do nothing - - //} else if (newSketchName.equalsIgnoreCase(sketch.name)) { - // NEED TO GET THE ACTUAL SKETCH NAME FROM CODE[0] HERE - - // TODO UNFINISHED - - /* - boolean problem = (sketchDir.renameTo(newSketchDir) || - sketchFile.renameTo(newSketchFile)); - if (problem) { - status.error("Error while trying to re-save the sketch."); - } - */ - - //} else { - // setup new sketch object with new name - //} - } - - /* - public void skSaveAs2(String newSketchName) { - if (newSketchName.equals(sketchName)) { - // nothing changes - return; - } - - File newSketchDir = new File(sketchDir.getParent() + - File.separator + newSketchName); - File newSketchFile = new File(newSketchDir, newSketchName + ".pde"); - - //doSave(); // save changes before renaming.. risky but oh well - String textareaContents = textarea.getText(); - int textareaPosition = textarea.getCaretPosition(); - - // if same name, but different case, just use renameTo - if (newSketchName.toLowerCase(). - equals(sketchName.toLowerCase())) { - //System.out.println("using renameTo"); - - boolean problem = (sketchDir.renameTo(newSketchDir) || - sketchFile.renameTo(newSketchFile)); - if (problem) { - status.error("Error while trying to re-save the sketch."); + message("Saving..."); + try { + if (sketch.saveAs()) { + message("Done Saving."); + sketchbook.rebuildMenu(); + } else { + message("Save Cancelled."); } - } else { - // make new dir - newSketchDir.mkdirs(); - // copy the sketch file itself with new name - PdeBase.copyFile(sketchFile, newSketchFile); - - // copy everything from the old dir to the new one - PdeBase.copyDir(sketchDir, newSketchDir); - - // remove the old sketch file from the new dir - new File(newSketchDir, sketchName + ".pde").delete(); - - // remove the old dir (!) - //if (renaming) { - // in case java is holding on to any files we want to delete - //System.gc(); - //PdeBase.removeDir(sketchDir); - //} - - // (important!) has to be done before opening, - // otherwise the new dir is set to sketchDir.. - // remove .jar, .class, and .java files from the applet dir - File appletDir = new File(newSketchDir, "applet"); - File oldjar = new File(appletDir, sketchName + ".jar"); - if (oldjar.exists()) oldjar.delete(); - File oldjava = new File(appletDir, sketchName + ".java"); - if (oldjava.exists()) oldjava.delete(); - File oldclass = new File(appletDir, sketchName + ".class"); - if (oldclass.exists()) oldclass.delete(); + } catch (Exception e) { + // show the error as a message in the window + error(e); } - - // get the changes into the sketchbook menu - //base.rebuildSketchbookMenu(); - sketchbook.rebuildMenu(); - - // open the new guy - handleOpen2(newSketchName, newSketchFile, newSketchDir); - - // update with the new junk and save that as the new code - changeText(textareaContents, true); - textarea.setCaretPosition(textareaPosition); - doSave(); + buttons.clear(); } - */ /** diff --git a/app/PdeEditorButtons.java b/app/PdeEditorButtons.java index ffa3a04c9..97a35e57b 100644 --- a/app/PdeEditorButtons.java +++ b/app/PdeEditorButtons.java @@ -341,7 +341,7 @@ public class PdeEditorButtons extends JComponent implements MouseInputListener { case STOP: setState(RUN, INACTIVE, true); editor.handleStop(); break; case OPEN: setState(OPEN, INACTIVE, true); break; case NEW: editor.handleNew(); break; - case SAVE: editor.handleSave2(); break; + case SAVE: editor.handleSave(); break; case EXPORT: editor.handleExport(); break; } currentSelection = -1; diff --git a/app/PdeEditorStatus.java b/app/PdeEditorStatus.java index b93a1e8f6..352e9a84c 100644 --- a/app/PdeEditorStatus.java +++ b/app/PdeEditorStatus.java @@ -408,7 +408,7 @@ public class PdeEditorStatus extends JPanel implements ActionListener { } else if (e.getSource() == yesButton) { // answer was in response to "save changes?" unprompt(); - editor.handleSave2(); + editor.handleSave(); editor.checkModified2(); } else if (e.getSource() == cancelButton) { diff --git a/app/PdeSketch.java b/app/PdeSketch.java index 3ffd1f8e8..746cb94d7 100644 --- a/app/PdeSketch.java +++ b/app/PdeSketch.java @@ -294,10 +294,89 @@ public class PdeSketch { } - public void saveAs() { - System.err.println("need to save ass here. code not yet finished."); + /** + * handles 'save as' for a sketch.. essentially duplicates + * the current sketch folder to a new location, and then calls + * 'save'. (needs to take the current state of the open files + * and save them to the new folder.. but not save over the old + * versions for the old sketch..) + * + * also removes the previously-generated .class and .jar files, + * because they can cause trouble. + */ + public boolean saveAs() throws IOException { + // get new name for folder + FileDialog fd = new FileDialog(editor, //new Frame(), + "Save sketch folder as...", + FileDialog.SAVE); + // always default to the sketchbook folder.. + fd.setDirectory(PdePreferences.get("sketchbook.path")); + // TODO or maybe this should default to the + // parent dir of the old folder? - // mark all files as modified so that it will save them + fd.show(); + String newParentDir = fd.getDirectory(); + String newName = fd.getFile(); + + // user cancelled selection + if (newName == null) return false; + + // new sketch folder + File newFolder = new File(newParentDir, newName); + + // make sure the paths aren't the same + if (newFolder.equals(folder)) { + PdeBase.showWarning("You can't fool me", + "The new sketch name and location are the same\n" + + "as the old. I ain't not doin nuthin'.", null); + return false; + } + + // copy the entire contents of the sketch folder + PdeBase.copyDir(folder, newFolder); + + // change the references to the dir location in PdeCode files + for (int i = 0; i < codeCount; i++) { + code[i].file = new File(newFolder, code[i].file.getName()); + } + for (int i = 0; i < hiddenCount; i++) { + hidden[i].file = new File(newFolder, hidden[i].file.getName()); + } + + // remove the old sketch file from the new dir + code[0].file.delete(); + // name for the new main .pde file + code[0].file = new File(newFolder, newName + ".pde"); + code[0].name = newName; + // write the contents to the renamed file + // (this may be resaved if the code is modified) + code[0].save(); + + // change the other paths + String oldName = name; + name = newName; + File oldFolder = folder; + folder = newFolder; + dataFolder = new File(folder, "data"); + codeFolder = new File(folder, "code"); + + // remove the 'applet', 'application', 'library' folders + // from the copied version. + // otherwise their .class and .jar files can cause conflicts. + PdeBase.removeDir(new File(folder, "applet")); + PdeBase.removeDir(new File(folder, "application")); + PdeBase.removeDir(new File(folder, "library")); + + // do a "save" + // this will take care of the unsaved changes in each of the tabs + save(); + + // get the changes into the sketchbook menu + //sketchbook.rebuildMenu(); + // done inside PdeEditor instead + + // let PdeEditor know that the save was successful + return true; } diff --git a/app/PdeSketchbook.java b/app/PdeSketchbook.java index 220f75b0d..52297ec66 100644 --- a/app/PdeSketchbook.java +++ b/app/PdeSketchbook.java @@ -212,28 +212,6 @@ public class PdeSketchbook { } - public String handleSaveAs() throws IOException { - // get new name for folder - FileDialog fd = new FileDialog(new Frame(), - "Save sketch folder as...", - FileDialog.SAVE); - // always default to the sketchbook folder.. - fd.setDirectory(PdePreferences.get("sketchbook.path")); - // TODO or maybe this should default to the - // parent dir of the old folder? - - fd.show(); - String parentDir = fd.getDirectory(); - String sketchDir = fd.getFile(); - - // user cancelled selection - if (sketchDir == null) return null; - - File dir = new File(parentDir, sketchDir); - return dir.getAbsolutePath(); // hmm.. is this ok if it doesn't exist? - } - - public JPopupMenu getPopupMenu() { return menu.getPopupMenu(); } diff --git a/todo.txt b/todo.txt index ffe495d23..83786b62d 100644 --- a/todo.txt +++ b/todo.txt @@ -15,7 +15,7 @@ X sketch is changing before the "save changes?" is complete X as a result, 'cancel' does nothing X always ask save changes, even if nothing changed -mangling and mess +040621 sunday X remove 'sketchbook.prompt' (comment it out) X not really needed X remove prompt stuff from the preferences panel @@ -24,21 +24,37 @@ X to use JLabel instead of JTextArea X font was wrong on windows X start working on "save as" -_ finish "save as" +040622 monday +X finish "save as" _ after using sketchbook menu as popup, disappears from file menu _ re-implement history _ write sketchbook.clean() _ write 'new text file' +_ implement hide/unhide _ implement read-only sketch folder _ examples are sort of there but need to be debugged _ read-only files should be checked _ get the console working again _ appendText is disabled due to NullPointerEx on startup +_ ctrl-5 (confirmed on xp) is marking the current sketch as modified +_ running present mode with a bug in the program hoses things +_ make sure the program compiles before starting present mode +_ if 'applet.html' is in sketch folder, use that as the template +_ comments -> embedding in applet text? (ala javadoc) +_ would this help casey with the examples? + +_ adding files to data folder that are already in the data folder +_ makes the file zero, because of internal error +_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1076358515 + + +discuss with casey _ is the sketch folder something that is never seen by the user? _ i.e. flash programs 'import' all data, etc _ same with how imovie works + _ NullPointerException when alt is pressed _ might be something to do with the applet frame being an awt not swing _ event first goes to the applet listener, needs to consume the event @@ -65,10 +81,6 @@ _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1080213711 _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1083093129 -_ adding files to data folder that are already in the data folder -_ makes the file zero, because of internal error -_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1076358515 - _ add mkdmg script to macosx build process _ could significantly speed things up