Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 89cf600

Browse files
matthijskooijmancmaglie
authored andcommitted
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.
1 parent 4e97727 commit 89cf600

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

‎app/src/processing/app/Base.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,24 +1481,21 @@ public void actionPerformed(ActionEvent actionevent) {
14811481
ButtonGroup boardsButtonGroup = new ButtonGroup();
14821482
Map<String, ButtonGroup> buttonGroupsMap = new HashMap<>();
14831483

1484+
List<JMenu> platformMenus = new ArrayList<JMenu>();
1485+
14841486
// Cycle through all packages
1485-
boolean first = true;
14861487
for (TargetPackage targetPackage : BaseNoGui.packages.values()) {
14871488
// For every package cycle through all platform
14881489
for (TargetPlatform targetPlatform : targetPackage.platforms()) {
14891490

1490-
// Add a separator from the previous platform
1491-
if (!first)
1492-
boardMenu.add(new JSeparator());
1493-
first = false;
1494-
14951491
// Add a title for each platform
14961492
String platformLabel = targetPlatform.getPreferences().get("name");
1497-
if (platformLabel != null && !targetPlatform.getBoards().isEmpty()) {
1498-
JMenuItem menuLabel = new JMenuItem(tr(platformLabel));
1499-
menuLabel.setEnabled(false);
1500-
boardMenu.add(menuLabel);
1501-
}
1493+
if (platformLabel == null)
1494+
platformLabel = targetPackage.getId() + "-" + targetPlatform.getId();
1495+
1496+
JMenu platformBoardsMenu = new JMenu(tr(platformLabel));
1497+
MenuScroller.setScrollerFor(platformBoardsMenu);
1498+
platformMenus.add(platformBoardsMenu);
15021499

15031500
// Cycle through all boards of this platform
15041501
for (TargetBoard board : targetPlatform.getBoards().values()) {
@@ -1507,14 +1504,27 @@ public void actionPerformed(ActionEvent actionevent) {
15071504
JMenuItem item = createBoardMenusAndCustomMenus(boardsCustomMenus, menuItemsToClickAfterStartup,
15081505
buttonGroupsMap,
15091506
board, targetPlatform, targetPackage);
1510-
boardMenu.add(item);
1507+
platformBoardsMenu.add(item);
15111508
boardsButtonGroup.add(item);
15121509
}
15131510
}
15141511
}
15151512

1513+
JMenuItem firstBoardItem = null;
1514+
for (JMenu platformMenu : platformMenus) {
1515+
if (firstBoardItem == null && platformMenu.getItemCount() > 0)
1516+
firstBoardItem = platformMenu.getItem(0);
1517+
boardMenu.add(platformMenu);
1518+
}
1519+
1520+
if (firstBoardItem == null) {
1521+
throw new IllegalStateException("No available boards");
1522+
}
1523+
1524+
// If there is no current board yet (first startup, or selected
1525+
// board no longer defined), select first available board.
15161526
if (menuItemsToClickAfterStartup.isEmpty()) {
1517-
menuItemsToClickAfterStartup.add(selectFirstEnabledMenuItem(boardMenu));
1527+
menuItemsToClickAfterStartup.add(firstBoardItem);
15181528
}
15191529

15201530
for (JMenuItem menuItemToClick : menuItemsToClickAfterStartup) {
@@ -1669,16 +1679,6 @@ private static JMenuItem selectVisibleSelectedOrFirstMenuItem(JMenu menu) {
16691679
throw new IllegalStateException("Menu has no enabled items");
16701680
}
16711681

1672-
private static JMenuItem selectFirstEnabledMenuItem(JMenu menu) {
1673-
for (int i = 1; i < menu.getItemCount(); i++) {
1674-
JMenuItem item = menu.getItem(i);
1675-
if (item != null && item.isEnabled()) {
1676-
return item;
1677-
}
1678-
}
1679-
throw new IllegalStateException("Menu has no enabled items");
1680-
}
1681-
16821682
public void rebuildProgrammerMenu() {
16831683
programmerMenus = new LinkedList<>();
16841684
ButtonGroup group = new ButtonGroup();

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /