properly reload menus/libraries list when changing sketchbook folder location

This commit is contained in:
benfry
2011-03-09 15:55:24 +00:00
parent fbbc728190
commit adbcafa53d
6 changed files with 90 additions and 34 deletions
+25 -9
View File
@@ -1050,21 +1050,30 @@ public class Base {
* Asynchronous version of menu rebuild to be used on save and rename
* to prevent the interface from locking up until the menus are done.
*/
protected void rebuildSketchbookMenus() {
protected void rebuildSketchbookMenusAsync() {
//System.out.println("async enter");
//new Exception().printStackTrace();
EventQueue.invokeLater(new Runnable() {
public void run() {
//System.out.println("starting rebuild");
// rebuildSketchbookMenu(sketchbookMenu);
rebuildSketchbookMenu();
for (Mode mode : modeList) {
mode.rebuildToolbarMenu();
}
//System.out.println("done with rebuild");
rebuildSketchbookMenus();
}
});
//System.out.println("async exit");
}
/**
* Synchronous version of rebuild, used when the sketchbook folder has
* changed, so that the libraries are properly re-scanned before those menus
* (and the examples window) are rebuilt.
*/
protected void rebuildSketchbookMenus() {
rebuildSketchbookMenu();
for (Mode mode : modeList) {
//mode.rebuildLibraryList();
mode.rebuildImportMenu(); // calls rebuildLibraryList
mode.rebuildToolbarMenu();
mode.resetExamples();
}
}
@@ -1590,6 +1599,13 @@ public class Base {
}
public void setSketchbookFolder(File folder) {
sketchbookFolder = folder;
Preferences.set("sketchbook.path", folder.getAbsolutePath());
rebuildSketchbookMenus();
}
public File getSketchbookFolder() {
// return new File(Preferences.get("sketchbook.path"));
return sketchbookFolder;
+34 -7
View File
@@ -200,7 +200,6 @@ public abstract class Mode {
public JMenu getImportMenu() {
if (importMenu == null) {
importMenu = new JMenu("Import Library...");
rebuildImportMenu();
}
return importMenu;
@@ -208,8 +207,12 @@ public abstract class Mode {
public void rebuildImportMenu() { //JMenu importMenu) {
//System.out.println("rebuilding import menu");
importMenu.removeAll();
if (importMenu == null) {
importMenu = new JMenu("Import Library...");
} else {
//System.out.println("rebuilding import menu");
importMenu.removeAll();
}
rebuildLibraryList();
@@ -225,17 +228,24 @@ public abstract class Mode {
// e1.printStackTrace();
// }
for (Library library : coreLibraries) {
JMenuItem item = new JMenuItem(library.getName());
item.addActionListener(listener);
item.setActionCommand(library.getJarPath());
if (coreLibraries.size() == 0) {
JMenuItem item = new JMenuItem(getTitle() + " mode has no core libraries");
item.setEnabled(false);
importMenu.add(item);
} else {
for (Library library : coreLibraries) {
JMenuItem item = new JMenuItem(library.getName());
item.addActionListener(listener);
item.setActionCommand(library.getJarPath());
importMenu.add(item);
}
}
if (contribLibraries.size() != 0) {
importMenu.addSeparator();
JMenuItem contrib = new JMenuItem("Contributed");
contrib.setEnabled(false);
importMenu.add(contrib);
for (Library library : contribLibraries) {
JMenuItem item = new JMenuItem(library.getName());
@@ -407,6 +417,23 @@ public abstract class Mode {
}
public void resetExamples() {
if (examplesFrame != null) {
boolean visible = examplesFrame.isVisible();
Rectangle bounds = null;
if (visible) {
bounds = examplesFrame.getBounds();
examplesFrame.setVisible(false);
}
examplesFrame = null;
if (visible) {
showExamplesFrame();
examplesFrame.setBounds(bounds);
}
}
}
public void showExamplesFrame() {
if (examplesFrame == null) {
examplesFrame = new JFrame(getTitle() + " Examples");
+1 -2
View File
@@ -516,8 +516,7 @@ public class Preferences {
String oldPath = get("sketchbook.path");
String newPath = sketchbookLocationField.getText();
if (!newPath.equals(oldPath)) {
editor.base.rebuildSketchbookMenus();
set("sketchbook.path", newPath);
editor.base.setSketchbookFolder(new File(newPath));
}
setBoolean("editor.external", externalEditorBox.isSelected());
+2 -3
View File
@@ -494,7 +494,7 @@ public class Sketch {
// get the changes into the sketchbook menu
// (re-enabled in 0115 to fix bug #332)
editor.base.rebuildSketchbookMenus();
editor.base.rebuildSketchbookMenusAsync();
} else { // else if something besides code[0]
if (!current.renameTo(newFile, newExtension)) {
@@ -891,8 +891,7 @@ public class Sketch {
editor.getScrollPosition());
// Name changed, rebuild the sketch menus
//editor.sketchbook.rebuildMenusAsync();
editor.base.rebuildSketchbookMenus();
editor.base.rebuildSketchbookMenusAsync();
// Make sure that it's not an untitled sketch
setUntitled(false);
+19 -8
View File
@@ -1,5 +1,17 @@
PROCESSING REV 0194 - 9 March 2011
[ fixes ]
+ The Auto Format command went missing in 0193. It's back for 0194, but is
now located in the Edit menu, where it will stay for the rest of its long
and happy life.
+ The "Import Library" menu wasn't being updated properly in 0193. Note that
for the time being, there are no core libraries on Android. (OpenGL is built
in, for instance.)
+ Library examples weren't showing up in 0193, now they're back.
[ notes ]
+ Because both OpenGL and OpenGL2 are present, there may be conflicts if you
@@ -12,15 +24,14 @@ PROCESSING REV 0194 - 9 March 2011
then you should remove one of the OpenGL libraries, depending on which you
would like to use.
[ fixes ]
+ OpenGL is built-in on Android. You don't need to add it as a library, the
way you do with the desktop. A "import processing.opengl.*" line won't
hurt anything (the preprocessor removes it), but it's also not necessary.
(This is also noted in the Android wiki.)
+ The Auto Format command went missing in 0193. It's back for 0194, but is
now located in the Edit menu, where it will stay for the rest of its long
and happy life.
+ The "Import Library" menu wasn't being updated properly in 0193. Note that
for the time being, there are no core libraries on Android. (OpenGL is built
in, for instance.)
+ Library examples no longer show up buried in the sketchbook. Instead they
can be found in the "Libraries" and "Contributed Libraries" sections of
the examples window.
[ additions ]
+9 -5
View File
@@ -7,19 +7,23 @@ X build.xml problem knocking out the library examples
X auto format missing
X remove "temporarily skipping deletion of" message
X figure out how to suppress errors from find in build.xml
X when changing sketchbook location, need to reload examples window
X and libraries, etc.. maybe just require a restart?
X rebuilding library list, etc when changing sketchbook location
_ flickering issue
_ when changing sketchbook location, need to reload examples window
_ and libraries, etc.. maybe just require a restart?
_ flickering issue with JAVA2D
regressions
_ strange window flicker when first opened
_ test libraries on android
_ test .java files on desktop version
_ untitled sketches not working properly
_ untitled sketches not working properly(?)
_ clicking the editor window (from the examples window) causes an exception
additions
_ when creating a sketch within non-java mode, should write the settings file
_ so that it re-loads in the proper environment
_ examples window sketches should load in proper environment
ugliness