@@ -122,6 +122,13 @@ public class Base {
122
122
private List <JMenu > boardsCustomMenus ;
123
123
private List <JMenuItem > programmerMenus ;
124
124
125
+ // these variables help rebuild the "recently used boards"
126
+ // menu on board selection
127
+ private HashMap <String , JMenuItem > recentBoardItems ;
128
+ private List <JMenuItem > recentBoardsToClear = new LinkedList <>();;
129
+ private JMenu boardMenu ;
130
+ private int recentBoardsJMenuIndex ;
131
+
125
132
private PdeKeywords pdeKeywords ;
126
133
private final List <JMenuItem > recentSketchesMenuItems = new LinkedList <>();
127
134
@@ -1360,6 +1367,26 @@ public void onBoardOrPortChange() {
1360
1367
}
1361
1368
}
1362
1369
1370
+ // Update recent boards list in preferences
1371
+ List <String > newRecentBoardIds = new ArrayList <String >();
1372
+ String currentBoard = PreferencesData .get ("board" );
1373
+ for (String recentBoard : PreferencesData .getCollection ("recent.boards" )){
1374
+ if (!recentBoard .equals (currentBoard )) {
1375
+ newRecentBoardIds .add (recentBoard );
1376
+ }
1377
+ }
1378
+ newRecentBoardIds .add (0 , currentBoard );
1379
+ if (newRecentBoardIds .size () == 6 ) {
1380
+ newRecentBoardIds .remove (5 );
1381
+ }
1382
+ PreferencesData .setCollection ("recent.boards" , newRecentBoardIds );
1383
+ try {
1384
+ rebuildRecentBoardsList ();
1385
+ } catch (Exception e ) {
1386
+ //TODO show error
1387
+ e .printStackTrace ();
1388
+ }
1389
+
1363
1390
// Update editors status bar
1364
1391
for (Editor editor : editors ) {
1365
1392
editor .onBoardOrPortChange ();
@@ -1433,9 +1460,10 @@ protected void onIndexesUpdated() throws Exception {
1433
1460
1434
1461
public void rebuildBoardsMenu () throws Exception {
1435
1462
boardsCustomMenus = new LinkedList <>();
1463
+ recentBoardItems = new HashMap <String , JMenuItem >();
1436
1464
1437
1465
// The first custom menu is the "Board" selection submenu
1438
- JMenu boardMenu = new JMenu (tr ("Board" ));
1466
+ boardMenu = new JMenu (tr ("Board" ));
1439
1467
boardMenu .putClientProperty ("removeOnWindowDeactivation" , true );
1440
1468
MenuScroller .setScrollerFor (boardMenu ).setTopFixedCount (1 );
1441
1469
@@ -1458,6 +1486,16 @@ public void actionPerformed(ActionEvent actionevent) {
1458
1486
}));
1459
1487
boardsCustomMenus .add (boardMenu );
1460
1488
1489
+ // Insert recently used boards menu and remember index for insertion later
1490
+ if (PreferencesData .has ("recent.boards" )) {
1491
+ // Insert menu label
1492
+ boardMenu .add (new JSeparator ());
1493
+ JMenuItem label = new JMenuItem (tr ("Recently Used Boards" ));
1494
+ label .setEnabled (false );
1495
+ boardMenu .add (label );
1496
+ recentBoardsJMenuIndex = boardMenu .getItemCount ();
1497
+ }
1498
+
1461
1499
// If there are no platforms installed we are done
1462
1500
if (BaseNoGui .packages .size () == 0 )
1463
1501
return ;
@@ -1555,6 +1593,23 @@ private String getPlatformUniqueId(TargetPlatform platform) {
1555
1593
return platform .getId () + "_" + platform .getFolder ();
1556
1594
}
1557
1595
1596
+ // clear the previous menu items from the "recently used boards"
1597
+ // menu and repopulate with updated items
1598
+ private void rebuildRecentBoardsList () throws Exception {
1599
+ Collection <String > recentBoardIds = new LinkedList <>();
1600
+ recentBoardIds = PreferencesData .getCollection ("recent.boards" );
1601
+ int idxAdv = 0 ;
1602
+ for (JMenuItem itemToClear : recentBoardsToClear ) {
1603
+ boardMenu .remove (itemToClear );
1604
+ }
1605
+ recentBoardsToClear .clear ();
1606
+ for (String boardId : recentBoardIds ) {
1607
+ boardMenu .add (recentBoardItems .get (boardId ), recentBoardsJMenuIndex +idxAdv );
1608
+ recentBoardsToClear .add (recentBoardItems .get (boardId ));
1609
+ idxAdv ++;
1610
+ }
1611
+ }
1612
+
1558
1613
private JRadioButtonMenuItem createBoardMenusAndCustomMenus (
1559
1614
final List <JMenu > boardsCustomMenus , List <JMenuItem > menuItemsToClickAfterStartup ,
1560
1615
Map <String , ButtonGroup > buttonGroupsMap ,
@@ -1585,6 +1640,21 @@ public void actionPerformed(ActionEvent actionevent) {
1585
1640
1586
1641
JRadioButtonMenuItem item = new JRadioButtonMenuItem (action );
1587
1642
1643
+ // create an action for the "recent boards" copy of this menu item
1644
+ // which clicks the original menu item
1645
+ Action actionClone = new AbstractAction (board .getName ()) {
1646
+ public void actionPerformed (ActionEvent actionevent ) {
1647
+ item .setSelected (true );
1648
+ item .getAction ().actionPerformed (new ActionEvent (this , -1 , "" ));
1649
+ }
1650
+ };
1651
+
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 );
1657
+
1588
1658
if (selBoard .equals (boardId ) && selPackage .equals (packageName )
1589
1659
&& selPlatform .equals (platformName )) {
1590
1660
menuItemsToClickAfterStartup .add (item );
0 commit comments