diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index d8e9b1cac45..4b6fe228828 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1468,24 +1468,21 @@ public void actionPerformed(ActionEvent actionevent) { ButtonGroup boardsButtonGroup = new ButtonGroup(); Map buttonGroupsMap = new HashMap<>(); + List platformMenus = new ArrayList(); + // Cycle through all packages - boolean first = true; for (TargetPackage targetPackage : BaseNoGui.packages.values()) { // For every package cycle through all platform for (TargetPlatform targetPlatform : targetPackage.platforms()) { - // Add a separator from the previous platform - if (!first) - boardMenu.add(new JSeparator()); - first = false; - // Add a title for each platform String platformLabel = targetPlatform.getPreferences().get("name"); - if (platformLabel != null && !targetPlatform.getBoards().isEmpty()) { - JMenuItem menuLabel = new JMenuItem(tr(platformLabel)); - menuLabel.setEnabled(false); - boardMenu.add(menuLabel); - } + if (platformLabel == null) + platformLabel = targetPackage.getId() + "-" + targetPlatform.getId(); + + JMenu platformBoardsMenu = new JMenu(tr(platformLabel)); + MenuScroller.setScrollerFor(platformBoardsMenu); + platformMenus.add(platformBoardsMenu); // Cycle through all boards of this platform for (TargetBoard board : targetPlatform.getBoards().values()) { @@ -1494,14 +1491,27 @@ public void actionPerformed(ActionEvent actionevent) { JMenuItem item = createBoardMenusAndCustomMenus(boardsCustomMenus, menuItemsToClickAfterStartup, buttonGroupsMap, board, targetPlatform, targetPackage); - boardMenu.add(item); + platformBoardsMenu.add(item); boardsButtonGroup.add(item); } } } + JMenuItem firstBoardItem = null; + for (JMenu platformMenu : platformMenus) { + if (firstBoardItem == null && platformMenu.getItemCount() > 0) + firstBoardItem = platformMenu.getItem(0); + boardMenu.add(platformMenu); + } + + if (firstBoardItem == null) { + throw new IllegalStateException("No available boards"); + } + + // If there is no current board yet (first startup, or selected + // board no longer defined), select first available board. if (menuItemsToClickAfterStartup.isEmpty()) { - menuItemsToClickAfterStartup.add(selectFirstEnabledMenuItem(boardMenu)); + menuItemsToClickAfterStartup.add(firstBoardItem); } for (JMenuItem menuItemToClick : menuItemsToClickAfterStartup) { @@ -1655,16 +1665,6 @@ private static JMenuItem selectVisibleSelectedOrFirstMenuItem(JMenu menu) { throw new IllegalStateException("Menu has no enabled items"); } - private static JMenuItem selectFirstEnabledMenuItem(JMenu menu) { - for (int i = 1; i < menu.getItemCount(); i++) { - JMenuItem item = menu.getItem(i); - if (item != null && item.isEnabled()) { - return item; - } - } - throw new IllegalStateException("Menu has no enabled items"); - } - public void rebuildProgrammerMenu() { programmerMenus = new LinkedList<>();