@@ -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
@@ -1324,6 +1329,42 @@ public void selectTargetBoard(TargetBoard targetBoard) {
1324
1329
onBoardOrPortChange ();
1325
1330
rebuildImportMenu (Editor .importMenu );
1326
1331
rebuildExamplesMenu (Editor .examplesMenu );
1332
+ try {
1333
+ rebuildRecentBoardsMenu ();
1334
+ } catch (Exception e ) {
1335
+ // TODO Auto-generated catch block
1336
+ e .printStackTrace ();
1337
+ }
1338
+ }
1339
+
1340
+ public void rebuildRecentBoardsMenu () throws Exception {
1341
+
1342
+ Enumeration <AbstractButton > btns = recentBoardsButtonGroup .getElements ();
1343
+ while (btns .hasMoreElements ()) {
1344
+ AbstractButton x = btns .nextElement ();
1345
+ if (x .isSelected ()) {
1346
+ return ;
1347
+ }
1348
+ }
1349
+ btns = recentBoardsButtonGroup .getElements ();
1350
+ while (btns .hasMoreElements ()) {
1351
+ AbstractButton x = btns .nextElement ();
1352
+ boardMenu .remove (x );
1353
+ }
1354
+ int index = 0 ;
1355
+ for (TargetBoard board : BaseNoGui .getRecentlyUsedBoards ()) {
1356
+ JMenuItem item = createBoardMenusAndCustomMenus (boardsCustomMenus , menuItemsToClickAfterStartup ,
1357
+ buttonGroupsMap ,
1358
+ board , board .getContainerPlatform (), board .getContainerPlatform ().getContainerPackage ());
1359
+ boardMenu .insert (item , 3 );
1360
+ item .setAccelerator (KeyStroke .getKeyStroke ('0' + index ,
1361
+ Toolkit .getDefaultToolkit ().getMenuShortcutKeyMask () |
1362
+ ActionEvent .SHIFT_MASK ));
1363
+ recentBoardsButtonGroup .add (item );
1364
+ boardsButtonGroup .add (item );
1365
+ index ++;
1366
+ }
1367
+ boardMenuScroller .setTopFixedCount (3 + index );
1327
1368
}
1328
1369
1329
1370
public synchronized void onBoardOrPortChange () {
@@ -1421,7 +1462,8 @@ public void rebuildBoardsMenu() throws Exception {
1421
1462
// The first custom menu is the "Board" selection submenu
1422
1463
boardMenu = new JMenu (tr ("Board" ));
1423
1464
boardMenu .putClientProperty ("removeOnWindowDeactivation" , true );
1424
- MenuScroller .setScrollerFor (boardMenu ).setTopFixedCount (1 );
1465
+ boardMenuScroller = MenuScroller .setScrollerFor (boardMenu );
1466
+ boardMenuScroller .setTopFixedCount (1 );
1425
1467
1426
1468
boardMenu .add (new JMenuItem (new AbstractAction (tr ("Boards Manager..." )) {
1427
1469
public void actionPerformed (ActionEvent actionevent ) {
@@ -1461,21 +1503,26 @@ public void actionPerformed(ActionEvent actionevent) {
1461
1503
boardsCustomMenus .add (customMenu );
1462
1504
}
1463
1505
1464
- List <JMenuItem > menuItemsToClickAfterStartup = new LinkedList <>();
1506
+ menuItemsToClickAfterStartup = new LinkedList <>();
1507
+ boardsButtonGroup = new ButtonGroup ();
1508
+ recentBoardsButtonGroup = new ButtonGroup ();
1509
+ buttonGroupsMap = new HashMap <>();
1465
1510
1466
- ButtonGroup boardsButtonGroup = new ButtonGroup ();
1467
- Map <String , ButtonGroup > buttonGroupsMap = new HashMap <>();
1511
+ if (BaseNoGui .getRecentlyUsedBoards () != null ) {
1512
+ JMenuItem recentLabel = new JMenuItem (tr ("Recently used boards" ));
1513
+ recentLabel .setEnabled (false );
1514
+ boardMenu .add (recentLabel );
1515
+ rebuildRecentBoardsMenu ();
1516
+ //rebuildRecentBoardsMenu(null);
1517
+ }
1468
1518
1469
1519
// Cycle through all packages
1470
- boolean first = true ;
1471
1520
for (TargetPackage targetPackage : BaseNoGui .packages .values ()) {
1472
1521
// For every package cycle through all platform
1473
1522
for (TargetPlatform targetPlatform : targetPackage .platforms ()) {
1474
1523
1475
1524
// Add a separator from the previous platform
1476
- if (!first )
1477
- boardMenu .add (new JSeparator ());
1478
- first = false ;
1525
+ boardMenu .add (new JSeparator ());
1479
1526
1480
1527
// Add a title for each platform
1481
1528
String platformLabel = targetPlatform .getPreferences ().get ("name" );
@@ -1555,6 +1602,9 @@ public void run() {
1555
1602
for (final String menuId : customMenus .keySet ()) {
1556
1603
String title = customMenus .get (menuId );
1557
1604
JMenu menu = getBoardCustomMenu (tr (title ));
1605
+ if (menu == null ) {
1606
+ continue ;
1607
+ }
1558
1608
1559
1609
if (board .hasMenu (menuId )) {
1560
1610
PreferencesMap boardCustomMenu = board .getMenuLabels (menuId );
@@ -1617,13 +1667,13 @@ private static boolean ifThereAreVisibleItemsOn(JMenu menu) {
1617
1667
return false ;
1618
1668
}
1619
1669
1620
- private JMenu getBoardCustomMenu (String label ) throws Exception {
1670
+ private JMenu getBoardCustomMenu (String label ) {
1621
1671
for (JMenu menu : boardsCustomMenus ) {
1622
1672
if (label .equals (menu .getText ())) {
1623
1673
return menu ;
1624
1674
}
1625
1675
}
1626
- throw new Exception ( "Custom menu not found!" ) ;
1676
+ return null ;
1627
1677
}
1628
1678
1629
1679
public List <JMenuItem > getProgrammerMenus () {
0 commit comments