diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 774d20f74ec..09f716f51be 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -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); @@ -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"); @@ -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")); } @@ -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.")); @@ -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 } @@ -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); } @@ -2409,7 +2446,6 @@ public void run() { try { serialMonitor.closeSerialPort(); - serialMonitor.setVisible(false); uploading = true; @@ -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); } diff --git a/app/src/processing/app/EditorToolbar.java b/app/src/processing/app/EditorToolbar.java index e7b8d3752d8..750b5743758 100644 --- a/app/src/processing/app/EditorToolbar.java +++ b/app/src/processing/app/EditorToolbar.java @@ -350,7 +350,7 @@ public void mousePressed(MouseEvent e) { break; case SERIAL: - editor.handleSerial(); + editor.handleSerial(true); break; } } diff --git a/build/shared/lib/preferences.txt b/build/shared/lib/preferences.txt index 67246f860e7..720d9fe06a6 100755 --- a/build/shared/lib/preferences.txt +++ b/build/shared/lib/preferences.txt @@ -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