Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Auto Show Serial Monitor" #115

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 45 additions & 7 deletions app/src/processing/app/Editor.java
Expand Up @@ -539,6 +539,9 @@ public void actionPerformed(ActionEvent e) {
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
handleExport(false);
// Hide the serial monitor window. It will reopen at the appropriate time
// if "auto show" is enabled
serialMonitor.setVisible(false);
}
});
fileMenu.add(item);
Expand Down Expand Up @@ -662,10 +665,25 @@ protected JMenu buildToolsMenu() {
item = newJMenuItemShift(_("Serial Monitor"), 'M');
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
handleSerial();
handleSerial(true);
}
});
menu.add(item);

// Create the "Auto Show Serial Monitor" menu item (a checkbox). Read the prefs
// to see if it should be enabled.
final boolean autoShowSerialMonitor = Preferences.getBoolean("serial.auto_show_monitor_window");
item = new JCheckBoxMenuItem("Auto Show Serial Monitor", autoShowSerialMonitor);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Make sure the choice in Preferences matches the checkbox state
JCheckBoxMenuItem checkboxMenuItem = (JCheckBoxMenuItem)e.getSource();
Preferences.setBoolean("serial.auto_show_monitor_window", checkboxMenuItem.isSelected());
// The pref needs to be saved so that other parts of the app will stay in sync
Preferences.save();
}
});
menu.add(item);

addTools(menu, Base.getToolsFolder());
File sketchbookTools = new File(Base.getSketchbookFolder(), "tools");
Expand Down Expand Up @@ -941,7 +959,6 @@ protected void selectSerialPort(String name) {
//System.out.println(item.getLabel());
Preferences.set("serial.port", name);
serialMonitor.closeSerialPort();
serialMonitor.setVisible(false);
serialMonitor = new SerialMonitor(Preferences.get("serial.port"));
//System.out.println("set to " + get("serial.port"));
}
Expand Down Expand Up @@ -1893,6 +1910,10 @@ public void handleRun(final boolean verbose) {
class DefaultRunHandler implements Runnable {
public void run() {
try {
// Ensure the serial monitor window is closed until after we successfully
// upload a sketch
serialMonitor.setVisible(false);

sketch.prepare();
sketch.build(false);
statusNotice(_("Done compiling."));
Expand Down Expand Up @@ -2370,16 +2391,21 @@ synchronized public void handleExport(final boolean usingProgrammer) {
// DAM: in Arduino, this is upload
class DefaultExportHandler implements Runnable {
public void run() {

// Hide the serial monitor window until we are certain the sketch
// uploaded successfully
serialMonitor.setVisible(false);

boolean uploadSuccessful = false;
try {
serialMonitor.closeSerialPort();
serialMonitor.setVisible(false);


uploading = true;

boolean success = sketch.exportApplet(false);
if (success) {
statusNotice(_("Done uploading."));
uploadSuccessful = true;
} else {
// error message will already be visible
}
Expand All @@ -2398,6 +2424,17 @@ public void run() {
}
status.unprogress();
uploading = false;

// If auto show is enabled make sure the serial monitor is hooked up and visible
if (uploadSuccessful) {
if (Preferences.getBoolean("serial.auto_show_monitor_window")) {
handleSerial(true);
}
}
else {
serialMonitor.setVisible(false);
}

//toolbar.clear();
toolbar.deactivate(EditorToolbar.EXPORT);
}
Expand All @@ -2409,7 +2446,6 @@ public void run() {

try {
serialMonitor.closeSerialPort();
serialMonitor.setVisible(false);

uploading = true;

Expand Down Expand Up @@ -2474,12 +2510,14 @@ protected boolean handleExportCheckModified() {
}


public void handleSerial() {
public void handleSerial(boolean makeVisible) {
if (uploading) return;

try {
serialMonitor.openSerialPort();
serialMonitor.setVisible(true);
if (makeVisible) {
serialMonitor.setVisible(true);
}
} catch (SerialException e) {
statusError(e);
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/processing/app/EditorToolbar.java
Expand Up @@ -350,7 +350,7 @@ public void mousePressed(MouseEvent e) {
break;

case SERIAL:
editor.handleSerial();
editor.handleSerial(true);
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions build/shared/lib/preferences.txt
Expand Up @@ -255,6 +255,7 @@ serial.databits=8
serial.stopbits=1
serial.parity=N
serial.debug_rate=9600
serial.auto_show_monitor_window=false

# I18 Preferences

Expand Down