@@ -539,6 +539,9 @@ public void actionPerformed(ActionEvent e) {
539
539
item .addActionListener (new ActionListener () {
540
540
public void actionPerformed (ActionEvent e ) {
541
541
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 );
542
545
}
543
546
});
544
547
fileMenu .add (item );
@@ -662,10 +665,25 @@ protected JMenu buildToolsMenu() {
662
665
item = newJMenuItemShift (_ ("Serial Monitor" ), 'M' );
663
666
item .addActionListener (new ActionListener () {
664
667
public void actionPerformed (ActionEvent e ) {
665
- handleSerial ();
668
+ handleSerial (true );
666
669
}
667
670
});
668
671
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 );
669
687
670
688
addTools (menu , Base .getToolsFolder ());
671
689
File sketchbookTools = new File (Base .getSketchbookFolder (), "tools" );
@@ -941,7 +959,7 @@ protected void selectSerialPort(String name) {
941
959
//System.out.println(item.getLabel());
942
960
Preferences .set ("serial.port" , name );
943
961
serialMonitor .closeSerialPort ();
944
- serialMonitor . setVisible ( false );
962
+
945
963
serialMonitor = new SerialMonitor (Preferences .get ("serial.port" ));
946
964
//System.out.println("set to " + get("serial.port"));
947
965
}
@@ -2371,15 +2389,25 @@ synchronized public void handleExport(final boolean usingProgrammer) {
2371
2389
class DefaultExportHandler implements Runnable {
2372
2390
public void run () {
2373
2391
2392
+ boolean uploadSuccessful = false ;
2374
2393
try {
2375
2394
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
+ }
2377
2404
2378
2405
uploading = true ;
2379
2406
2380
2407
boolean success = sketch .exportApplet (false );
2381
2408
if (success ) {
2382
2409
statusNotice (_ ("Done uploading." ));
2410
+ uploadSuccessful = true ;
2383
2411
} else {
2384
2412
// error message will already be visible
2385
2413
}
@@ -2398,6 +2426,17 @@ public void run() {
2398
2426
}
2399
2427
status .unprogress ();
2400
2428
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
+
2401
2440
//toolbar.clear();
2402
2441
toolbar .deactivate (EditorToolbar .EXPORT );
2403
2442
}
@@ -2409,7 +2448,6 @@ public void run() {
2409
2448
2410
2449
try {
2411
2450
serialMonitor .closeSerialPort ();
2412
- serialMonitor .setVisible (false );
2413
2451
2414
2452
uploading = true ;
2415
2453
@@ -2474,12 +2512,14 @@ protected boolean handleExportCheckModified() {
2474
2512
}
2475
2513
2476
2514
2477
- public void handleSerial () {
2515
+ public void handleSerial (boolean makeVisible ) {
2478
2516
if (uploading ) return ;
2479
2517
2480
2518
try {
2481
2519
serialMonitor .openSerialPort ();
2482
- serialMonitor .setVisible (true );
2520
+ if (makeVisible ) {
2521
+ serialMonitor .setVisible (true );
2522
+ }
2483
2523
} catch (SerialException e ) {
2484
2524
statusError (e );
2485
2525
}
0 commit comments