@@ -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
@@ -1324,6 +1329,42 @@ public void selectTargetBoard(TargetBoard targetBoard) {
13241329 onBoardOrPortChange ();
13251330 rebuildImportMenu (Editor .importMenu );
13261331 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 );
13271368 }
13281369
13291370 public synchronized void onBoardOrPortChange () {
@@ -1421,7 +1462,8 @@ public void rebuildBoardsMenu() throws Exception {
14211462 // The first custom menu is the "Board" selection submenu
14221463 boardMenu = new JMenu (tr ("Board" ));
14231464 boardMenu .putClientProperty ("removeOnWindowDeactivation" , true );
1424- MenuScroller .setScrollerFor (boardMenu ).setTopFixedCount (1 );
1465+ boardMenuScroller = MenuScroller .setScrollerFor (boardMenu );
1466+ boardMenuScroller .setTopFixedCount (1 );
14251467
14261468 boardMenu .add (new JMenuItem (new AbstractAction (tr ("Boards Manager..." )) {
14271469 public void actionPerformed (ActionEvent actionevent ) {
@@ -1461,21 +1503,26 @@ public void actionPerformed(ActionEvent actionevent) {
14611503 boardsCustomMenus .add (customMenu );
14621504 }
14631505
1464- List <JMenuItem > menuItemsToClickAfterStartup = new LinkedList <>();
1506+ menuItemsToClickAfterStartup = new LinkedList <>();
1507+ boardsButtonGroup = new ButtonGroup ();
1508+ recentBoardsButtonGroup = new ButtonGroup ();
1509+ buttonGroupsMap = new HashMap <>();
14651510
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+ }
14681518
14691519 // Cycle through all packages
1470- boolean first = true ;
14711520 for (TargetPackage targetPackage : BaseNoGui .packages .values ()) {
14721521 // For every package cycle through all platform
14731522 for (TargetPlatform targetPlatform : targetPackage .platforms ()) {
14741523
14751524 // Add a separator from the previous platform
1476- if (!first )
1477- boardMenu .add (new JSeparator ());
1478- first = false ;
1525+ boardMenu .add (new JSeparator ());
14791526
14801527 // Add a title for each platform
14811528 String platformLabel = targetPlatform .getPreferences ().get ("name" );
@@ -1555,6 +1602,9 @@ public void run() {
15551602 for (final String menuId : customMenus .keySet ()) {
15561603 String title = customMenus .get (menuId );
15571604 JMenu menu = getBoardCustomMenu (tr (title ));
1605+ if (menu == null ) {
1606+ continue ;
1607+ }
15581608
15591609 if (board .hasMenu (menuId )) {
15601610 PreferencesMap boardCustomMenu = board .getMenuLabels (menuId );
@@ -1617,13 +1667,13 @@ private static boolean ifThereAreVisibleItemsOn(JMenu menu) {
16171667 return false ;
16181668 }
16191669
1620- private JMenu getBoardCustomMenu (String label ) throws Exception {
1670+ private JMenu getBoardCustomMenu (String label ) {
16211671 for (JMenu menu : boardsCustomMenus ) {
16221672 if (label .equals (menu .getText ())) {
16231673 return menu ;
16241674 }
16251675 }
1626- throw new Exception ( "Custom menu not found!" ) ;
1676+ return null ;
16271677 }
16281678
16291679 public List <JMenuItem > getProgrammerMenus () {
0 commit comments