Skip to content

Commit e5833e8

Browse files
committed
Make run button behave
When clicking run button while a sketch is running, it will be activated again when the sketch is restarted. Previously it got deactivated by the old sketch runner, because it was quitting after the new sketch runner started.
1 parent 4a50ea3 commit e5833e8

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

java/src/processing/mode/java/JavaEditor.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,13 @@ public void handleContinue() {
11701170
}
11711171

11721172

1173+
public void onRunnerExiting(Runner runner) {
1174+
if (this.runtime == runner) {
1175+
deactivateRun();
1176+
}
1177+
}
1178+
1179+
11731180
// /** Toggle a breakpoint on the current line. */
11741181
// public void toggleBreakpoint() {
11751182
// toggleBreakpoint(getCurrentLineID().lineIdx());

java/src/processing/mode/java/runner/Runner.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424

2525
import processing.app.*;
2626
import processing.app.exec.StreamRedirectThread;
27-
import processing.app.ui.Editor;
2827
import processing.core.*;
2928
import processing.data.StringList;
3029
import processing.mode.java.JavaBuild;
30+
import processing.mode.java.JavaEditor;
3131

3232
import java.awt.GraphicsDevice;
3333
import java.awt.GraphicsEnvironment;
@@ -71,7 +71,7 @@ public class Runner implements MessageConsumer {
7171
protected Thread outThread = null;
7272

7373
protected SketchException exception;
74-
protected Editor editor;
74+
protected JavaEditor editor;
7575
protected JavaBuild build;
7676
protected Process process;
7777

@@ -86,8 +86,8 @@ public Runner(JavaBuild build, RunnerListener listener) throws SketchException {
8686

8787
checkLocalHost();
8888

89-
if (listener instanceof Editor) {
90-
this.editor = (Editor) listener;
89+
if (listener instanceof JavaEditor) {
90+
this.editor = (JavaEditor) listener;
9191
sketchErr = editor.getConsole().getErr();
9292
sketchOut = editor.getConsole().getOut();
9393
} else {
@@ -610,7 +610,9 @@ public void run() {
610610
// or the user manually closes the sketch window.
611611
// TODO this should be handled better, should it not?
612612
if (editor != null) {
613-
editor.deactivateRun();
613+
java.awt.EventQueue.invokeLater(() -> {
614+
editor.onRunnerExiting(Runner.this);
615+
});
614616
}
615617
} catch (InterruptedException exc) {
616618
// we don't interrupt
@@ -679,7 +681,9 @@ public void exceptionEvent(ExceptionEvent event) {
679681
handleCommonErrors(exceptionName, message, listener, sketchErr);
680682

681683
if (editor != null) {
682-
editor.deactivateRun();
684+
java.awt.EventQueue.invokeLater(() -> {
685+
editor.onRunnerExiting(Runner.this);
686+
});
683687
}
684688
}
685689

0 commit comments

Comments
 (0)