Skip to content

Move populateSketchbookMenu to a separate thread #1037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -1942,18 +1942,20 @@ public void rebuildSketchbook() {


public void populateSketchbookMenu(JMenu menu) {
boolean found = false;
try {
found = addSketches(menu, sketchbookFolder);
} catch (Exception e) {
Messages.showWarning("Sketchbook Menu Error",
"An error occurred while trying to list the sketchbook.", e);
}
if (!found) {
JMenuItem empty = new JMenuItem(Language.text("menu.file.sketchbook.empty"));
empty.setEnabled(false);
menu.add(empty);
}
new Thread(() -> {
boolean found = false;
try {
found = addSketches(menu, sketchbookFolder);
} catch (Exception e) {
Messages.showWarning("Sketchbook Menu Error",
"An error occurred while trying to list the sketchbook.", e);
}
if (!found) {
JMenuItem empty = new JMenuItem(Language.text("menu.file.sketchbook.empty"));
empty.setEnabled(false);
menu.add(empty);
}
}).start();
}


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

// Don't look inside the 'android' folders in the sketchbook
if (folder.getName().equals("android")) {
return false;
}

if (folder.getName().equals("libraries")) {
return false; // let's not go there
}
Expand Down Expand Up @@ -2054,13 +2062,19 @@ protected boolean addSketches(JMenu menu, File folder) {
*/
public boolean addSketches(DefaultMutableTreeNode node, File folder,
boolean examples) throws IOException {
Messages.log("scanning " + folder.getAbsolutePath());
// skip .DS_Store files, etc. (this shouldn't actually be necessary)
if (!folder.isDirectory()) {
return false;
}

final String folderName = folder.getName();

// Don't look inside the 'android' folders in the sketchbook
if (folderName.equals("android")) {
return false;
}

// Don't look inside the 'libraries' folders in the sketchbook
if (folderName.equals("libraries")) {
return false;
Expand Down
Loading