@@ -116,6 +116,8 @@ public class Base {
116
116
List <Editor > editors = Collections .synchronizedList (new ArrayList <Editor >());
117
117
Editor activeEditor ;
118
118
119
+ private static JMenu boardMenu ;
120
+
119
121
// these menus are shared so that the board and serial port selections
120
122
// are the same for all windows (since the board and serial port that are
121
123
// actually used are determined by the preferences, which are shared)
@@ -1328,6 +1330,28 @@ public void rebuildExamplesMenu(JMenu menu) {
1328
1330
private static String priorPlatformFolder ;
1329
1331
private static boolean newLibraryImported ;
1330
1332
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
+
1331
1355
public void onBoardOrPortChange () {
1332
1356
BaseNoGui .onBoardOrPortChange ();
1333
1357
@@ -1421,7 +1445,7 @@ public void rebuildBoardsMenu() throws Exception {
1421
1445
boardsCustomMenus = new LinkedList <>();
1422
1446
1423
1447
// The first custom menu is the "Board" selection submenu
1424
- JMenu boardMenu = new JMenu (tr ("Board" ));
1448
+ boardMenu = new JMenu (tr ("Board" ));
1425
1449
boardMenu .putClientProperty ("removeOnWindowDeactivation" , true );
1426
1450
MenuScroller .setScrollerFor (boardMenu ).setTopFixedCount (1 );
1427
1451
@@ -1530,12 +1554,7 @@ private JRadioButtonMenuItem createBoardMenusAndCustomMenus(
1530
1554
@ SuppressWarnings ("serial" )
1531
1555
Action action = new AbstractAction (board .getName ()) {
1532
1556
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" ));
1539
1558
}
1540
1559
};
1541
1560
action .putValue ("b" , board );
0 commit comments