Skip to content

Annotate custom menu to avoid name clashing #8880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -1436,17 +1436,16 @@ public void actionPerformed(ActionEvent actionevent) {
boardMenu.add(new JSeparator());

// Generate custom menus for all platforms
Set<String> customMenusTitles = new LinkedHashSet<>();
for (TargetPackage targetPackage : BaseNoGui.packages.values()) {
for (TargetPlatform targetPlatform : targetPackage.platforms()) {
customMenusTitles.addAll(targetPlatform.getCustomMenus().values());
for (String customMenuTitle : targetPlatform.getCustomMenus().values()) {
JMenu customMenu = new JMenu(tr(customMenuTitle));
customMenu.putClientProperty("platform", getPlatformUniqueId(targetPlatform));
customMenu.putClientProperty("removeOnWindowDeactivation", true);
boardsCustomMenus.add(customMenu);
}
}
}
for (String customMenuTitle : customMenusTitles) {
JMenu customMenu = new JMenu(tr(customMenuTitle));
customMenu.putClientProperty("removeOnWindowDeactivation", true);
boardsCustomMenus.add(customMenu);
}

List<JMenuItem> menuItemsToClickAfterStartup = new LinkedList<>();

Expand Down Expand Up @@ -1495,6 +1494,10 @@ public void actionPerformed(ActionEvent actionevent) {
}
}

private String getPlatformUniqueId(TargetPlatform platform) {
return platform.getId() + "_" + platform.getFolder();
}

private JRadioButtonMenuItem createBoardMenusAndCustomMenus(
final List<JMenu> boardsCustomMenus, List<JMenuItem> menuItemsToClickAfterStartup,
Map<String, ButtonGroup> buttonGroupsMap,
Expand Down Expand Up @@ -1532,19 +1535,24 @@ public void actionPerformed(ActionEvent actionevent) {
PreferencesMap customMenus = targetPlatform.getCustomMenus();
for (final String menuId : customMenus.keySet()) {
String title = customMenus.get(menuId);
JMenu menu = getBoardCustomMenu(tr(title));
JMenu menu = getBoardCustomMenu(tr(title), getPlatformUniqueId(targetPlatform));

if (board.hasMenu(menuId)) {
PreferencesMap boardCustomMenu = board.getMenuLabels(menuId);
for (String customMenuOption : boardCustomMenu.keySet()) {
@SuppressWarnings("serial")
Action subAction = new AbstractAction(tr(boardCustomMenu.get(customMenuOption))) {
public void actionPerformed(ActionEvent e) {
PreferencesData.set("custom_" + menuId, ((TargetBoard) getValue("board")).getId() + "_" + getValue("custom_menu_option"));
PreferencesData.set("custom_" + menuId, ((List<TargetBoard>) getValue("board")).get(0).getId() + "_" + getValue("custom_menu_option"));
onBoardOrPortChange();
}
};
subAction.putValue("board", board);
List<TargetBoard> boards = (List<TargetBoard>) subAction.getValue("board");
if (boards == null) {
boards = new ArrayList<TargetBoard>();
}
boards.add(board);
subAction.putValue("board", boards);
subAction.putValue("custom_menu_option", customMenuOption);

if (!buttonGroupsMap.containsKey(menuId)) {
Expand Down Expand Up @@ -1572,7 +1580,9 @@ private void filterVisibilityOfSubsequentBoardMenus(List<JMenu> boardsCustomMenu
JMenu menu = boardsCustomMenus.get(i);
for (int m = 0; m < menu.getItemCount(); m++) {
JMenuItem menuItem = menu.getItem(m);
menuItem.setVisible(menuItem.getAction().getValue("board").equals(board));
for (TargetBoard t_board : (List<TargetBoard>)menuItem.getAction().getValue("board")) {
menuItem.setVisible(t_board.equals(board));
}
}
menu.setVisible(ifThereAreVisibleItemsOn(menu));

Expand All @@ -1595,9 +1605,9 @@ private static boolean ifThereAreVisibleItemsOn(JMenu menu) {
return false;
}

private JMenu getBoardCustomMenu(String label) throws Exception {
private JMenu getBoardCustomMenu(String label, String platformUniqueId) throws Exception {
for (JMenu menu : boardsCustomMenus) {
if (label.equals(menu.getText())) {
if (label.equals(menu.getText()) && menu.getClientProperty("platform").equals(platformUniqueId)) {
return menu;
}
}
Expand Down