@@ -1309,7 +1309,7 @@ public void rebuildExamplesMenu(JMenu menu) {
13091309 private static String priorPlatformFolder ;
13101310 private static boolean newLibraryImported ;
13111311
1312- public void onBoardOrPortChange () {
1312+ public synchronized void onBoardOrPortChange () {
13131313 BaseNoGui .onBoardOrPortChange ();
13141314
13151315 // reload keywords when package/platform changes
@@ -1508,12 +1508,26 @@ private JRadioButtonMenuItem createBoardMenusAndCustomMenus(
15081508 @ SuppressWarnings ("serial" )
15091509 Action action = new AbstractAction (board .getName ()) {
15101510 public void actionPerformed (ActionEvent actionevent ) {
1511- BaseNoGui .selectBoard ((TargetBoard ) getValue ("b" ));
1512- filterVisibilityOfSubsequentBoardMenus (boardsCustomMenus , (TargetBoard ) getValue ("b" ), 1 );
15131511
1514- onBoardOrPortChange ();
1515- rebuildImportMenu (Editor .importMenu );
1516- rebuildExamplesMenu (Editor .examplesMenu );
1512+ new Thread ()
1513+ {
1514+ public void run () {
1515+ if (activeEditor != null && activeEditor .isCompiling ()) {
1516+ // block until isCompiling becomes false, but aboid blocking the UI
1517+ while (activeEditor .isCompiling ()) {
1518+ try {
1519+ Thread .sleep (100 );
1520+ } catch (InterruptedException e ) {}
1521+ }
1522+ }
1523+
1524+ BaseNoGui .selectBoard ((TargetBoard ) getValue ("b" ));
1525+ filterVisibilityOfSubsequentBoardMenus (boardsCustomMenus , (TargetBoard ) getValue ("b" ), 1 );
1526+ onBoardOrPortChange ();
1527+ rebuildImportMenu (Editor .importMenu );
1528+ rebuildExamplesMenu (Editor .examplesMenu );
1529+ }
1530+ }.start ();
15171531 }
15181532 };
15191533 action .putValue ("b" , board );
0 commit comments