Skip to content

Commit c86a162

Browse files
committed
Move populateSketchbookMenu to a separate thread
1 parent 12d37b6 commit c86a162

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

app/src/processing/app/Base.java

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,18 +1942,20 @@ public void rebuildSketchbook() {
19421942

19431943

19441944
public void populateSketchbookMenu(JMenu menu) {
1945-
boolean found = false;
1946-
try {
1947-
found = addSketches(menu, sketchbookFolder);
1948-
} catch (Exception e) {
1949-
Messages.showWarning("Sketchbook Menu Error",
1950-
"An error occurred while trying to list the sketchbook.", e);
1951-
}
1952-
if (!found) {
1953-
JMenuItem empty = new JMenuItem(Language.text("menu.file.sketchbook.empty"));
1954-
empty.setEnabled(false);
1955-
menu.add(empty);
1956-
}
1945+
new Thread(() -> {
1946+
boolean found = false;
1947+
try {
1948+
found = addSketches(menu, sketchbookFolder);
1949+
} catch (Exception e) {
1950+
Messages.showWarning("Sketchbook Menu Error",
1951+
"An error occurred while trying to list the sketchbook.", e);
1952+
}
1953+
if (!found) {
1954+
JMenuItem empty = new JMenuItem(Language.text("menu.file.sketchbook.empty"));
1955+
empty.setEnabled(false);
1956+
menu.add(empty);
1957+
}
1958+
}).start();
19571959
}
19581960

19591961

@@ -1964,11 +1966,17 @@ public void populateSketchbookMenu(JMenu menu) {
19641966
* sketch should open in a new window.
19651967
*/
19661968
protected boolean addSketches(JMenu menu, File folder) {
1969+
Messages.log("scanning " + folder.getAbsolutePath());
19671970
// skip .DS_Store files, etc. (this shouldn't actually be necessary)
19681971
if (!folder.isDirectory()) {
19691972
return false;
19701973
}
19711974

1975+
// Don't look inside the 'android' folders in the sketchbook
1976+
if (folder.getName().equals("android")) {
1977+
return false;
1978+
}
1979+
19721980
if (folder.getName().equals("libraries")) {
19731981
return false; // let's not go there
19741982
}
@@ -2054,13 +2062,19 @@ protected boolean addSketches(JMenu menu, File folder) {
20542062
*/
20552063
public boolean addSketches(DefaultMutableTreeNode node, File folder,
20562064
boolean examples) throws IOException {
2065+
Messages.log("scanning " + folder.getAbsolutePath());
20572066
// skip .DS_Store files, etc. (this shouldn't actually be necessary)
20582067
if (!folder.isDirectory()) {
20592068
return false;
20602069
}
20612070

20622071
final String folderName = folder.getName();
20632072

2073+
// Don't look inside the 'android' folders in the sketchbook
2074+
if (folderName.equals("android")) {
2075+
return false;
2076+
}
2077+
20642078
// Don't look inside the 'libraries' folders in the sketchbook
20652079
if (folderName.equals("libraries")) {
20662080
return false;

0 commit comments

Comments
 (0)