Skip to content

Commit

Permalink
Merge branch 'startup-try1' into master-dev-rjlr
Browse files Browse the repository at this point in the history
Conflicts:
	app/src/processing/app/Base.java
  • Loading branch information
ricardojlrufino committed May 10, 2020
2 parents 7a323aa + 6fb467c commit d257f8a
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
import java.io.*;
import java.util.List;
import java.util.Timer;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.*;
import java.util.logging.Handler;
import java.util.logging.Level;
Expand Down Expand Up @@ -131,6 +133,9 @@ public class Base {

private PdeKeywords pdeKeywords;
private final List<JMenuItem> recentSketchesMenuItems = new LinkedList<>();

// Executor to load / reload menus in backgroud.
private Executor menuExecutor = Executors.newCachedThreadPool();

static public void main(String args[]) throws Exception {
if (!OSUtils.isWindows()) {
Expand Down Expand Up @@ -1088,14 +1093,10 @@ protected boolean handleQuitEach() {
public void rebuildSketchbookMenus() {
//System.out.println("async enter");
//new Exception().printStackTrace();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
//System.out.println("starting rebuild");
rebuildSketchbookMenu(Editor.sketchbookMenu);
rebuildToolbarMenu(Editor.toolbarMenu);
//System.out.println("done with rebuild");
}
});
//System.out.println("starting rebuild");
rebuildSketchbookMenu(Editor.sketchbookMenu);
rebuildToolbarMenu(Editor.toolbarMenu);
//System.out.println("done with rebuild");
//System.out.println("async exit");
}

Expand Down Expand Up @@ -1212,12 +1213,12 @@ protected void rebuildSketchbookMenu(JMenu menu) {
Editor.sketchbookData = null;

menu.removeAll();

SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
addSketches(menu, BaseNoGui.getSketchbookFolder());

// Execute in backgroud thread, no need UI thread becouse no rendering needed
menuExecutor.execute(() -> {

addSketches(menu, BaseNoGui.getSketchbookFolder());

JMenu librariesMenu = JMenuUtils.findSubMenuWithLabel(menu, "libraries");
if (librariesMenu != null) {
menu.remove(librariesMenu);
Expand All @@ -1226,8 +1227,8 @@ public void run() {
if (hardwareMenu != null) {
menu.remove(hardwareMenu);
}
}
});

}

private LibraryList getSortedLibraries() {
Expand Down Expand Up @@ -1311,10 +1312,8 @@ public void rebuildExamplesMenu(JMenu menu) {

menu.removeAll();

SwingUtilities.invokeLater(new Runnable() {

@Override
public void run() {
// Execute in backgroud thread, no need UI thread becouse no rendering needed
menuExecutor.execute(() -> {
// Add examples from distribution "example" folder
JMenuItem label = new JMenuItem(tr("Built-in Examples"));
label.setEnabled(false);
Expand Down Expand Up @@ -1476,7 +1475,6 @@ public void run() {
addSketchesSubmenu(menu, lib);
}
}
}
});

}
Expand Down Expand Up @@ -1576,9 +1574,8 @@ protected void onIndexesUpdated() throws Exception {
public void rebuildBoardsMenu() throws Exception {
boardsCustomMenus = new LinkedList<>();

SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
// Execute in backgroud thread, no need UI thread becouse no rendering needed
menuExecutor.execute(() -> {
// The first custom menu is the "Board" selection submenu
JMenu boardMenu = new JMenu(tr("Board"));
boardMenu.putClientProperty("removeOnWindowDeactivation", true);
Expand Down Expand Up @@ -1700,7 +1697,6 @@ public void actionPerformed(ActionEvent actionevent) {
menuItemToClick.setSelected(true);
menuItemToClick.getAction().actionPerformed(new ActionEvent(this, -1, ""));
}
}
});

}
Expand Down

0 comments on commit d257f8a

Please sign in to comment.