From 91bcf775d3911427cf420609e94420f30e57fa83 Mon Sep 17 00:00:00 2001 From: benfry Date: Thu, 9 Nov 2006 13:52:36 +0000 Subject: [PATCH] working on async method for rebuilding sketch menu --- app/Editor.java | 8 +++++--- app/Sketchbook.java | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/Editor.java b/app/Editor.java index a0923ab81..b27028f59 100644 --- a/app/Editor.java +++ b/app/Editor.java @@ -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."); } diff --git a/app/Sketchbook.java b/app/Sketchbook.java index 163b6aae6..46ddd366c 100644 --- a/app/Sketchbook.java +++ b/app/Sketchbook.java @@ -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"); }