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