@@ -116,6 +116,8 @@ public class Base {
116116 List <Editor > editors = Collections .synchronizedList (new ArrayList <Editor >());
117117 Editor activeEditor ;
118118
119+ private static JMenu boardMenu ;
120+
119121 // these menus are shared so that the board and serial port selections
120122 // are the same for all windows (since the board and serial port that are
121123 // actually used are determined by the preferences, which are shared)
@@ -1342,6 +1344,29 @@ public void rebuildExamplesMenu(JMenu menu) {
13421344 private static String priorPlatformFolder ;
13431345 private static boolean newLibraryImported ;
13441346
1347+ public void selectTargetBoard (TargetBoard targetBoard ) {
1348+ for (int i = 0 ; i < boardMenu .getItemCount (); i ++) {
1349+ JMenuItem menuItem = boardMenu .getItem (i );
1350+ if (!(menuItem instanceof JRadioButtonMenuItem )) {
1351+ continue ;
1352+ }
1353+
1354+ JRadioButtonMenuItem radioButtonMenuItem = ((JRadioButtonMenuItem ) menuItem );
1355+ if (targetBoard .getName ().equals (radioButtonMenuItem .getText ())) {
1356+ radioButtonMenuItem .setSelected (true );
1357+ break ;
1358+ }
1359+ }
1360+
1361+ BaseNoGui .selectBoard (targetBoard );
1362+ filterVisibilityOfSubsequentBoardMenus (boardsCustomMenus , targetBoard , 1 );
1363+
1364+ onBoardOrPortChange ();
1365+ rebuildImportMenu (Editor .importMenu );
1366+ rebuildExamplesMenu (Editor .examplesMenu );
1367+ rebuildProgrammerMenu ();
1368+ }
1369+
13451370 public void onBoardOrPortChange () {
13461371 BaseNoGui .onBoardOrPortChange ();
13471372
@@ -1435,7 +1460,7 @@ public void rebuildBoardsMenu() throws Exception {
14351460 boardsCustomMenus = new LinkedList <>();
14361461
14371462 // The first custom menu is the "Board" selection submenu
1438- JMenu boardMenu = new JMenu (tr ("Board" ));
1463+ boardMenu = new JMenu (tr ("Board" ));
14391464 boardMenu .putClientProperty ("removeOnWindowDeactivation" , true );
14401465 MenuScroller .setScrollerFor (boardMenu ).setTopFixedCount (1 );
14411466
@@ -1568,13 +1593,7 @@ private JRadioButtonMenuItem createBoardMenusAndCustomMenus(
15681593 @ SuppressWarnings ("serial" )
15691594 Action action = new AbstractAction (board .getName ()) {
15701595 public void actionPerformed (ActionEvent actionevent ) {
1571- BaseNoGui .selectBoard ((TargetBoard ) getValue ("b" ));
1572- filterVisibilityOfSubsequentBoardMenus (boardsCustomMenus , (TargetBoard ) getValue ("b" ), 1 );
1573-
1574- onBoardOrPortChange ();
1575- rebuildImportMenu (Editor .importMenu );
1576- rebuildExamplesMenu (Editor .examplesMenu );
1577- rebuildProgrammerMenu ();
1596+ selectTargetBoard ((TargetBoard ) getValue ("b" ));
15781597 }
15791598 };
15801599 action .putValue ("b" , board );
0 commit comments