@@ -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)
@@ -1332,6 +1334,28 @@ public void rebuildExamplesMenu(JMenu menu) {
1332
1334
private static String priorPlatformFolder ;
1333
1335
private static boolean newLibraryImported ;
1334
1336
1337
+ public void selectTargetBoard (TargetBoard targetBoard ) {
1338
+ for (int i = 0 ; i < boardMenu .getItemCount (); i ++) {
1339
+ JMenuItem menuItem = boardMenu .getItem (i );
1340
+ if (!(menuItem instanceof JRadioButtonMenuItem )) {
1341
+ continue ;
1342
+ }
1343
+
1344
+ JRadioButtonMenuItem radioButtonMenuItem = ((JRadioButtonMenuItem ) menuItem );
1345
+ if (targetBoard .getName ().equals (radioButtonMenuItem .getText ())) {
1346
+ radioButtonMenuItem .setSelected (true );
1347
+ break ;
1348
+ }
1349
+ }
1350
+
1351
+ BaseNoGui .selectBoard (targetBoard );
1352
+ filterVisibilityOfSubsequentBoardMenus (boardsCustomMenus , targetBoard , 1 );
1353
+
1354
+ onBoardOrPortChange ();
1355
+ rebuildImportMenu (Editor .importMenu );
1356
+ rebuildExamplesMenu (Editor .examplesMenu );
1357
+ }
1358
+
1335
1359
public void onBoardOrPortChange () {
1336
1360
BaseNoGui .onBoardOrPortChange ();
1337
1361
@@ -1425,7 +1449,7 @@ public void rebuildBoardsMenu() throws Exception {
1425
1449
boardsCustomMenus = new LinkedList <>();
1426
1450
1427
1451
// The first custom menu is the "Board" selection submenu
1428
- JMenu boardMenu = new JMenu (tr ("Board" ));
1452
+ boardMenu = new JMenu (tr ("Board" ));
1429
1453
boardMenu .putClientProperty ("removeOnWindowDeactivation" , true );
1430
1454
MenuScroller .setScrollerFor (boardMenu ).setTopFixedCount (1 );
1431
1455
@@ -1534,12 +1558,7 @@ private JRadioButtonMenuItem createBoardMenusAndCustomMenus(
1534
1558
@ SuppressWarnings ("serial" )
1535
1559
Action action = new AbstractAction (board .getName ()) {
1536
1560
public void actionPerformed (ActionEvent actionevent ) {
1537
- BaseNoGui .selectBoard ((TargetBoard ) getValue ("b" ));
1538
- filterVisibilityOfSubsequentBoardMenus (boardsCustomMenus , (TargetBoard ) getValue ("b" ), 1 );
1539
-
1540
- onBoardOrPortChange ();
1541
- rebuildImportMenu (Editor .importMenu );
1542
- rebuildExamplesMenu (Editor .examplesMenu );
1561
+ selectTargetBoard ((TargetBoard ) getValue ("b" ));
1543
1562
}
1544
1563
};
1545
1564
action .putValue ("b" , board );
0 commit comments