Skip to content

Commit 38433c6

Browse files
Separate the boards menu per platform
Previously, the Tools->Boards menu was one long list, divided into different platforms by (unselectable) headers. When more than one or two platforms were installed, this quickly results in a very long list of boards that is hard to navigate. This commit changes the board menu to have a submenu for each platform, where each submenu contains just the boards for that platform. Note that this first keeps a list of board items and then adds those to the boards menu later. This could have been done directly, but the intermediate list makes it easier to special-case single platform installations, as well as sort the list in subsequent commits. This fixes part of arduino#8858.
1 parent f0c007d commit 38433c6

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

app/src/processing/app/Base.java

+23-23
Original file line numberDiff line numberDiff line change
@@ -1468,24 +1468,21 @@ public void actionPerformed(ActionEvent actionevent) {
14681468
ButtonGroup boardsButtonGroup = new ButtonGroup();
14691469
Map<String, ButtonGroup> buttonGroupsMap = new HashMap<>();
14701470

1471+
List<JMenu> platformMenus = new ArrayList<JMenu>();
1472+
14711473
// Cycle through all packages
1472-
boolean first = true;
14731474
for (TargetPackage targetPackage : BaseNoGui.packages.values()) {
14741475
// For every package cycle through all platform
14751476
for (TargetPlatform targetPlatform : targetPackage.platforms()) {
14761477

1477-
// Add a separator from the previous platform
1478-
if (!first)
1479-
boardMenu.add(new JSeparator());
1480-
first = false;
1481-
14821478
// Add a title for each platform
14831479
String platformLabel = targetPlatform.getPreferences().get("name");
1484-
if (platformLabel != null && !targetPlatform.getBoards().isEmpty()) {
1485-
JMenuItem menuLabel = new JMenuItem(tr(platformLabel));
1486-
menuLabel.setEnabled(false);
1487-
boardMenu.add(menuLabel);
1488-
}
1480+
if (platformLabel == null)
1481+
platformLabel = targetPackage.getId() + "-" + targetPlatform.getId();
1482+
1483+
JMenu platformBoardsMenu = new JMenu(tr(platformLabel));
1484+
MenuScroller.setScrollerFor(platformBoardsMenu);
1485+
platformMenus.add(platformBoardsMenu);
14891486

14901487
// Cycle through all boards of this platform
14911488
for (TargetBoard board : targetPlatform.getBoards().values()) {
@@ -1494,14 +1491,27 @@ public void actionPerformed(ActionEvent actionevent) {
14941491
JMenuItem item = createBoardMenusAndCustomMenus(boardsCustomMenus, menuItemsToClickAfterStartup,
14951492
buttonGroupsMap,
14961493
board, targetPlatform, targetPackage);
1497-
boardMenu.add(item);
1494+
platformBoardsMenu.add(item);
14981495
boardsButtonGroup.add(item);
14991496
}
15001497
}
15011498
}
15021499

1500+
JMenuItem firstBoardItem = null;
1501+
for (JMenu platformMenu : platformMenus) {
1502+
if (firstBoardItem == null && platformMenu.getItemCount() > 0)
1503+
firstBoardItem = platformMenu.getItem(0);
1504+
boardMenu.add(platformMenu);
1505+
}
1506+
1507+
if (firstBoardItem == null) {
1508+
throw new IllegalStateException("No available boards");
1509+
}
1510+
1511+
// If there is no current board yet (first startup, or selected
1512+
// board no longer defined), select first available board.
15031513
if (menuItemsToClickAfterStartup.isEmpty()) {
1504-
menuItemsToClickAfterStartup.add(selectFirstEnabledMenuItem(boardMenu));
1514+
menuItemsToClickAfterStartup.add(firstBoardItem);
15051515
}
15061516

15071517
for (JMenuItem menuItemToClick : menuItemsToClickAfterStartup) {
@@ -1655,16 +1665,6 @@ private static JMenuItem selectVisibleSelectedOrFirstMenuItem(JMenu menu) {
16551665
throw new IllegalStateException("Menu has no enabled items");
16561666
}
16571667

1658-
private static JMenuItem selectFirstEnabledMenuItem(JMenu menu) {
1659-
for (int i = 1; i < menu.getItemCount(); i++) {
1660-
JMenuItem item = menu.getItem(i);
1661-
if (item != null && item.isEnabled()) {
1662-
return item;
1663-
}
1664-
}
1665-
throw new IllegalStateException("Menu has no enabled items");
1666-
}
1667-
16681668
public void rebuildProgrammerMenu() {
16691669
programmerMenus = new LinkedList<>();
16701670

0 commit comments

Comments
 (0)