mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-21 15:54:39 +01:00
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 #8858.
This commit is contained in:
parent
7c4205b412
commit
7bcd76332e
@ -1481,24 +1481,21 @@ public class Base {
|
||||
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()) {
|
||||
@ -1507,14 +1504,27 @@ public class Base {
|
||||
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) {
|
||||
@ -1669,16 +1679,6 @@ public class Base {
|
||||
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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user