Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TweakMode fix to issue #3208 #3227

Merged
merged 2 commits into from Apr 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions java/src/processing/mode/java/JavaEditor.java
Expand Up @@ -2739,10 +2739,11 @@ private void removeSpacesFromCode() {
* Replace all numbers with variables and add code to initialize
* these variables and handle update messages.
*/
//public boolean automateSketch(Sketch sketch, ArrayList<Handle> handles[])
protected boolean automateSketch(Sketch sketch, List<List<Handle>> handles) {
protected boolean automateSketch(Sketch sketch, SketchParser parser) {
SketchCode[] code = sketch.getCode();

List<List<Handle>> handles = parser.allHandles;

if (code.length < 1) {
return false;
}
Expand All @@ -2751,8 +2752,8 @@ protected boolean automateSketch(Sketch sketch, List<List<Handle>> handles) {
return false;
}

int setupStartPos = SketchParser.getSetupStart(baseCode[0]);
if (setupStartPos < 0) {
int setupEndPos = SketchParser.getSetupEnd(baseCode[0]);
if (setupEndPos < 0) {
return false;
}

Expand Down Expand Up @@ -2794,7 +2795,7 @@ protected boolean automateSketch(Sketch sketch, List<List<Handle>> handles) {
}
code[tab].setProgram(c);
}

// add the main header to the code in the first tab
String c = code[0].getProgram();

Expand Down Expand Up @@ -2849,8 +2850,8 @@ protected boolean automateSketch(Sketch sketch, List<List<Handle>> handles) {
" tweakmode_initAllVars();\n"+
" tweakmode_initCommunication();\n\n";

setupStartPos = SketchParser.getSetupStart(c);
c = replaceString(c, setupStartPos, setupStartPos, addToSetup);
setupEndPos = SketchParser.getSetupEnd(c);
c = replaceString(c, setupEndPos, setupEndPos, addToSetup);

code[0].setProgram(header + c);

Expand Down
9 changes: 5 additions & 4 deletions java/src/processing/mode/java/JavaMode.java
Expand Up @@ -167,7 +167,6 @@ public Runner handleTweak(Sketch sketch,
RunnerListener listener,
final boolean present) throws SketchException {
final JavaEditor editor = (JavaEditor)listener;
boolean launchInteractive = false;

if (isSketchModified(sketch)) {
editor.deactivateRun();
Expand All @@ -193,7 +192,7 @@ public Runner handleTweak(Sketch sketch,
final SketchParser parser = new SketchParser(editor.baseCode, requiresTweak);

// add our code to the sketch
launchInteractive = editor.automateSketch(sketch, parser.allHandles);
final boolean launchInteractive = editor.automateSketch(sketch, parser);

build = new JavaBuild(sketch);
appletClassName = build.build(false);
Expand All @@ -204,8 +203,10 @@ public Runner handleTweak(Sketch sketch,
public void run() {
runtime.launch(present); // this blocks until finished
// next lines are executed when the sketch quits
editor.initEditorCode(parser.allHandles, false);
editor.stopInteractiveMode(parser.allHandles);
if (launchInteractive) {
editor.initEditorCode(parser.allHandles, false);
editor.stopInteractiveMode(parser.allHandles);
}
}
}).start();

Expand Down