Skip to content

Commit

Permalink
Add mnemonics to Boards menu: a-z,A-Z,0-9
Browse files Browse the repository at this point in the history
  • Loading branch information
jaggzh committed Jun 9, 2022
1 parent 43b0818 commit 0a08cf2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
27 changes: 25 additions & 2 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -1424,15 +1424,31 @@ protected void onIndexesUpdated() throws Exception {
onBoardOrPortChange();
}

public void setMenuItemIncrementalMnemonic(JMenuItem item, int i) {
char c;
if (i>=0 && i<26) {
c = (char)(i+'a');
} else if (i>=26 && i<26*2) {
c = (char)(i-26+'A');
} else if (i>=26*2 && i<26*2 + 10) {
c = (char)(i-26*2+'0');
} else {
return;
}
item.setText(c + ". " + item.getText());
item.setMnemonic(c);
}

public void rebuildBoardsMenu() throws Exception {
boardsCustomMenus = new LinkedList<>();

// The first custom menu is the "Board" selection submenu
JMenu boardMenu = new JMenu(tr("Board"));
boardMenu.setMnemonic('B');
boardMenu.putClientProperty("removeOnWindowDeactivation", true);
MenuScroller.setScrollerFor(boardMenu).setTopFixedCount(1);

boardMenu.add(new JMenuItem(new AbstractAction(tr("Boards Manager...")) {
JMenuItem menuItem = new JMenuItem(new AbstractAction(tr("Boards Manager...")) {
public void actionPerformed(ActionEvent actionevent) {
String filterText = "";
String dropdownItem = "";
Expand All @@ -1448,7 +1464,9 @@ public void actionPerformed(ActionEvent actionevent) {
e.printStackTrace();
}
}
}));
});
menuItem.setMnemonic('M');
boardMenu.add(menuItem);
boardsCustomMenus.add(boardMenu);

// If there are no platforms installed we are done
Expand Down Expand Up @@ -1522,9 +1540,14 @@ public void actionPerformed(ActionEvent actionevent) {
}
} else {
// For multiple platforms, use submenus
// int i=0;
String keys="";
int i=0;
for (JMenu platformMenu : platformMenus) {
if (firstBoardItem == null && platformMenu.getItemCount() > 0)
firstBoardItem = platformMenu.getItem(0);
setMenuItemIncrementalMnemonic(platformMenu, i);
i++;
boardMenu.add(platformMenu);
}
}
Expand Down
1 change: 1 addition & 0 deletions app/src/processing/app/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@ private JMenu buildToolsMenu() {

if (portMenu == null)
portMenu = new JMenu(tr("Port"));
portMenu.setMnemonic('P');
populatePortMenu();
toolsMenu.add(portMenu);
MenuScroller.setScrollerFor(portMenu);
Expand Down

0 comments on commit 0a08cf2

Please sign in to comment.