@@ -152,6 +152,8 @@ public class Editor extends JFrame implements RunnerListener {
152152
153153 Runnable runHandler ;
154154 Runnable presentHandler ;
155+ Runnable runAndSaveHandler ;
156+ Runnable presentAndSaveHandler ;
155157 Runnable stopHandler ;
156158 Runnable exportHandler ;
157159 Runnable exportAppHandler ;
@@ -563,22 +565,6 @@ public void actionPerformed(ActionEvent e) {
563565 });
564566 fileMenu .add (saveAsMenuItem );
565567
566- item = newJMenuItem (_ ("Upload" ), 'U' );
567- item .addActionListener (new ActionListener () {
568- public void actionPerformed (ActionEvent e ) {
569- handleExport (false );
570- }
571- });
572- fileMenu .add (item );
573-
574- item = newJMenuItemShift (_ ("Upload Using Programmer" ), 'U' );
575- item .addActionListener (new ActionListener () {
576- public void actionPerformed (ActionEvent e ) {
577- handleExport (true );
578- }
579- });
580- fileMenu .add (item );
581-
582568 fileMenu .addSeparator ();
583569
584570 item = newJMenuItemShift (_ ("Page Setup" ), 'P' );
@@ -637,14 +623,31 @@ public void actionPerformed(ActionEvent e) {
637623 }
638624 });
639625 sketchMenu .add (item );
626+
627+ item = newJMenuItem (_ ("Upload" ), 'U' );
628+ item .addActionListener (new ActionListener () {
629+ public void actionPerformed (ActionEvent e ) {
630+ handleExport (false );
631+ }
632+ });
633+ sketchMenu .add (item );
634+
635+ item = newJMenuItemShift (_ ("Upload Using Programmer" ), 'U' );
636+ item .addActionListener (new ActionListener () {
637+ public void actionPerformed (ActionEvent e ) {
638+ handleExport (true );
639+ }
640+ });
641+ sketchMenu .add (item );
640642
641- // item = newJMenuItemShift("Verify / Compile (verbose)", 'R');
642- // item.addActionListener(new ActionListener() {
643- // public void actionPerformed(ActionEvent e) {
644- // handleRun(true);
645- // }
646- // });
647- // sketchMenu.add(item);
643+
644+ item = newJMenuItemAlt ("Export compiled Binary" , 'S' );
645+ item .addActionListener (new ActionListener () {
646+ public void actionPerformed (ActionEvent e ) {
647+ handleRunAndSave (true );
648+ }
649+ });
650+ sketchMenu .add (item );
648651
649652// item = new JMenuItem("Stop");
650653// item.addActionListener(new ActionListener() {
@@ -1508,11 +1511,17 @@ protected void updateRedoState() {
15081511 // abstract from the editor in this fashion.
15091512
15101513
1511- public void setHandlers (Runnable runHandler , Runnable presentHandler ,
1514+ public void setHandlers (Runnable runHandler ,
1515+ Runnable presentHandler ,
1516+ Runnable runAndSaveHandler ,
1517+ Runnable presentAndSaveHandler ,
15121518 Runnable stopHandler ,
1513- Runnable exportHandler , Runnable exportAppHandler ) {
1519+ Runnable exportHandler ,
1520+ Runnable exportAppHandler ) {
15141521 this .runHandler = runHandler ;
15151522 this .presentHandler = presentHandler ;
1523+ this .runAndSaveHandler = runAndSaveHandler ;
1524+ this .presentAndSaveHandler = presentAndSaveHandler ;
15161525 this .stopHandler = stopHandler ;
15171526 this .exportHandler = exportHandler ;
15181527 this .exportAppHandler = exportAppHandler ;
@@ -1522,6 +1531,8 @@ public void setHandlers(Runnable runHandler, Runnable presentHandler,
15221531 public void resetHandlers () {
15231532 runHandler = new BuildHandler ();
15241533 presentHandler = new BuildHandler (true );
1534+ runAndSaveHandler = new BuildAndSaveHandler ();
1535+ presentAndSaveHandler = new BuildAndSaveHandler (true );
15251536 stopHandler = new DefaultStopHandler ();
15261537 exportHandler = new DefaultExportHandler ();
15271538 exportAppHandler = new DefaultExportAppHandler ();
@@ -2012,6 +2023,29 @@ public void handleRun(final boolean verbose) {
20122023 // placed on the event thread and causes a hang--bad idea all around.
20132024 new Thread (verbose ? presentHandler : runHandler ).start ();
20142025 }
2026+
2027+ /**
2028+ * Implements Sketch → Run and Save.
2029+ * @param verbose Set true to run with verbose output.
2030+ */
2031+ public void handleRunAndSave (final boolean verbose ) {
2032+ internalCloseRunner ();
2033+ running = true ;
2034+ toolbar .activate (EditorToolbar .RUN );
2035+ status .progress (_ ("Compiling sketch..." ));
2036+
2037+ // do this to advance/clear the terminal window / dos prompt / etc
2038+ for (int i = 0 ; i < 10 ; i ++) System .out .println ();
2039+
2040+ // clear the console on each run, unless the user doesn't want to
2041+ if (Preferences .getBoolean ("console.auto_clear" )) {
2042+ console .clear ();
2043+ }
2044+
2045+ // Cannot use invokeLater() here, otherwise it gets
2046+ // placed on the event thread and causes a hang--bad idea all around.
2047+ new Thread (verbose ? presentAndSaveHandler : runAndSaveHandler ).start ();
2048+ }
20152049
20162050 class BuildHandler implements Runnable {
20172051
@@ -2029,7 +2063,7 @@ public BuildHandler(boolean verbose) {
20292063 public void run () {
20302064 try {
20312065 sketch .prepare ();
2032- sketch .build (verbose );
2066+ sketch .build (verbose , false );
20332067 statusNotice (_ ("Done compiling." ));
20342068 } catch (PreferencesMapException e ) {
20352069 statusError (I18n .format (
@@ -2044,6 +2078,38 @@ public void run() {
20442078 toolbar .deactivate (EditorToolbar .RUN );
20452079 }
20462080 }
2081+
2082+ class BuildAndSaveHandler implements Runnable {
2083+
2084+ private final boolean verbose ;
2085+
2086+ public BuildAndSaveHandler () {
2087+ this (false );
2088+ }
2089+
2090+ public BuildAndSaveHandler (boolean verbose ) {
2091+ this .verbose = verbose ;
2092+ }
2093+
2094+ @ Override
2095+ public void run () {
2096+ try {
2097+ sketch .prepare ();
2098+ sketch .build (verbose , true );
2099+ statusNotice (_ ("Done compiling." ));
2100+ } catch (PreferencesMapException e ) {
2101+ statusError (I18n .format (
2102+ _ ("Error while compiling: missing '{0}' configuration parameter" ),
2103+ e .getMessage ()));
2104+ } catch (Exception e ) {
2105+ status .unprogress ();
2106+ statusError (e );
2107+ }
2108+
2109+ status .unprogress ();
2110+ toolbar .deactivate (EditorToolbar .RUN );
2111+ }
2112+ }
20472113
20482114 class DefaultStopHandler implements Runnable {
20492115 public void run () {
0 commit comments