Skip to content

Commit a0e6949

Browse files
committed
Add mnemonics to Tools -> Boards and Ports
1 parent 43b0818 commit a0e6949

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

app/src/processing/app/Base.java

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

app/src/processing/app/Editor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ private JMenu buildToolsMenu() {
741741

742742
if (portMenu == null)
743743
portMenu = new JMenu(tr("Port"));
744+
portMenu.setMnemonic('P');
744745
populatePortMenu();
745746
toolsMenu.add(portMenu);
746747
MenuScroller.setScrollerFor(portMenu);
@@ -1109,6 +1110,7 @@ private void populatePortMenu() {
11091110

11101111
String lastProtocol = "";
11111112
String lastProtocolLabel = "";
1113+
int i=0;
11121114
for (BoardPort port : ports) {
11131115
if (!port.getProtocol().equals(lastProtocol) || !port.getProtocolLabel().equals(lastProtocolLabel)) {
11141116
if (!lastProtocol.isEmpty()) {
@@ -1124,13 +1126,14 @@ private void populatePortMenu() {
11241126

11251127
BoardPortJCheckBoxMenuItem item = new BoardPortJCheckBoxMenuItem(port);
11261128
item.setSelected(address.equals(selectedPort));
1129+
Base.setMenuItemMnemonicNum10(item, i, false);
1130+
i++;
11271131
portMenu.add(item);
11281132
}
11291133

11301134
portMenu.setEnabled(portMenu.getMenuComponentCount() > 0);
11311135
}
11321136

1133-
11341137
private JMenu buildHelpMenu() {
11351138
JMenu menu = new JMenu(tr("Help"));
11361139
menu.setMnemonic(KeyEvent.VK_H);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy