@@ -116,6 +116,8 @@ public class Base {
116116 // int editorCount;
117117 List <Editor > editors = Collections .synchronizedList (new ArrayList <Editor >());
118118 Editor activeEditor ;
119+
120+ private static JMenu boardMenu ;
119121
120122 // these menus are shared so that the board and serial port selections
121123 // are the same for all windows (since the board and serial port that are
@@ -1308,6 +1310,28 @@ public void rebuildExamplesMenu(JMenu menu) {
13081310
13091311 private static String priorPlatformFolder ;
13101312 private static boolean newLibraryImported ;
1313+
1314+ public void selectTargetBoard (TargetBoard targetBoard ) {
1315+ for (int i = 0 ; i < boardMenu .getItemCount (); i ++) {
1316+ JMenuItem menuItem = boardMenu .getItem (i );
1317+ if (!(menuItem instanceof JRadioButtonMenuItem )) {
1318+ continue ;
1319+ }
1320+
1321+ JRadioButtonMenuItem radioButtonMenuItem = ((JRadioButtonMenuItem ) menuItem );
1322+ if (targetBoard .getName ().equals (radioButtonMenuItem .getText ())) {
1323+ radioButtonMenuItem .setSelected (true );
1324+ break ;
1325+ }
1326+ }
1327+
1328+ BaseNoGui .selectBoard (targetBoard );
1329+ filterVisibilityOfSubsequentBoardMenus (boardsCustomMenus , targetBoard , 1 );
1330+
1331+ onBoardOrPortChange ();
1332+ rebuildImportMenu (Editor .importMenu );
1333+ rebuildExamplesMenu (Editor .examplesMenu );
1334+ }
13111335
13121336 public synchronized void onBoardOrPortChange () {
13131337 BaseNoGui .onBoardOrPortChange ();
@@ -1402,7 +1426,7 @@ public void rebuildBoardsMenu() throws Exception {
14021426 boardsCustomMenus = new LinkedList <>();
14031427
14041428 // The first custom menu is the "Board" selection submenu
1405- JMenu boardMenu = new JMenu (tr ("Board" ));
1429+ boardMenu = new JMenu (tr ("Board" ));
14061430 boardMenu .putClientProperty ("removeOnWindowDeactivation" , true );
14071431 MenuScroller .setScrollerFor (boardMenu ).setTopFixedCount (1 );
14081432
@@ -1520,12 +1544,7 @@ public void run() {
15201544 } catch (InterruptedException e ) {}
15211545 }
15221546 }
1523-
1524- BaseNoGui .selectBoard ((TargetBoard ) getValue ("b" ));
1525- filterVisibilityOfSubsequentBoardMenus (boardsCustomMenus , (TargetBoard ) getValue ("b" ), 1 );
1526- onBoardOrPortChange ();
1527- rebuildImportMenu (Editor .importMenu );
1528- rebuildExamplesMenu (Editor .examplesMenu );
1547+ selectTargetBoard ((TargetBoard ) getValue ("b" ));
15291548 }
15301549 }.start ();
15311550 }
0 commit comments