@@ -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)
@@ -1329,6 +1331,28 @@ public void rebuildExamplesMenu(JMenu menu) {
1329
1331
private static String priorPlatformFolder ;
1330
1332
private static boolean newLibraryImported ;
1331
1333
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
+
1332
1356
public void onBoardOrPortChange () {
1333
1357
BaseNoGui .onBoardOrPortChange ();
1334
1358
@@ -1422,7 +1446,7 @@ public void rebuildBoardsMenu() throws Exception {
1422
1446
boardsCustomMenus = new LinkedList <>();
1423
1447
1424
1448
// The first custom menu is the "Board" selection submenu
1425
- JMenu boardMenu = new JMenu (tr ("Board" ));
1449
+ boardMenu = new JMenu (tr ("Board" ));
1426
1450
boardMenu .putClientProperty ("removeOnWindowDeactivation" , true );
1427
1451
MenuScroller .setScrollerFor (boardMenu ).setTopFixedCount (1 );
1428
1452
@@ -1531,12 +1555,7 @@ private JRadioButtonMenuItem createBoardMenusAndCustomMenus(
1531
1555
@ SuppressWarnings ("serial" )
1532
1556
Action action = new AbstractAction (board .getName ()) {
1533
1557
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" ));
1540
1559
}
1541
1560
};
1542
1561
action .putValue ("b" , board );
0 commit comments