From 77c869d6b770e66ad47733db7f473255f08c9e01 Mon Sep 17 00:00:00 2001 From: Reed Mangino Date: Wed, 12 Sep 2012 16:44:18 -0400 Subject: [PATCH 1/2] Added support for automatically showing the Serial Monitor window. This support is controled by a checkbox menu item in the Tools menu ("Auto Show Serial Monitor"). The feature is disabled by default and is tracked by a boolean "serial.auto_show_monitor_window" in Preferences.txt. When "auto show" is disabled the Serial Monitor window behavior is unchanged (i.e. if you don't enable "auto show" the IDE will work as it always has). --- app/src/processing/app/Editor.java | 52 ++++++++++++++++++++++++++---- build/shared/lib/preferences.txt | 1 + 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 838ca2dc285..f0253dcb9b5 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,7 @@ 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")); } @@ -2371,15 +2389,25 @@ synchronized public void handleExport(final boolean usingProgrammer) { class DefaultExportHandler implements Runnable { public void run() { + boolean uploadSuccessful = false; try { serialMonitor.closeSerialPort(); - serialMonitor.setVisible(false); + + // If "auto show" is disabled make sure we hide the serial monitor window. + // This causes the IDE to act the way it always has in the the past. + if (Preferences.getBoolean("serial.auto_show_monitor_window")) { + serialMonitor.setVisible(true); + } + else { + 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 +2426,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 +2448,6 @@ public void run() { try { serialMonitor.closeSerialPort(); - serialMonitor.setVisible(false); uploading = true; @@ -2474,12 +2512,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/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 From a9544e9a1c91b1b18e341d8100bc60706f7b0f94 Mon Sep 17 00:00:00 2001 From: Reed Mangino Date: Wed, 9 Oct 2013 08:35:35 -0400 Subject: [PATCH 2/2] Take 2: Added support for automatically showing the Serial Monitor window upon successful sketch upload This fix was originally attempted via the following pull request but the Arduino team didn't take it (even though users have been asking for it for years). https://github.com/rmangino/Arduino/commit/77c869d6b770e66ad47733db7f473255f08c9e01 This new pull request fixes an issue which didn't exist when I made the original pull request (over a year ago). This support is controlled via a checkbox menu item in the Tools menu ("Auto Show Serial Monitor"). The feature is *disabled by default* and is tracked by a boolean "serial.auto_show_monitor_window" in Preferences.txt. When "auto show" is disabled the Serial Monitor window behavior is unchanged (i.e. if you don't enable "auto show" the IDE will work as it always has). The serial monitor window is hidden when the sketch fails to compile. NOTE: The IDE's default behavior has *not* changed. The only difference is that a user may now *explicitly* request that the serial monitor window be shown upon automatically upon successful upload. Signed-off-by: Reed Mangino --- app/src/processing/app/Editor.java | 32 +++++++++++------------ app/src/processing/app/EditorToolbar.java | 2 +- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 449404f1597..09f716f51be 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -675,13 +675,13 @@ public void actionPerformed(ActionEvent e) { 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(); - } + 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); @@ -959,7 +959,6 @@ protected void selectSerialPort(String name) { //System.out.println(item.getLabel()); Preferences.set("serial.port", name); serialMonitor.closeSerialPort(); - serialMonitor = new SerialMonitor(Preferences.get("serial.port")); //System.out.println("set to " + get("serial.port")); } @@ -1911,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.")); @@ -2388,20 +2391,15 @@ 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(); - // If "auto show" is disabled make sure we hide the serial monitor window. - // This causes the IDE to act the way it always has in the the past. - if (Preferences.getBoolean("serial.auto_show_monitor_window")) { - serialMonitor.setVisible(true); - } - else { - serialMonitor.setVisible(false); - } - uploading = true; boolean success = sketch.exportApplet(false); 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; } }