@@ -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)
@@ -1337,6 +1339,29 @@ public void rebuildExamplesMenu(JMenu menu) {
13371339 private static String priorPlatformFolder ;
13381340 private static boolean newLibraryImported ;
13391341
1342+ public void selectTargetBoard (TargetBoard targetBoard ) {
1343+ for (int i = 0 ; i < boardMenu .getItemCount (); i ++) {
1344+ JMenuItem menuItem = boardMenu .getItem (i );
1345+ if (!(menuItem instanceof JRadioButtonMenuItem )) {
1346+ continue ;
1347+ }
1348+
1349+ JRadioButtonMenuItem radioButtonMenuItem = ((JRadioButtonMenuItem ) menuItem );
1350+ if (targetBoard .getName ().equals (radioButtonMenuItem .getText ())) {
1351+ radioButtonMenuItem .setSelected (true );
1352+ break ;
1353+ }
1354+ }
1355+
1356+ BaseNoGui .selectBoard (targetBoard );
1357+ filterVisibilityOfSubsequentBoardMenus (boardsCustomMenus , targetBoard , 1 );
1358+
1359+ onBoardOrPortChange ();
1360+ rebuildImportMenu (Editor .importMenu );
1361+ rebuildExamplesMenu (Editor .examplesMenu );
1362+ rebuildProgrammerMenu ();
1363+ }
1364+
13401365 public void onBoardOrPortChange () {
13411366 BaseNoGui .onBoardOrPortChange ();
13421367
@@ -1430,7 +1455,7 @@ public void rebuildBoardsMenu() throws Exception {
14301455 boardsCustomMenus = new LinkedList <>();
14311456
14321457 // The first custom menu is the "Board" selection submenu
1433- JMenu boardMenu = new JMenu (tr ("Board" ));
1458+ boardMenu = new JMenu (tr ("Board" ));
14341459 boardMenu .putClientProperty ("removeOnWindowDeactivation" , true );
14351460 MenuScroller .setScrollerFor (boardMenu ).setTopFixedCount (1 );
14361461
@@ -1539,13 +1564,7 @@ private JRadioButtonMenuItem createBoardMenusAndCustomMenus(
15391564 @ SuppressWarnings ("serial" )
15401565 Action action = new AbstractAction (board .getName ()) {
15411566 public void actionPerformed (ActionEvent actionevent ) {
1542- BaseNoGui .selectBoard ((TargetBoard ) getValue ("b" ));
1543- filterVisibilityOfSubsequentBoardMenus (boardsCustomMenus , (TargetBoard ) getValue ("b" ), 1 );
1544-
1545- onBoardOrPortChange ();
1546- rebuildImportMenu (Editor .importMenu );
1547- rebuildExamplesMenu (Editor .examplesMenu );
1548- rebuildProgrammerMenu ();
1567+ selectTargetBoard ((TargetBoard ) getValue ("b" ));
15491568 }
15501569 };
15511570 action .putValue ("b" , board );
0 commit comments