working on async method for rebuilding sketch menu

This commit is contained in:
benfry
2006-11-09 13:52:36 +00:00
parent 0be1545ff7
commit 91bcf775d3
2 changed files with 21 additions and 4 deletions
+5 -3
View File
@@ -1563,7 +1563,8 @@ public class Editor extends JFrame
if (!oldPath.equals(newPath)) {
if (Base.calcFolderSize(sketch.folder) == 0) {
Base.removeDir(sketch.folder);
sketchbook.rebuildMenus();
//sketchbook.rebuildMenus();
sketchbook.rebuildMenusAsync();
}
}
} catch (Exception e) { } // oh well
@@ -1695,7 +1696,8 @@ public class Editor extends JFrame
message(EMPTY);
}
// rebuild sketch menu in case a save-as was forced
sketchbook.rebuildMenus();
//sketchbook.rebuildMenus();
sketchbook.rebuildMenusAsync();
} catch (Exception e) {
// show the error as a message in the window
@@ -1720,7 +1722,7 @@ public class Editor extends JFrame
try {
if (sketch.saveAs()) {
message("Done Saving.");
sketchbook.rebuildMenus();
sketchbook.rebuildMenusAsync();
} else {
message("Save Cancelled.");
}
+16 -1
View File
@@ -224,7 +224,7 @@ public class Sketchbook {
}
// make a note of a newly added sketch in the sketchbook menu
rebuildMenus();
rebuildMenusAsync();
// now open it up
//handleOpen(newbieName, newbieFile, newbieDir);
@@ -340,6 +340,19 @@ public class Sketchbook {
}
/**
* Asynchronous version of menu rebuild to be used on 'new' and 'save',
* to prevent the interface from locking up until the menus are done.
*/
public void rebuildMenusAsync() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
rebuildMenus();
}
});
}
/**
* Rebuild the menu full of sketches based on the
* contents of the sketchbook.
@@ -349,6 +362,7 @@ public class Sketchbook {
* the menu will disappear from its original location.
*/
public void rebuildMenus() {
//EditorConsole.systemOut.println("rebuilding menus");
try {
// rebuild file/open and the toolbar popup menus
buildMenu(openMenu);
@@ -373,6 +387,7 @@ public class Sketchbook {
"sketchbook menu. Things might get a little\n" +
"kooky around here.", e);
}
//EditorConsole.systemOut.println("done rebuilding menus");
}