Skip to content

Commit

Permalink
Separate the boards menu per platform
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
matthijskooijman authored and cmaglie committed Mar 25, 2020
1 parent 4e97727 commit 89cf600
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -1481,24 +1481,21 @@ public void actionPerformed(ActionEvent actionevent) {
ButtonGroup boardsButtonGroup = new ButtonGroup();
Map<String, ButtonGroup> buttonGroupsMap = new HashMap<>();

List<JMenu> platformMenus = new ArrayList<JMenu>();

// 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()) {
Expand All @@ -1507,14 +1504,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) {
Expand Down Expand Up @@ -1669,16 +1679,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<>();
ButtonGroup group = new ButtonGroup();
Expand Down

0 comments on commit 89cf600

Please sign in to comment.