From 22e9d2524588b024acbb7b66e3f15d82c3a4413b Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Mon, 8 Jun 2015 10:05:39 +0200 Subject: [PATCH] Update sketch code when editing with an external editor and IDE gets focus. Fixes #1778 --- app/src/processing/app/Base.java | 7 +++++++ app/src/processing/app/Sketch.java | 17 +++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index a64f46327..a6c635f5b 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -623,6 +623,13 @@ public class Base { protected void handleActivated(Editor whichEditor) { activeEditor = whichEditor; activeEditor.rebuildRecentSketchesMenu(); + if (PreferencesData.getBoolean("editor.external")) { + try { + activeEditor.getSketch().load(true); + } catch (IOException e) { + // noop + } + } // set the current window to be the console that's getting output EditorConsoleStream.setCurrent(activeEditor.console); diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index 9d8fef024..374b6bb24 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -108,6 +108,10 @@ public class Sketch { * in which case the load happens each time "run" is hit. */ protected void load() throws IOException { + load(false); + } + + protected void load(boolean forceUpdate) throws IOException { data.load(); for (SketchCode code : data.getCodes()) { @@ -117,7 +121,7 @@ public class Sketch { // set the main file to be the current tab if (editor != null) { - setCurrentCode(0); + setCurrentCode(currentIndex, forceUpdate); } } @@ -979,8 +983,12 @@ public class Sketch { * */ public void setCurrentCode(int which) { + setCurrentCode(which, false); + } + + public void setCurrentCode(int which, boolean forceUpdate) { // if current is null, then this is the first setCurrent(0) - if ((currentIndex == which) && (current != null)) { + if (!forceUpdate && (currentIndex == which) && (current != null)) { return; } @@ -1065,11 +1073,8 @@ public class Sketch { //handleOpen(sketch); //history.lastRecorded = historySaved; - // set current to null so that the tab gets updated - // http://dev.processing.org/bugs/show_bug.cgi?id=515 - current = null; // nuke previous files and settings, just get things loaded - load(); + load(true); } // // handle preprocessing the main file's code