Skip to content

Commit

Permalink
Use un-translated labels to sort boards submenus
Browse files Browse the repository at this point in the history
Otherwise it may happen some weird sorting when untraslated and
translated labels are sorted together:

    Arduino megaAVR Boards
    Arduino nRF52 Board
    ESP32 Arduino
    ESP8266 Modules
    Schede Arduino AVR   <-- the localized string falls to the bottom

all the Arduino boards should be packed together, so it's better to not
use localization at all while sorting. After this patch it will look like

    Schede Arduino AVR
    Arduino megaAVR Boards
    Arduino nRF52 Board
    ESP32 Arduino
    ESP8266 Modules
  • Loading branch information
cmaglie committed Mar 25, 2020
1 parent 55fa3f5 commit 747ce01
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -1481,19 +1481,29 @@ public void actionPerformed(ActionEvent actionevent) {
ButtonGroup boardsButtonGroup = new ButtonGroup();
Map<String, ButtonGroup> buttonGroupsMap = new HashMap<>();

List<JMenu> platformMenus = new ArrayList<JMenu>();
class PlatformJMenu extends JMenu {
private String untraslatedText;

public PlatformJMenu(TargetPlatform pl) {
super();
untraslatedText = pl.getPreferences().get("name");
if (untraslatedText == null) {
untraslatedText = pl.getContainerPackage().getId() + "-" + pl.getId();
}
setText(tr(untraslatedText));
}

public String getUntraslatedText() {
return untraslatedText;
}
}
List<PlatformJMenu> platformMenus = new ArrayList<>();

// Cycle through all packages
for (TargetPackage targetPackage : BaseNoGui.packages.values()) {
// For every package cycle through all platform
for (TargetPlatform targetPlatform : targetPackage.platforms()) {

// Add a title for each platform
String platformLabel = targetPlatform.getPreferences().get("name");
if (platformLabel == null)
platformLabel = targetPackage.getId() + "-" + targetPlatform.getId();

JMenu platformBoardsMenu = new JMenu(tr(platformLabel));
PlatformJMenu platformBoardsMenu = new PlatformJMenu(targetPlatform);
MenuScroller.setScrollerFor(platformBoardsMenu);
platformMenus.add(platformBoardsMenu);

Expand All @@ -1510,7 +1520,7 @@ public void actionPerformed(ActionEvent actionevent) {
}
}

platformMenus.sort((x,y) -> x.getText().compareToIgnoreCase(y.getText()));
platformMenus.sort((x,y) -> x.getUntraslatedText().compareToIgnoreCase(y.getUntraslatedText()));

JMenuItem firstBoardItem = null;
if (platformMenus.size() == 1) {
Expand Down

0 comments on commit 747ce01

Please sign in to comment.