@@ -117,6 +117,11 @@ public class Base {
117
117
Editor activeEditor ;
118
118
119
119
private static JMenu boardMenu ;
120
+ private static ButtonGroup boardsButtonGroup ;
121
+ private static ButtonGroup recentBoardsButtonGroup ;
122
+ private static Map <String , ButtonGroup > buttonGroupsMap ;
123
+ private static List <JMenuItem > menuItemsToClickAfterStartup ;
124
+ private static MenuScroller boardMenuScroller ;
120
125
121
126
// these menus are shared so that the board and serial port selections
122
127
// are the same for all windows (since the board and serial port that are
@@ -1350,6 +1355,41 @@ public void selectTargetBoard(TargetBoard targetBoard) {
1350
1355
onBoardOrPortChange ();
1351
1356
rebuildImportMenu (Editor .importMenu );
1352
1357
rebuildExamplesMenu (Editor .examplesMenu );
1358
+ try {
1359
+ rebuildRecentBoardsMenu ();
1360
+ } catch (Exception e ) {
1361
+ // fail silently
1362
+ }
1363
+ }
1364
+
1365
+ public void rebuildRecentBoardsMenu () throws Exception {
1366
+
1367
+ Enumeration <AbstractButton > btns = recentBoardsButtonGroup .getElements ();
1368
+ while (btns .hasMoreElements ()) {
1369
+ AbstractButton x = btns .nextElement ();
1370
+ if (x .isSelected ()) {
1371
+ return ;
1372
+ }
1373
+ }
1374
+ btns = recentBoardsButtonGroup .getElements ();
1375
+ while (btns .hasMoreElements ()) {
1376
+ AbstractButton x = btns .nextElement ();
1377
+ boardMenu .remove (x );
1378
+ }
1379
+ int index = 0 ;
1380
+ for (TargetBoard board : BaseNoGui .getRecentlyUsedBoards ()) {
1381
+ JMenuItem item = createBoardMenusAndCustomMenus (boardsCustomMenus , menuItemsToClickAfterStartup ,
1382
+ buttonGroupsMap ,
1383
+ board , board .getContainerPlatform (), board .getContainerPlatform ().getContainerPackage ());
1384
+ boardMenu .insert (item , 3 );
1385
+ item .setAccelerator (KeyStroke .getKeyStroke ('0' + index ,
1386
+ Toolkit .getDefaultToolkit ().getMenuShortcutKeyMask () |
1387
+ ActionEvent .SHIFT_MASK ));
1388
+ recentBoardsButtonGroup .add (item );
1389
+ boardsButtonGroup .add (item );
1390
+ index ++;
1391
+ }
1392
+ boardMenuScroller .setTopFixedCount (3 + index );
1353
1393
}
1354
1394
1355
1395
public void onBoardOrPortChange () {
@@ -1447,7 +1487,8 @@ public void rebuildBoardsMenu() throws Exception {
1447
1487
// The first custom menu is the "Board" selection submenu
1448
1488
boardMenu = new JMenu (tr ("Board" ));
1449
1489
boardMenu .putClientProperty ("removeOnWindowDeactivation" , true );
1450
- MenuScroller .setScrollerFor (boardMenu ).setTopFixedCount (1 );
1490
+ boardMenuScroller = MenuScroller .setScrollerFor (boardMenu );
1491
+ boardMenuScroller .setTopFixedCount (1 );
1451
1492
1452
1493
boardMenu .add (new JMenuItem (new AbstractAction (tr ("Boards Manager..." )) {
1453
1494
public void actionPerformed (ActionEvent actionevent ) {
@@ -1486,21 +1527,26 @@ public void actionPerformed(ActionEvent actionevent) {
1486
1527
}
1487
1528
}
1488
1529
1489
- List <JMenuItem > menuItemsToClickAfterStartup = new LinkedList <>();
1530
+ menuItemsToClickAfterStartup = new LinkedList <>();
1531
+ boardsButtonGroup = new ButtonGroup ();
1532
+ recentBoardsButtonGroup = new ButtonGroup ();
1533
+ buttonGroupsMap = new HashMap <>();
1490
1534
1491
- ButtonGroup boardsButtonGroup = new ButtonGroup ();
1492
- Map <String , ButtonGroup > buttonGroupsMap = new HashMap <>();
1535
+ if (BaseNoGui .getRecentlyUsedBoards () != null ) {
1536
+ JMenuItem recentLabel = new JMenuItem (tr ("Recently used boards" ));
1537
+ recentLabel .setEnabled (false );
1538
+ boardMenu .add (recentLabel );
1539
+ rebuildRecentBoardsMenu ();
1540
+ //rebuildRecentBoardsMenu(null);
1541
+ }
1493
1542
1494
1543
// Cycle through all packages
1495
- boolean first = true ;
1496
1544
for (TargetPackage targetPackage : BaseNoGui .packages .values ()) {
1497
1545
// For every package cycle through all platform
1498
1546
for (TargetPlatform targetPlatform : targetPackage .platforms ()) {
1499
1547
1500
1548
// Add a separator from the previous platform
1501
- if (!first )
1502
- boardMenu .add (new JSeparator ());
1503
- first = false ;
1549
+ boardMenu .add (new JSeparator ());
1504
1550
1505
1551
// Add a title for each platform
1506
1552
String platformLabel = targetPlatform .getPreferences ().get ("name" );
@@ -1570,6 +1616,9 @@ public void actionPerformed(ActionEvent actionevent) {
1570
1616
for (final String menuId : customMenus .keySet ()) {
1571
1617
String title = customMenus .get (menuId );
1572
1618
JMenu menu = getBoardCustomMenu (tr (title ), getPlatformUniqueId (targetPlatform ));
1619
+ if (menu == null ) {
1620
+ continue ;
1621
+ }
1573
1622
1574
1623
if (board .hasMenu (menuId )) {
1575
1624
PreferencesMap boardCustomMenu = board .getMenuLabels (menuId );
@@ -1645,7 +1694,7 @@ private JMenu getBoardCustomMenu(String label, String platformUniqueId) throws E
1645
1694
return menu ;
1646
1695
}
1647
1696
}
1648
- throw new Exception ( "Custom menu not found!" ) ;
1697
+ return null ;
1649
1698
}
1650
1699
1651
1700
public List <JMenuItem > getProgrammerMenus () {
0 commit comments