Skip to content

Commit a9631da

Browse files
Store original board items, not clones and use the original action
This simplifies the creation of the original board items by just storing the original and leaving the creation of new actions and items for the recent boards menu for later, for only the items actually present there. Also, it turns out that cloning the action is not actually needed, you can just attach the original action to the recent board menu item as well (this skips setting the clicked item as selected, but it works because the original action changes the current board, which regenerates the recent board menu anyway).
1 parent 2acc1f7 commit a9631da

File tree

1 file changed

+9
-23
lines changed

1 file changed

+9
-23
lines changed

Diff for: app/src/processing/app/Base.java

+9-23
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public class Base {
124124

125125
// these variables help rebuild the "recently used boards"
126126
// menu on board selection
127-
private HashMap<String, JRadioButtonMenuItem> recentBoardItems;
127+
private HashMap<String, JRadioButtonMenuItem> boardItems;
128128
private List<JRadioButtonMenuItem> recentBoardsToClear = new LinkedList<>();;
129129
private JMenu boardMenu;
130130
private int recentBoardsJMenuIndex;
@@ -1473,7 +1473,7 @@ protected void onIndexesUpdated() throws Exception {
14731473

14741474
public void rebuildBoardsMenu() throws Exception {
14751475
boardsCustomMenus = new LinkedList<>();
1476-
recentBoardItems = new HashMap<String, JRadioButtonMenuItem>();
1476+
boardItems = new HashMap<String, JRadioButtonMenuItem>();
14771477

14781478
// The first custom menu is the "Board" selection submenu
14791479
boardMenu = new JMenu(tr("Board"));
@@ -1625,10 +1625,12 @@ private void rebuildRecentBoardsList() throws Exception {
16251625
}
16261626
recentBoardsToClear.clear();
16271627
for (String boardId : recentBoardIds) {
1628-
JRadioButtonMenuItem addItem = recentBoardItems.get(boardId);
1629-
boardMenu.add(addItem, recentBoardsJMenuIndex+idxAdv);
1630-
recentBoardsToClear.add(addItem);
1631-
addItem.setSelected(boardId.equals(currentBoard));
1628+
JRadioButtonMenuItem originalItem = boardItems.get(boardId);
1629+
JRadioButtonMenuItem recentItem = new JRadioButtonMenuItem(originalItem.getAction());
1630+
1631+
boardMenu.add(recentItem, recentBoardsJMenuIndex+idxAdv);
1632+
recentBoardsToClear.add(recentItem);
1633+
recentItem.setSelected(boardId.equals(currentBoard));
16321634
idxAdv++;
16331635
}
16341636
}
@@ -1662,23 +1664,7 @@ public void actionPerformed(ActionEvent actionevent) {
16621664
action.putValue("b", board);
16631665

16641666
JRadioButtonMenuItem item = new JRadioButtonMenuItem(action);
1665-
1666-
// create an action for the "recent boards" copy of this menu item
1667-
// which clicks the original menu item
1668-
Action actionClone = new AbstractAction(board.getName()) {
1669-
public void actionPerformed(ActionEvent actionevent) {
1670-
item.setSelected(true);
1671-
item.getAction().actionPerformed(new ActionEvent(this, -1, ""));
1672-
}
1673-
};
1674-
1675-
// No need to hog memory if recent boards feature is turned off
1676-
if (PreferencesData.getInteger("recent.num_boards") > 0) {
1677-
// create a menu item for the "recent boards" menu
1678-
JRadioButtonMenuItem itemClone = new JRadioButtonMenuItem(actionClone);
1679-
// populate list of menuitem copies
1680-
recentBoardItems.put(boardId, itemClone);
1681-
}
1667+
boardItems.put(boardId, item);
16821668

16831669
if (selBoard.equals(boardId) && selPackage.equals(packageName)
16841670
&& selPlatform.equals(platformName)) {

0 commit comments

Comments
 (0)