@@ -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)
@@ -1329,6 +1331,28 @@ public void rebuildExamplesMenu(JMenu menu) {
13291331 private static String priorPlatformFolder ;
13301332 private static boolean newLibraryImported ;
13311333
1334+ public void selectTargetBoard (TargetBoard targetBoard ) {
1335+ for (int i = 0 ; i < boardMenu .getItemCount (); i ++) {
1336+ JMenuItem menuItem = boardMenu .getItem (i );
1337+ if (!(menuItem instanceof JRadioButtonMenuItem )) {
1338+ continue ;
1339+ }
1340+
1341+ JRadioButtonMenuItem radioButtonMenuItem = ((JRadioButtonMenuItem ) menuItem );
1342+ if (targetBoard .getName ().equals (radioButtonMenuItem .getText ())) {
1343+ radioButtonMenuItem .setSelected (true );
1344+ break ;
1345+ }
1346+ }
1347+
1348+ BaseNoGui .selectBoard (targetBoard );
1349+ filterVisibilityOfSubsequentBoardMenus (boardsCustomMenus , targetBoard , 1 );
1350+
1351+ onBoardOrPortChange ();
1352+ rebuildImportMenu (Editor .importMenu );
1353+ rebuildExamplesMenu (Editor .examplesMenu );
1354+ }
1355+
13321356 public void onBoardOrPortChange () {
13331357 BaseNoGui .onBoardOrPortChange ();
13341358
@@ -1422,7 +1446,7 @@ public void rebuildBoardsMenu() throws Exception {
14221446 boardsCustomMenus = new LinkedList <>();
14231447
14241448 // The first custom menu is the "Board" selection submenu
1425- JMenu boardMenu = new JMenu (tr ("Board" ));
1449+ boardMenu = new JMenu (tr ("Board" ));
14261450 boardMenu .putClientProperty ("removeOnWindowDeactivation" , true );
14271451 MenuScroller .setScrollerFor (boardMenu ).setTopFixedCount (1 );
14281452
@@ -1531,12 +1555,7 @@ private JRadioButtonMenuItem createBoardMenusAndCustomMenus(
15311555 @ SuppressWarnings ("serial" )
15321556 Action action = new AbstractAction (board .getName ()) {
15331557 public void actionPerformed (ActionEvent actionevent ) {
1534- BaseNoGui .selectBoard ((TargetBoard ) getValue ("b" ));
1535- filterVisibilityOfSubsequentBoardMenus (boardsCustomMenus , (TargetBoard ) getValue ("b" ), 1 );
1536-
1537- onBoardOrPortChange ();
1538- rebuildImportMenu (Editor .importMenu );
1539- rebuildExamplesMenu (Editor .examplesMenu );
1558+ selectTargetBoard ((TargetBoard ) getValue ("b" ));
15401559 }
15411560 };
15421561 action .putValue ("b" , board );
0 commit comments