@@ -118,6 +118,11 @@ public class Base {
118
118
Editor activeEditor ;
119
119
120
120
private static JMenu boardMenu ;
121
+ private static ButtonGroup boardsButtonGroup ;
122
+ private static ButtonGroup recentBoardsButtonGroup ;
123
+ private static Map <String , ButtonGroup > buttonGroupsMap ;
124
+ private static List <JMenuItem > menuItemsToClickAfterStartup ;
125
+ private static MenuScroller boardMenuScroller ;
121
126
122
127
// these menus are shared so that the board and serial port selections
123
128
// are the same for all windows (since the board and serial port that are
@@ -1335,6 +1340,41 @@ public void selectTargetBoard(TargetBoard targetBoard) {
1335
1340
onBoardOrPortChange ();
1336
1341
rebuildImportMenu (Editor .importMenu );
1337
1342
rebuildExamplesMenu (Editor .examplesMenu );
1343
+ try {
1344
+ rebuildRecentBoardsMenu ();
1345
+ } catch (Exception e ) {
1346
+ // fail silently
1347
+ }
1348
+ }
1349
+
1350
+ public void rebuildRecentBoardsMenu () throws Exception {
1351
+
1352
+ Enumeration <AbstractButton > btns = recentBoardsButtonGroup .getElements ();
1353
+ while (btns .hasMoreElements ()) {
1354
+ AbstractButton x = btns .nextElement ();
1355
+ if (x .isSelected ()) {
1356
+ return ;
1357
+ }
1358
+ }
1359
+ btns = recentBoardsButtonGroup .getElements ();
1360
+ while (btns .hasMoreElements ()) {
1361
+ AbstractButton x = btns .nextElement ();
1362
+ boardMenu .remove (x );
1363
+ }
1364
+ int index = 0 ;
1365
+ for (TargetBoard board : BaseNoGui .getRecentlyUsedBoards ()) {
1366
+ JMenuItem item = createBoardMenusAndCustomMenus (boardsCustomMenus , menuItemsToClickAfterStartup ,
1367
+ buttonGroupsMap ,
1368
+ board , board .getContainerPlatform (), board .getContainerPlatform ().getContainerPackage ());
1369
+ boardMenu .insert (item , 3 );
1370
+ item .setAccelerator (KeyStroke .getKeyStroke ('0' + index ,
1371
+ Toolkit .getDefaultToolkit ().getMenuShortcutKeyMask () |
1372
+ ActionEvent .SHIFT_MASK ));
1373
+ recentBoardsButtonGroup .add (item );
1374
+ boardsButtonGroup .add (item );
1375
+ index ++;
1376
+ }
1377
+ boardMenuScroller .setTopFixedCount (3 + index );
1338
1378
}
1339
1379
1340
1380
public void onBoardOrPortChange () {
@@ -1432,7 +1472,8 @@ public void rebuildBoardsMenu() throws Exception {
1432
1472
// The first custom menu is the "Board" selection submenu
1433
1473
boardMenu = new JMenu (tr ("Board" ));
1434
1474
boardMenu .putClientProperty ("removeOnWindowDeactivation" , true );
1435
- MenuScroller .setScrollerFor (boardMenu ).setTopFixedCount (1 );
1475
+ boardMenuScroller = MenuScroller .setScrollerFor (boardMenu );
1476
+ boardMenuScroller .setTopFixedCount (1 );
1436
1477
1437
1478
boardMenu .add (new JMenuItem (new AbstractAction (tr ("Boards Manager..." )) {
1438
1479
public void actionPerformed (ActionEvent actionevent ) {
@@ -1472,21 +1513,26 @@ public void actionPerformed(ActionEvent actionevent) {
1472
1513
boardsCustomMenus .add (customMenu );
1473
1514
}
1474
1515
1475
- List <JMenuItem > menuItemsToClickAfterStartup = new LinkedList <>();
1516
+ menuItemsToClickAfterStartup = new LinkedList <>();
1517
+ boardsButtonGroup = new ButtonGroup ();
1518
+ recentBoardsButtonGroup = new ButtonGroup ();
1519
+ buttonGroupsMap = new HashMap <>();
1476
1520
1477
- ButtonGroup boardsButtonGroup = new ButtonGroup ();
1478
- Map <String , ButtonGroup > buttonGroupsMap = new HashMap <>();
1521
+ if (BaseNoGui .getRecentlyUsedBoards () != null ) {
1522
+ JMenuItem recentLabel = new JMenuItem (tr ("Recently used boards" ));
1523
+ recentLabel .setEnabled (false );
1524
+ boardMenu .add (recentLabel );
1525
+ rebuildRecentBoardsMenu ();
1526
+ //rebuildRecentBoardsMenu(null);
1527
+ }
1479
1528
1480
1529
// Cycle through all packages
1481
- boolean first = true ;
1482
1530
for (TargetPackage targetPackage : BaseNoGui .packages .values ()) {
1483
1531
// For every package cycle through all platform
1484
1532
for (TargetPlatform targetPlatform : targetPackage .platforms ()) {
1485
1533
1486
1534
// Add a separator from the previous platform
1487
- if (!first )
1488
- boardMenu .add (new JSeparator ());
1489
- first = false ;
1535
+ boardMenu .add (new JSeparator ());
1490
1536
1491
1537
// Add a title for each platform
1492
1538
String platformLabel = targetPlatform .getPreferences ().get ("name" );
@@ -1552,6 +1598,9 @@ public void actionPerformed(ActionEvent actionevent) {
1552
1598
for (final String menuId : customMenus .keySet ()) {
1553
1599
String title = customMenus .get (menuId );
1554
1600
JMenu menu = getBoardCustomMenu (tr (title ));
1601
+ if (menu == null ) {
1602
+ continue ;
1603
+ }
1555
1604
1556
1605
if (board .hasMenu (menuId )) {
1557
1606
PreferencesMap boardCustomMenu = board .getMenuLabels (menuId );
@@ -1614,13 +1663,13 @@ private static boolean ifThereAreVisibleItemsOn(JMenu menu) {
1614
1663
return false ;
1615
1664
}
1616
1665
1617
- private JMenu getBoardCustomMenu (String label ) throws Exception {
1666
+ private JMenu getBoardCustomMenu (String label ) {
1618
1667
for (JMenu menu : boardsCustomMenus ) {
1619
1668
if (label .equals (menu .getText ())) {
1620
1669
return menu ;
1621
1670
}
1622
1671
}
1623
- throw new Exception ( "Custom menu not found!" ) ;
1672
+ return null ;
1624
1673
}
1625
1674
1626
1675
public List <JMenuItem > getProgrammerMenus () {
0 commit comments