@@ -118,6 +118,11 @@ public class Base {
118118 Editor activeEditor ;
119119
120120 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 ;
121126
122127 // these menus are shared so that the board and serial port selections
123128 // are the same for all windows (since the board and serial port that are
@@ -1335,6 +1340,41 @@ public void selectTargetBoard(TargetBoard targetBoard) {
13351340 onBoardOrPortChange ();
13361341 rebuildImportMenu (Editor .importMenu );
13371342 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 );
13381378 }
13391379
13401380 public void onBoardOrPortChange () {
@@ -1432,7 +1472,8 @@ public void rebuildBoardsMenu() throws Exception {
14321472 // The first custom menu is the "Board" selection submenu
14331473 boardMenu = new JMenu (tr ("Board" ));
14341474 boardMenu .putClientProperty ("removeOnWindowDeactivation" , true );
1435- MenuScroller .setScrollerFor (boardMenu ).setTopFixedCount (1 );
1475+ boardMenuScroller = MenuScroller .setScrollerFor (boardMenu );
1476+ boardMenuScroller .setTopFixedCount (1 );
14361477
14371478 boardMenu .add (new JMenuItem (new AbstractAction (tr ("Boards Manager..." )) {
14381479 public void actionPerformed (ActionEvent actionevent ) {
@@ -1472,21 +1513,26 @@ public void actionPerformed(ActionEvent actionevent) {
14721513 boardsCustomMenus .add (customMenu );
14731514 }
14741515
1475- List <JMenuItem > menuItemsToClickAfterStartup = new LinkedList <>();
1516+ menuItemsToClickAfterStartup = new LinkedList <>();
1517+ boardsButtonGroup = new ButtonGroup ();
1518+ recentBoardsButtonGroup = new ButtonGroup ();
1519+ buttonGroupsMap = new HashMap <>();
14761520
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+ }
14791528
14801529 // Cycle through all packages
1481- boolean first = true ;
14821530 for (TargetPackage targetPackage : BaseNoGui .packages .values ()) {
14831531 // For every package cycle through all platform
14841532 for (TargetPlatform targetPlatform : targetPackage .platforms ()) {
14851533
14861534 // Add a separator from the previous platform
1487- if (!first )
1488- boardMenu .add (new JSeparator ());
1489- first = false ;
1535+ boardMenu .add (new JSeparator ());
14901536
14911537 // Add a title for each platform
14921538 String platformLabel = targetPlatform .getPreferences ().get ("name" );
@@ -1552,6 +1598,9 @@ public void actionPerformed(ActionEvent actionevent) {
15521598 for (final String menuId : customMenus .keySet ()) {
15531599 String title = customMenus .get (menuId );
15541600 JMenu menu = getBoardCustomMenu (tr (title ));
1601+ if (menu == null ) {
1602+ continue ;
1603+ }
15551604
15561605 if (board .hasMenu (menuId )) {
15571606 PreferencesMap boardCustomMenu = board .getMenuLabels (menuId );
@@ -1614,13 +1663,13 @@ private static boolean ifThereAreVisibleItemsOn(JMenu menu) {
16141663 return false ;
16151664 }
16161665
1617- private JMenu getBoardCustomMenu (String label ) throws Exception {
1666+ private JMenu getBoardCustomMenu (String label ) {
16181667 for (JMenu menu : boardsCustomMenus ) {
16191668 if (label .equals (menu .getText ())) {
16201669 return menu ;
16211670 }
16221671 }
1623- throw new Exception ( "Custom menu not found!" ) ;
1672+ return null ;
16241673 }
16251674
16261675 public List <JMenuItem > getProgrammerMenus () {
0 commit comments