diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index ef4d9b30a4e..f1d5b9ccd40 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1436,17 +1436,16 @@ public void actionPerformed(ActionEvent actionevent) { boardMenu.add(new JSeparator()); // Generate custom menus for all platforms - Set 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 menuItemsToClickAfterStartup = new LinkedList<>(); @@ -1495,6 +1494,10 @@ public void actionPerformed(ActionEvent actionevent) { } } + private String getPlatformUniqueId(TargetPlatform platform) { + return platform.getId() + "_" + platform.getFolder(); + } + private JRadioButtonMenuItem createBoardMenusAndCustomMenus( final List boardsCustomMenus, List menuItemsToClickAfterStartup, Map buttonGroupsMap, @@ -1532,7 +1535,7 @@ 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); @@ -1540,11 +1543,16 @@ public void actionPerformed(ActionEvent actionevent) { @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) getValue("board")).get(0).getId() + "_" + getValue("custom_menu_option")); onBoardOrPortChange(); } }; - subAction.putValue("board", board); + List boards = (List) subAction.getValue("board"); + if (boards == null) { + boards = new ArrayList(); + } + boards.add(board); + subAction.putValue("board", boards); subAction.putValue("custom_menu_option", customMenuOption); if (!buttonGroupsMap.containsKey(menuId)) { @@ -1572,7 +1580,9 @@ private void filterVisibilityOfSubsequentBoardMenus(List 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)menuItem.getAction().getValue("board")) { + menuItem.setVisible(t_board.equals(board)); + } } menu.setVisible(ifThereAreVisibleItemsOn(menu)); @@ -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; } }