@@ -539,6 +539,9 @@ public void actionPerformed(ActionEvent e) {
539539 item .addActionListener (new ActionListener () {
540540 public void actionPerformed (ActionEvent e ) {
541541 handleExport (false );
542+ // Hide the serial monitor window. It will reopen at the appropriate time
543+ // if "auto show" is enabled
544+ serialMonitor .setVisible (false );
542545 }
543546 });
544547 fileMenu .add (item );
@@ -662,10 +665,25 @@ protected JMenu buildToolsMenu() {
662665 item = newJMenuItemShift (_ ("Serial Monitor" ), 'M' );
663666 item .addActionListener (new ActionListener () {
664667 public void actionPerformed (ActionEvent e ) {
665- handleSerial ();
668+ handleSerial (true );
666669 }
667670 });
668671 menu .add (item );
672+
673+ // Create the "Auto Show Serial Monitor" menu item (a checkbox). Read the prefs
674+ // to see if it should be enabled.
675+ final boolean autoShowSerialMonitor = Preferences .getBoolean ("serial.auto_show_monitor_window" );
676+ item = new JCheckBoxMenuItem ("Auto Show Serial Monitor" , autoShowSerialMonitor );
677+ item .addActionListener (new ActionListener () {
678+ public void actionPerformed (ActionEvent e ) {
679+ // Make sure the choice in Preferences matches the checkbox state
680+ JCheckBoxMenuItem checkboxMenuItem = (JCheckBoxMenuItem )e .getSource ();
681+ Preferences .setBoolean ("serial.auto_show_monitor_window" , checkboxMenuItem .isSelected ());
682+ // The pref needs to be saved so that other parts of the app will stay in sync
683+ Preferences .save ();
684+ }
685+ });
686+ menu .add (item );
669687
670688 addTools (menu , Base .getToolsFolder ());
671689 File sketchbookTools = new File (Base .getSketchbookFolder (), "tools" );
@@ -941,7 +959,7 @@ protected void selectSerialPort(String name) {
941959 //System.out.println(item.getLabel());
942960 Preferences .set ("serial.port" , name );
943961 serialMonitor .closeSerialPort ();
944- serialMonitor . setVisible ( false );
962+
945963 serialMonitor = new SerialMonitor (Preferences .get ("serial.port" ));
946964 //System.out.println("set to " + get("serial.port"));
947965 }
@@ -2371,15 +2389,25 @@ synchronized public void handleExport(final boolean usingProgrammer) {
23712389 class DefaultExportHandler implements Runnable {
23722390 public void run () {
23732391
2392+ boolean uploadSuccessful = false ;
23742393 try {
23752394 serialMonitor .closeSerialPort ();
2376- serialMonitor .setVisible (false );
2395+
2396+ // If "auto show" is disabled make sure we hide the serial monitor window.
2397+ // This causes the IDE to act the way it always has in the the past.
2398+ if (Preferences .getBoolean ("serial.auto_show_monitor_window" )) {
2399+ serialMonitor .setVisible (true );
2400+ }
2401+ else {
2402+ serialMonitor .setVisible (false );
2403+ }
23772404
23782405 uploading = true ;
23792406
23802407 boolean success = sketch .exportApplet (false );
23812408 if (success ) {
23822409 statusNotice (_ ("Done uploading." ));
2410+ uploadSuccessful = true ;
23832411 } else {
23842412 // error message will already be visible
23852413 }
@@ -2398,6 +2426,17 @@ public void run() {
23982426 }
23992427 status .unprogress ();
24002428 uploading = false ;
2429+
2430+ // If auto show is enabled make sure the serial monitor is hooked up and visible
2431+ if (uploadSuccessful ) {
2432+ if (Preferences .getBoolean ("serial.auto_show_monitor_window" )) {
2433+ handleSerial (true );
2434+ }
2435+ }
2436+ else {
2437+ serialMonitor .setVisible (false );
2438+ }
2439+
24012440 //toolbar.clear();
24022441 toolbar .deactivate (EditorToolbar .EXPORT );
24032442 }
@@ -2409,7 +2448,6 @@ public void run() {
24092448
24102449 try {
24112450 serialMonitor .closeSerialPort ();
2412- serialMonitor .setVisible (false );
24132451
24142452 uploading = true ;
24152453
@@ -2474,12 +2512,14 @@ protected boolean handleExportCheckModified() {
24742512 }
24752513
24762514
2477- public void handleSerial () {
2515+ public void handleSerial (boolean makeVisible ) {
24782516 if (uploading ) return ;
24792517
24802518 try {
24812519 serialMonitor .openSerialPort ();
2482- serialMonitor .setVisible (true );
2520+ if (makeVisible ) {
2521+ serialMonitor .setVisible (true );
2522+ }
24832523 } catch (SerialException e ) {
24842524 statusError (e );
24852525 }
0 commit comments