mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-02 13:24:12 +01:00
Merge pull request #2628 from ffissore/split-ports-by-category
Split ports in menu, grouping boards by their protocol
This commit is contained in:
commit
00941453db
@ -60,6 +60,9 @@ import cc.arduino.packages.uploaders.SerialUploader;
|
|||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class Editor extends JFrame implements RunnerListener {
|
public class Editor extends JFrame implements RunnerListener {
|
||||||
|
|
||||||
|
private final static List<String> BOARD_PROTOCOLS_ORDER = Arrays.asList(new String[]{"serial", "network"});
|
||||||
|
private final static List<String> BOARD_PROTOCOLS_ORDER_TRANSLATIONS = Arrays.asList(new String[]{_("Serial ports"), _("Network ports")});
|
||||||
|
|
||||||
Base base;
|
Base base;
|
||||||
|
|
||||||
// otherwise, if the window is resized with the message label
|
// otherwise, if the window is resized with the message label
|
||||||
@ -996,7 +999,30 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
String selectedPort = Preferences.get("serial.port");
|
String selectedPort = Preferences.get("serial.port");
|
||||||
|
|
||||||
List<BoardPort> ports = Base.getDiscoveryManager().discovery();
|
List<BoardPort> ports = Base.getDiscoveryManager().discovery();
|
||||||
|
|
||||||
|
Collections.sort(ports, new Comparator<BoardPort>() {
|
||||||
|
@Override
|
||||||
|
public int compare(BoardPort o1, BoardPort o2) {
|
||||||
|
return BOARD_PROTOCOLS_ORDER.indexOf(o1.getProtocol()) - BOARD_PROTOCOLS_ORDER.indexOf(o2.getProtocol());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
String lastProtocol = null;
|
||||||
|
String lastProtocolTranslated;
|
||||||
for (BoardPort port : ports) {
|
for (BoardPort port : ports) {
|
||||||
|
if (lastProtocol == null || !port.getProtocol().equals(lastProtocol)) {
|
||||||
|
if (lastProtocol != null) {
|
||||||
|
serialMenu.addSeparator();
|
||||||
|
}
|
||||||
|
lastProtocol = port.getProtocol();
|
||||||
|
|
||||||
|
if (BOARD_PROTOCOLS_ORDER.indexOf(port.getProtocol()) != -1) {
|
||||||
|
lastProtocolTranslated = BOARD_PROTOCOLS_ORDER_TRANSLATIONS.get(BOARD_PROTOCOLS_ORDER.indexOf(port.getProtocol()));
|
||||||
|
} else {
|
||||||
|
lastProtocolTranslated = port.getProtocol();
|
||||||
|
}
|
||||||
|
serialMenu.add(new JMenuItem(_(lastProtocolTranslated)));
|
||||||
|
}
|
||||||
String address = port.getAddress();
|
String address = port.getAddress();
|
||||||
String label = port.getLabel();
|
String label = port.getLabel();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user