Skip to content

Commit c0ab536

Browse files
matthijskooijmancmaglie
authored andcommitted
Add Base.selectSerialPort
This method takes care of setting the serial.port preference to the given value, as well as deriving the serial.port.file preference. This should prevent duplicate code in the future. Note that a second copy of this code lives in SerialUploader, but that doesn't write to the global Preferences but a local prefs map. Since the global Preferences are currently static, there is no way to share code between these two copies.
1 parent 7548591 commit c0ab536

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

app/src/processing/app/Base.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,6 +1600,13 @@ private void selectBoard(TargetBoard targetBoard) {
16001600
rebuildExamplesMenu(Editor.examplesMenu);
16011601
}
16021602

1603+
public static void selectSerialPort(String port) {
1604+
Preferences.set("serial.port", port);
1605+
if (port.startsWith("/dev/"))
1606+
Preferences.set("serial.port.file", port.substring(5));
1607+
else
1608+
Preferences.set("serial.port.file", port);
1609+
}
16031610

16041611
public void rebuildProgrammerMenu(JMenu menu) {
16051612
menu.removeAll();

app/src/processing/app/Editor.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -965,11 +965,7 @@ protected void selectSerialPort(String name) {
965965
}
966966
if (selection != null) selection.setState(true);
967967
//System.out.println(item.getLabel());
968-
Preferences.set("serial.port", name);
969-
if (name.startsWith("/dev/"))
970-
Preferences.set("serial.port.file", name.substring(5));
971-
else
972-
Preferences.set("serial.port.file", name);
968+
Base.selectSerialPort(name);
973969
if (serialMonitor != null) {
974970
try {
975971
serialMonitor.close();

0 commit comments

Comments
 (0)