From 2778651eb60caa1bbe72fdf4b1338eb49a3b7ac2 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 14 May 2019 17:25:53 +0200 Subject: [PATCH] Allow multiple boards to share the same menu This stuff is truly madness, should be refactored from the ground up by a Java expert --- app/src/processing/app/Base.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index d3c433802..e690adc32 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1539,11 +1539,16 @@ public class Base { @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)) { @@ -1571,7 +1576,9 @@ public class Base { 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));