got sketchbook.clean() working again, also added prefs for it

This commit is contained in:
benfry
2004-06-22 03:13:54 +00:00
parent 74f78546bf
commit 572770ac7b
3 changed files with 51 additions and 28 deletions
+14 -1
View File
@@ -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"));
+34 -25
View File
@@ -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));
}
}
}
+3 -2
View File
@@ -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