Update sketch code when editing with an external editor and IDE gets focus. Fixes #1778

This commit is contained in:
Federico Fissore 2015-06-08 10:05:39 +02:00
parent aef835b45c
commit 22e9d25245
2 changed files with 18 additions and 6 deletions

View File

@ -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);

View File

@ -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 {
* </OL>
*/
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