diff --git a/processing/app/PdeBase.java b/processing/app/PdeBase.java index b2aee04de..044e5fb47 100644 --- a/processing/app/PdeBase.java +++ b/processing/app/PdeBase.java @@ -88,7 +88,6 @@ public class PdeBase { public PdeBase() { - // figure out which operating system // this has to be first, since editor needs to know @@ -796,8 +795,10 @@ public class PdeBase { static public int calcFolderSize(File folder) { int size = 0; - //System.out.println("calcFolderSize " + folder); String files[] = folder.list(); + // null if folder doesn't exist, happens when deleting sketch + if (files == null) return -1; + for (int i = 0; i < files.length; i++) { if (files[i].equals(".") || (files[i].equals("..")) || files[i].equals(".DS_Store")) continue; diff --git a/processing/app/PdeEditor.java b/processing/app/PdeEditor.java index c5ce5c5cf..3f6c336a6 100644 --- a/processing/app/PdeEditor.java +++ b/processing/app/PdeEditor.java @@ -1310,6 +1310,19 @@ public class PdeEditor extends JFrame } + /** + * Extra public method so that PdeSketch can call + * this when a sketch is selected to be deleted, + * and it won't prompt for save as. + */ + public void handleNew() { + doStop(); + handleNewShift = false; + handleNewLibrary = false; + handleNew2(true); + } + + /** * User selected "New Library", this will act just like handleNew * but internally set a flag that the new guy is a library, @@ -1326,12 +1339,13 @@ public class PdeEditor extends JFrame /** * Does all the plumbing to create a new project * then calls handleOpen to load it up. - * @param startup true if the app is starting (auto-create a sketch) + * + * @param noPrompt true if the app is starting (auto-create a sketch) */ - protected void handleNew2(boolean startup) { + protected void handleNew2(boolean noPrompt) { try { String pdePath = - sketchbook.handleNew(startup, handleNewShift, handleNewLibrary); + sketchbook.handleNew(noPrompt, handleNewShift, handleNewLibrary); if (pdePath != null) handleOpen2(pdePath); } catch (IOException e) { @@ -1376,6 +1390,18 @@ public class PdeEditor extends JFrame * need to be saved. */ protected void handleOpen2(String path) { + if (sketch != null) { + // if leaving an empty sketch (i.e. the default) do an + // auto-clean right away + if (PdeBase.calcFolderSize(sketch.folder) == 0) { + //System.err.println("removing empty poopster"); + PdeBase.removeDir(sketch.folder); + sketchbook.rebuildMenus(); + } + //} else { + //System.err.println("sketch was null"); + } + try { // check to make sure that this .pde file is // in a folder of the same name diff --git a/processing/app/PdeEditorHeader.java b/processing/app/PdeEditorHeader.java index c0dd7b3e5..59d2e52be 100644 --- a/processing/app/PdeEditorHeader.java +++ b/processing/app/PdeEditorHeader.java @@ -46,7 +46,7 @@ public class PdeEditorHeader extends JComponent { JMenu menu; JPopupMenu popup; - JMenuItem deleteItem; + JMenuItem hideItem; int menuLeft; int menuRight; @@ -168,9 +168,8 @@ public class PdeEditorHeader extends JComponent { tabRight = new int[sketch.codeCount]; } - // disable rename on the first tab - deleteItem.setEnabled(sketch.current != sketch.code[0]); - // re-enabling for 75 to bring back renaming of sketches + // disable hide on the first tab + hideItem.setEnabled(sketch.current != sketch.code[0]); //int x = 0; //PdePreferences.GUI_SMALL; int x = (PdeBase.platform == PdeBase.MACOSX) ? 0 : 1; @@ -308,7 +307,6 @@ public class PdeEditorHeader extends JComponent { } }); menu.add(item); - deleteItem = item; item = new JMenuItem("Hide"); item.addActionListener(new ActionListener() { @@ -317,6 +315,7 @@ public class PdeEditorHeader extends JComponent { } }); menu.add(item); + hideItem = item; JMenu unhide = new JMenu("Unhide"); ActionListener unhideListener = new ActionListener() { diff --git a/processing/app/PdeSketch.java b/processing/app/PdeSketch.java index a70089ac6..11982a8ad 100644 --- a/processing/app/PdeSketch.java +++ b/processing/app/PdeSketch.java @@ -363,6 +363,11 @@ public class PdeSketch { File newFolder = new File(folder.getParentFile(), newName); boolean success = folder.renameTo(newFolder); folder = newFolder; + + // get the changes into the sketchbook menu + editor.sketchbook.rebuildMenus(); + + // reload the sketch load(); } else { @@ -402,16 +407,19 @@ public class PdeSketch { public void deleteCode() { // don't allow delete of the main code // TODO maybe gray out the menu on setCurrent(0) + /* if (current == code[0]) { PdeBase.showMessage("Can't do that", "You cannot delete the main " + ".pde file from a sketch\n"); return; } + */ // confirm deletion with user, yes/no Object[] options = { "OK", "Cancel" }; - String prompt = + String prompt = (current == code[0]) ? + "Are you sure you want to delete this sketch?" : "Are you sure you want to delete \"" + current.name + "\"?"; int result = JOptionPane.showOptionDialog(editor, prompt, @@ -422,21 +430,33 @@ public class PdeSketch { options, options[0]); if (result == JOptionPane.YES_OPTION) { - // delete the file - if (!current.file.delete()) { - PdeBase.showMessage("Couldn't do it", - "Could not delete \"" + current.name + "\"."); - return; + if (current == code[0]) { + // delete the entire sketch + PdeBase.removeDir(folder); + + // get the changes into the sketchbook menu + //sketchbook.rebuildMenus(); + + // make a new sketch, and i think this will rebuild the sketch menu + editor.handleNew(); + + } else { + // delete the file + if (!current.file.delete()) { + PdeBase.showMessage("Couldn't do it", + "Could not delete \"" + current.name + "\"."); + return; + } + + // remove code from the list + removeCode(current); + + // just set current tab to the main tab + setCurrent(0); + + // update the tabs + editor.header.repaint(); } - - // remove code from the list - removeCode(current); - - // just set current tab to the main tab - setCurrent(0); - - // update the tabs - editor.header.repaint(); } } diff --git a/processing/app/PdeSketchbook.java b/processing/app/PdeSketchbook.java index 328af0e99..72bbe8953 100644 --- a/processing/app/PdeSketchbook.java +++ b/processing/app/PdeSketchbook.java @@ -130,7 +130,7 @@ public class PdeSketchbook { * Handle creating a sketch folder, return its base .pde file * or null if the operation was cancelled. */ - public String handleNew(boolean startup, + public String handleNew(boolean noPrompt, boolean shift, boolean library) throws IOException { File newbieDir = null; @@ -147,7 +147,7 @@ public class PdeSketchbook { // unless, ermm, they user tested it and people preferred that as // a way to get started. shite. now i hate myself. // - if (startup) prompt = false; + if (noPrompt) prompt = false; if (prompt) { //if (!startup) { diff --git a/processing/todo.txt b/processing/todo.txt index 4d561b2fa..2d9ce4a73 100644 --- a/processing/todo.txt +++ b/processing/todo.txt @@ -30,9 +30,12 @@ o if additional tab is "public" class.. then make external? X this seems too dangerous X make font builder vertically resizable X 200 pt font hoses things / hides buttons -X bring back "rename" ? +X rename/delete work X rename is now enabled on the first tab -X 'delete' is disabled on the first tab (what would you do after delete?) +X delete on first tab will also delete the entire sketch +X leaving an empty sketch will remove it +X avoids creating a zillion sketches when deleting/clearing up sketchbook +X disable 'hide' menu item for the main code tab sketchbook/prefs location X read from registry key to get the proper name for these folders