@@ -124,8 +124,8 @@ public class Base {
124
124
125
125
// these variables help rebuild the "recently used boards"
126
126
// menu on board selection
127
- private HashMap <String , JMenuItem > recentBoardItems ;
128
- private List <JMenuItem > recentBoardsToClear = new LinkedList <>();;
127
+ private HashMap <String , JRadioButtonMenuItem > recentBoardItems ;
128
+ private List <JRadioButtonMenuItem > recentBoardsToClear = new LinkedList <>();;
129
129
private JMenu boardMenu ;
130
130
private int recentBoardsJMenuIndex ;
131
131
@@ -1376,16 +1376,29 @@ public void onBoardOrPortChange() {
1376
1376
}
1377
1377
}
1378
1378
newRecentBoardIds .add (0 , currentBoard );
1379
- if (newRecentBoardIds .size () == 6 ) {
1380
- newRecentBoardIds .remove (5 );
1379
+
1380
+ int numBoards = 0 ;
1381
+
1382
+ if (PreferencesData .has ("recent.num_boards" )) {
1383
+ numBoards = PreferencesData .getInteger ("recent.num_boards" );
1384
+ }
1385
+
1386
+ while (newRecentBoardIds .size () > numBoards ) {
1387
+ newRecentBoardIds .remove (newRecentBoardIds .size () - 1 );
1381
1388
}
1382
1389
PreferencesData .setCollection ("recent.boards" , newRecentBoardIds );
1383
- try {
1384
- rebuildRecentBoardsList ();
1385
- } catch (Exception e ) {
1386
- //TODO show error
1387
- e .printStackTrace ();
1388
- }
1390
+
1391
+ // If recent.num_boards is 0, interpret this as the feature
1392
+ // being turned off. There's no need to rebuild the menu
1393
+ // because it will be hidden
1394
+ if (numBoards > 0 ) {
1395
+ try {
1396
+ rebuildRecentBoardsList ();
1397
+ } catch (Exception e ) {
1398
+ //TODO show error
1399
+ e .printStackTrace ();
1400
+ }
1401
+ }
1389
1402
1390
1403
// Update editors status bar
1391
1404
for (Editor editor : editors ) {
@@ -1460,7 +1473,7 @@ protected void onIndexesUpdated() throws Exception {
1460
1473
1461
1474
public void rebuildBoardsMenu () throws Exception {
1462
1475
boardsCustomMenus = new LinkedList <>();
1463
- recentBoardItems = new HashMap <String , JMenuItem >();
1476
+ recentBoardItems = new HashMap <String , JRadioButtonMenuItem >();
1464
1477
1465
1478
// The first custom menu is the "Board" selection submenu
1466
1479
boardMenu = new JMenu (tr ("Board" ));
@@ -1487,7 +1500,12 @@ public void actionPerformed(ActionEvent actionevent) {
1487
1500
boardsCustomMenus .add (boardMenu );
1488
1501
1489
1502
// Insert recently used boards menu and remember index for insertion later
1490
- if (PreferencesData .has ("recent.boards" )) {
1503
+ // Check if the field exists, in case preferences got lost
1504
+ if (!PreferencesData .has ("recent.num_boards" )){
1505
+ // (default to 5)
1506
+ PreferencesData .setInteger ("recent.num_boards" , 5 );
1507
+ }
1508
+ if (PreferencesData .getInteger ("recent.num_boards" ) > 0 ) {
1491
1509
// Insert menu label
1492
1510
boardMenu .add (new JSeparator ());
1493
1511
JMenuItem label = new JMenuItem (tr ("Recently Used Boards" ));
@@ -1502,6 +1520,9 @@ public void actionPerformed(ActionEvent actionevent) {
1502
1520
1503
1521
// Separate "Install boards..." command from installed boards
1504
1522
boardMenu .add (new JSeparator ());
1523
+ JMenuItem label = new JMenuItem (tr ("All Installed Boards" ));
1524
+ label .setEnabled (false );
1525
+ boardMenu .add (label );
1505
1526
1506
1527
// Generate custom menus for all platforms
1507
1528
for (TargetPackage targetPackage : BaseNoGui .packages .values ()) {
@@ -1596,16 +1617,18 @@ private String getPlatformUniqueId(TargetPlatform platform) {
1596
1617
// clear the previous menu items from the "recently used boards"
1597
1618
// menu and repopulate with updated items
1598
1619
private void rebuildRecentBoardsList () throws Exception {
1599
- Collection <String > recentBoardIds = new LinkedList <>( );
1600
- recentBoardIds = PreferencesData .getCollection ( "recent.boards " );
1620
+ Collection <String > recentBoardIds = PreferencesData . getCollection ( "recent.boards" );
1621
+ String currentBoard = PreferencesData .get ( "board " );
1601
1622
int idxAdv = 0 ;
1602
- for (JMenuItem itemToClear : recentBoardsToClear ) {
1623
+ for (JRadioButtonMenuItem itemToClear : recentBoardsToClear ) {
1603
1624
boardMenu .remove (itemToClear );
1604
1625
}
1605
1626
recentBoardsToClear .clear ();
1606
1627
for (String boardId : recentBoardIds ) {
1607
- boardMenu .add (recentBoardItems .get (boardId ), recentBoardsJMenuIndex +idxAdv );
1608
- recentBoardsToClear .add (recentBoardItems .get (boardId ));
1628
+ JRadioButtonMenuItem addItem = recentBoardItems .get (boardId );
1629
+ boardMenu .add (addItem , recentBoardsJMenuIndex +idxAdv );
1630
+ recentBoardsToClear .add (addItem );
1631
+ addItem .setSelected (boardId .equals (currentBoard ));
1609
1632
idxAdv ++;
1610
1633
}
1611
1634
}
@@ -1649,11 +1672,13 @@ public void actionPerformed(ActionEvent actionevent) {
1649
1672
}
1650
1673
};
1651
1674
1652
- // create a menu item for the "recent boards" menu
1653
- JMenuItem itemClone = new JMenuItem (actionClone );
1654
-
1655
- // populate list of menuitem copies
1656
- recentBoardItems .put (boardId , itemClone );
1675
+ // No need to hog memory if recent boards feature is turned off
1676
+ if (PreferencesData .getInteger ("recent.num_boards" ) > 0 ) {
1677
+ // create a menu item for the "recent boards" menu
1678
+ JRadioButtonMenuItem itemClone = new JRadioButtonMenuItem (actionClone );
1679
+ // populate list of menuitem copies
1680
+ recentBoardItems .put (boardId , itemClone );
1681
+ }
1657
1682
1658
1683
if (selBoard .equals (boardId ) && selPackage .equals (packageName )
1659
1684
&& selPlatform .equals (platformName )) {
0 commit comments