diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index e9ddc9e4222..7af728fdd49 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -999,9 +999,9 @@ public boolean handleQuit() { // kill uploader (if still alive) UploaderUtils uploaderInstance = new UploaderUtils(); Uploader uploader = uploaderInstance.getUploaderByPreferences(false); - if (uploader != null && uploader.programmerPid != null && uploader.programmerPid.isAlive()) { + if (uploader != null && Uploader.programmerPid != null && Uploader.programmerPid.isAlive()) { // kill the stuck programmer - uploader.programmerPid.destroyForcibly(); + Uploader.programmerPid.destroyForcibly(); } if (handleQuitEach()) { @@ -1444,8 +1444,9 @@ public void actionPerformed(ActionEvent actionevent) { String filterText = ""; String dropdownItem = ""; if (actionevent instanceof Event) { - filterText = ((Event) actionevent).getPayload().get("filterText").toString(); - dropdownItem = ((Event) actionevent).getPayload().get("dropdownItem").toString(); + Event e = ((Event) actionevent); + filterText = e.getPayload().get("filterText").toString(); + dropdownItem = e.getPayload().get("dropdownItem").toString(); } try { openBoardsManager(filterText, dropdownItem); @@ -1481,24 +1482,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(platformLabel); + MenuScroller.setScrollerFor(platformBoardsMenu); + platformMenus.add(platformBoardsMenu); // Cycle through all boards of this platform for (TargetBoard board : targetPlatform.getBoards().values()) { @@ -1507,14 +1505,40 @@ public void actionPerformed(ActionEvent actionevent) { JMenuItem item = createBoardMenusAndCustomMenus(boardsCustomMenus, menuItemsToClickAfterStartup, buttonGroupsMap, board, targetPlatform, targetPackage); - boardMenu.add(item); + platformBoardsMenu.add(item); boardsButtonGroup.add(item); } } } + platformMenus.sort((x,y) -> x.getText().compareToIgnoreCase(y.getText())); + + JMenuItem firstBoardItem = null; + if (platformMenus.size() == 1) { + // When just one platform exists, add the board items directly, + // rather than using a submenu + for (Component boardItem : platformMenus.get(0).getMenuComponents()) { + boardMenu.add(boardItem); + if (firstBoardItem == null) + firstBoardItem = (JMenuItem)boardItem; + } + } else { + // For multiple platforms, use submenus + 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) { @@ -1579,7 +1603,7 @@ public void actionPerformed(ActionEvent e) { }; List boards = (List) subAction.getValue("board"); if (boards == null) { - boards = new ArrayList(); + boards = new ArrayList<>(); } boards.add(board); subAction.putValue("board", boards); @@ -1669,16 +1693,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(); @@ -1990,6 +2004,7 @@ public void keyPressed(KeyEvent e) { Base.this.handleFontSizeChange(-1); } break; + default: } } } diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index f0c7c19248c..2ec29c498cb 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -761,6 +761,20 @@ private JMenu buildToolsMenu() { toolsMenu.add(item); toolsMenu.addMenuListener(new StubMenuListener() { + public JMenuItem getSelectedItemRecursive(JMenu menu) { + int count = menu.getItemCount(); + for (int i=0; i < count; i++) { + JMenuItem item = menu.getItem(i); + + if ((item instanceof JMenu)) + item = getSelectedItemRecursive((JMenu)item); + + if (item != null && item.isSelected()) + return item; + } + return null; + } + public void menuSelected(MenuEvent e) { //System.out.println("Tools menu selected."); populatePortMenu(); @@ -772,15 +786,9 @@ public void menuSelected(MenuEvent e) { String basename = name; int index = name.indexOf(':'); if (index > 0) basename = name.substring(0, index); - String sel = null; - int count = menu.getItemCount(); - for (int i=0; i < count; i++) { - JMenuItem item = menu.getItem(i); - if (item != null && item.isSelected()) { - sel = item.getText(); - if (sel != null) break; - } - } + + JMenuItem item = getSelectedItemRecursive(menu); + String sel = item != null ? item.getText() : null; if (sel == null) { if (!name.equals(basename)) menu.setText(basename); } else { diff --git a/arduino-core/src/processing/app/I18n.java b/arduino-core/src/processing/app/I18n.java index 0ab961aa9ed..1f1a9f93703 100644 --- a/arduino-core/src/processing/app/I18n.java +++ b/arduino-core/src/processing/app/I18n.java @@ -106,10 +106,6 @@ public static String format(String fmt, Object... args) { * This method is an hack to extract words with gettext tool. */ protected static void unusedStrings() { - // These phrases are defined in the "platform.txt". - tr("Arduino AVR Boards"); - tr("Arduino ARM (32-bits) Boards"); - // This word is defined in the "boards.txt". tr("Processor"); }