@@ -1424,15 +1424,45 @@ protected void onIndexesUpdated() throws Exception {
14241424 onBoardOrPortChange ();
14251425 }
14261426
1427+ public static void setMenuItemMnemonicAlphaNum (JMenuItem item , int i , Boolean repeat ) {
1428+ char c ;
1429+ // JMenu hotkeys treats lower and upper case the same,
1430+ // so we only do lower, then digits, for visibility
1431+ if (i >=26 +10 ) {
1432+ if (!repeat ) return ;
1433+ i = i %(26 +10 );
1434+ }
1435+ if (i >=0 && i <26 ) {
1436+ c = (char )(i +'a' );
1437+ } else if (i >=26 && i <(26 +10 )) {
1438+ c = (char )(i -26 +'0' );
1439+ } else {
1440+ return ;
1441+ }
1442+ item .setText (c + ". " + item .getText ());
1443+ item .setMnemonic (c );
1444+ }
1445+
1446+ public static void setMenuItemMnemonicNum10 (JMenuItem item , int i , Boolean repeat ) {
1447+ char c ;
1448+ if (i >=0 && (repeat || i <10 )) {
1449+ c = (char )((i %10 )+'0' );
1450+ item .setText (c + ". " + item .getText ());
1451+ item .setMnemonic (c );
1452+ }
1453+ }
1454+
1455+
14271456 public void rebuildBoardsMenu () throws Exception {
14281457 boardsCustomMenus = new LinkedList <>();
14291458
14301459 // The first custom menu is the "Board" selection submenu
14311460 JMenu boardMenu = new JMenu (tr ("Board" ));
1461+ boardMenu .setMnemonic ('B' );
14321462 boardMenu .putClientProperty ("removeOnWindowDeactivation" , true );
14331463 MenuScroller .setScrollerFor (boardMenu ).setTopFixedCount (1 );
14341464
1435- boardMenu . add ( new JMenuItem (new AbstractAction (tr ("Boards Manager..." )) {
1465+ JMenuItem menuItem = new JMenuItem (new AbstractAction (tr ("Boards Manager..." )) {
14361466 public void actionPerformed (ActionEvent actionevent ) {
14371467 String filterText = "" ;
14381468 String dropdownItem = "" ;
@@ -1448,7 +1478,9 @@ public void actionPerformed(ActionEvent actionevent) {
14481478 e .printStackTrace ();
14491479 }
14501480 }
1451- }));
1481+ });
1482+ menuItem .setMnemonic ('M' );
1483+ boardMenu .add (menuItem );
14521484 boardsCustomMenus .add (boardMenu );
14531485
14541486 // If there are no platforms installed we are done
@@ -1497,12 +1529,15 @@ public void actionPerformed(ActionEvent actionevent) {
14971529 platformMenus .add (platformBoardsMenu );
14981530
14991531 // Cycle through all boards of this platform
1532+ int i =0 ;
15001533 for (TargetBoard board : targetPlatform .getBoards ().values ()) {
15011534 if (board .getPreferences ().get ("hide" ) != null )
15021535 continue ;
15031536 JMenuItem item = createBoardMenusAndCustomMenus (boardsCustomMenus , menuItemsToClickAfterStartup ,
15041537 buttonGroupsMap ,
15051538 board , targetPlatform , targetPackage );
1539+ setMenuItemMnemonicAlphaNum (item , i , true );
1540+ i ++;
15061541 platformBoardsMenu .add (item );
15071542 boardsButtonGroup .add (item );
15081543 }
@@ -1515,16 +1550,26 @@ public void actionPerformed(ActionEvent actionevent) {
15151550 if (platformMenus .size () == 1 ) {
15161551 // When just one platform exists, add the board items directly,
15171552 // rather than using a submenu
1553+ int i =0 ;
15181554 for (Component boardItem : platformMenus .get (0 ).getMenuComponents ()) {
1555+ // For mnemonics, need to test single-platform setups:
1556+ // Eg. setMenuItemMnemonicAlphaNum((JMenuItem)boardItem, i, true); i++;
15191557 boardMenu .add (boardItem );
15201558 if (firstBoardItem == null )
15211559 firstBoardItem = (JMenuItem )boardItem ;
15221560 }
15231561 } else {
15241562 // For multiple platforms, use submenus
1563+ // int i=0;
1564+ String keys ="" ;
1565+ int i =0 ;
15251566 for (JMenu platformMenu : platformMenus ) {
15261567 if (firstBoardItem == null && platformMenu .getItemCount () > 0 )
15271568 firstBoardItem = platformMenu .getItem (0 );
1569+ // Ideally we'd exclude the manually-assigned "Board (M)anager" key
1570+ // when assigning a mnemonic to this item
1571+ setMenuItemMnemonicAlphaNum (platformMenu , i , true );
1572+ i ++;
15281573 boardMenu .add (platformMenu );
15291574 }
15301575 }
0 commit comments