diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index ab7d379ef44..1d38c590a30 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1310,7 +1310,7 @@ public void rebuildExamplesMenu(JMenu menu) { private static String priorPlatformFolder; private static boolean newLibraryImported; - public void onBoardOrPortChange() { + public synchronized void onBoardOrPortChange() { BaseNoGui.onBoardOrPortChange(); // reload keywords when package/platform changes @@ -1509,12 +1509,26 @@ private JRadioButtonMenuItem createBoardMenusAndCustomMenus( @SuppressWarnings("serial") Action action = new AbstractAction(board.getName()) { public void actionPerformed(ActionEvent actionevent) { - BaseNoGui.selectBoard((TargetBoard) getValue("b")); - filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, (TargetBoard) getValue("b"), 1); - onBoardOrPortChange(); - rebuildImportMenu(Editor.importMenu); - rebuildExamplesMenu(Editor.examplesMenu); + new Thread() + { + public void run() { + if (activeEditor != null && activeEditor.isCompiling()) { + // block until isCompiling becomes false, but aboid blocking the UI + while (activeEditor.isCompiling()) { + try { + Thread.sleep(100); + } catch (InterruptedException e) {} + } + } + + BaseNoGui.selectBoard((TargetBoard) getValue("b")); + filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, (TargetBoard) getValue("b"), 1); + onBoardOrPortChange(); + rebuildImportMenu(Editor.importMenu); + rebuildExamplesMenu(Editor.examplesMenu); + } + }.start(); } }; action.putValue("b", board); diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index dd7759471bc..f473f50dfb6 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -2266,6 +2266,10 @@ public void run() { } } + public boolean isCompiling() { + return uploading; + } + private void resumeOrCloseSerialMonitor() { // Return the serial monitor window to its initial state if (serialMonitor != null) {