From fb37f2f459b7b2a1fe6e90f2c6adc3a06b59c113 Mon Sep 17 00:00:00 2001 From: benfry Date: Tue, 22 Jun 2004 03:13:54 +0000 Subject: [PATCH] got sketchbook.clean() working again, also added prefs for it --- processing/app/PdePreferences.java | 15 +++++++- processing/app/PdeSketchbook.java | 59 +++++++++++++++++------------- processing/todo.txt | 5 ++- 3 files changed, 51 insertions(+), 28 deletions(-) diff --git a/processing/app/PdePreferences.java b/processing/app/PdePreferences.java index bef8c14d7..cbbf545eb 100644 --- a/processing/app/PdePreferences.java +++ b/processing/app/PdePreferences.java @@ -85,6 +85,7 @@ public class PdePreferences extends JComponent { JTextField sketchbookLocationField; JCheckBox sketchPromptBox; + JCheckBox sketchCleanBox; JCheckBox exportLibraryBox; JCheckBox externalEditorBox; @@ -194,6 +195,16 @@ public class PdePreferences extends JComponent { top += d.height + GUI_BETWEEN; + // [ ] Delete empty sketches on Quit + + sketchCleanBox = new JCheckBox("Delete empty sketches on Quit"); + pain.add(sketchCleanBox); + d = sketchCleanBox.getPreferredSize(); + sketchCleanBox.setBounds(left, top, d.width, d.height); + right = Math.max(right, left + d.width); + top += d.height + GUI_BETWEEN; + + // Sketchbook location: // [...............................] [ Browse ] @@ -240,7 +251,7 @@ public class PdePreferences extends JComponent { top += vmax + GUI_BETWEEN; - // [ ] Use external editor + // [ ] Enable export to "Library" exportLibraryBox = new JCheckBox("Enable export to \"Library\""); pain.add(exportLibraryBox); @@ -367,6 +378,7 @@ public class PdePreferences extends JComponent { // put each of the settings into the table setBoolean("sketchbook.prompt", sketchPromptBox.isSelected()); + setBoolean("sketchbook.auto_clean", sketchCleanBox.isSelected()); set("sketchbook.path", sketchbookLocationField.getText()); setBoolean("export.library", exportLibraryBox.isSelected()); setBoolean("editor.external", externalEditorBox.isSelected()); @@ -380,6 +392,7 @@ public class PdePreferences extends JComponent { // set all settings entry boxes to their actual status sketchPromptBox.setSelected(getBoolean("sketchbook.prompt")); + sketchCleanBox.setSelected(getBoolean("sketchbook.auto_clean")); sketchbookLocationField.setText(get("sketchbook.path")); exportLibraryBox.setSelected(getBoolean("export.library")); externalEditorBox.setSelected(getBoolean("editor.external")); diff --git a/processing/app/PdeSketchbook.java b/processing/app/PdeSketchbook.java index e077cbcf3..d66fad54c 100644 --- a/processing/app/PdeSketchbook.java +++ b/processing/app/PdeSketchbook.java @@ -404,39 +404,48 @@ public class PdeSketchbook { * Clear out projects that are empty. */ public void clean() { - System.err.println("TODO sketchbook.clean() is disabled"); - if (true) return; // fool the compiler + //if (!PdePreferences.getBoolean("sketchbook.auto_clean")) return; - if (!PdePreferences.getBoolean("sketchbook.auto_clean")) return; - - //String userPath = base.sketchbookPath + File.separator + userName; - //File userFolder = new File(userPath); File sketchbookFolder = new File(PdePreferences.get("sketchbook.path")); + if (!sketchbookFolder.exists()) return; - //System.out.println("auto cleaning"); - if (sketchbookFolder.exists()) { - //String entries[] = new File(userPath).list(); - String entries[] = sketchbookFolder.list(); - if (entries != null) { - for (int j = 0; j < entries.length; j++) { - //System.out.println(entries[j] + " " + entries.length); + //String entries[] = new File(userPath).list(); + String entries[] = sketchbookFolder.list(); + if (entries != null) { + for (int j = 0; j < entries.length; j++) { + //System.out.println(entries[j] + " " + entries.length); + if (entries[j].charAt(0) == '.') continue; - if (entries[j].charAt(0) == '.') continue; + //File prey = new File(userPath, entries[j]); + File prey = new File(sketchbookFolder, entries[j]); + File pde = new File(prey, entries[j] + ".pde"); - //File prey = new File(userPath, entries[j]); - File prey = new File(sketchbookFolder, entries[j]); - File pde = new File(prey, entries[j] + ".pde"); + // make sure this is actually a sketch folder with a .pde, + // not a .DS_Store file or another random user folder - // make sure this is actually a sketch folder with a .pde, - // not a .DS_Store file or another random user folder + if (pde.exists() && + (PdeBase.calcFolderSize(prey) == 0)) { + //System.out.println("i want to remove " + prey); - if (pde.exists()) { - if (PdeBase.calcFolderSize(prey) == 0) { - //System.out.println("i want to remove " + prey); + if (PdePreferences.getBoolean("sketchbook.auto_clean")) { + PdeBase.removeDir(prey); + + } else { // otherwise prompt the user + String prompt = + "Remove empty sketch titled \"" + entries[j] + "\"?"; + + Object[] options = { "Yes", "No" }; + int result = + JOptionPane.showOptionDialog(editor, + prompt, + "Housekeeping", + JOptionPane.YES_NO_OPTION, + JOptionPane.QUESTION_MESSAGE, + null, + options, + options[0]); + if (result == JOptionPane.YES_OPTION) { PdeBase.removeDir(prey); - //} else { - //System.out.println("not removign because size is " + - // calcFolderSize(prey)); } } } diff --git a/processing/todo.txt b/processing/todo.txt index 1316f0e64..34fa55d2e 100644 --- a/processing/todo.txt +++ b/processing/todo.txt @@ -109,8 +109,9 @@ X shift-new will always prompt with filedialog X dashes shouldn't be allowed in filenames for sketches X actually, lost the naming stuff because now using FileDialog X this also needs to be checked when building the sketch menu - -_ write sketchbook.clean() +X rewrite sketchbook.clean() +X prompt user if they don't have it set to auto +X add a pref to the preferences window _ don't force everything into a single .jar on export