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.
This commit is contained in:
Matthijs Kooijman 2014-04-07 10:11:57 +02:00 committed by Cristian Maglie
parent 7548591d51
commit c0ab536b7b
2 changed files with 8 additions and 5 deletions

View File

@ -1600,6 +1600,13 @@ public class Base {
rebuildExamplesMenu(Editor.examplesMenu);
}
public static void selectSerialPort(String port) {
Preferences.set("serial.port", port);
if (port.startsWith("/dev/"))
Preferences.set("serial.port.file", port.substring(5));
else
Preferences.set("serial.port.file", port);
}
public void rebuildProgrammerMenu(JMenu menu) {
menu.removeAll();

View File

@ -965,11 +965,7 @@ public class Editor extends JFrame implements RunnerListener {
}
if (selection != null) selection.setState(true);
//System.out.println(item.getLabel());
Preferences.set("serial.port", name);
if (name.startsWith("/dev/"))
Preferences.set("serial.port.file", name.substring(5));
else
Preferences.set("serial.port.file", name);
Base.selectSerialPort(name);
if (serialMonitor != null) {
try {
serialMonitor.close();