Skip to content

Commit 22e9d25

Browse files
author
Federico Fissore
committed
Update sketch code when editing with an external editor and IDE gets focus. Fixes #1778
1 parent aef835b commit 22e9d25

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

app/src/processing/app/Base.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,13 @@ protected void storeRecentSketches(Sketch sketch) {
623623
protected void handleActivated(Editor whichEditor) {
624624
activeEditor = whichEditor;
625625
activeEditor.rebuildRecentSketchesMenu();
626+
if (PreferencesData.getBoolean("editor.external")) {
627+
try {
628+
activeEditor.getSketch().load(true);
629+
} catch (IOException e) {
630+
// noop
631+
}
632+
}
626633

627634
// set the current window to be the console that's getting output
628635
EditorConsoleStream.setCurrent(activeEditor.console);

app/src/processing/app/Sketch.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ public Sketch(Editor _editor, File file) throws IOException {
108108
* in which case the load happens each time "run" is hit.
109109
*/
110110
protected void load() throws IOException {
111+
load(false);
112+
}
113+
114+
protected void load(boolean forceUpdate) throws IOException {
111115
data.load();
112116

113117
for (SketchCode code : data.getCodes()) {
@@ -117,7 +121,7 @@ protected void load() throws IOException {
117121

118122
// set the main file to be the current tab
119123
if (editor != null) {
120-
setCurrentCode(0);
124+
setCurrentCode(currentIndex, forceUpdate);
121125
}
122126
}
123127

@@ -979,8 +983,12 @@ public void importLibrary(File jarPath) throws IOException {
979983
* </OL>
980984
*/
981985
public void setCurrentCode(int which) {
986+
setCurrentCode(which, false);
987+
}
988+
989+
public void setCurrentCode(int which, boolean forceUpdate) {
982990
// if current is null, then this is the first setCurrent(0)
983-
if ((currentIndex == which) && (current != null)) {
991+
if (!forceUpdate && (currentIndex == which) && (current != null)) {
984992
return;
985993
}
986994

@@ -1065,11 +1073,8 @@ public void prepare() throws IOException {
10651073
//handleOpen(sketch);
10661074
//history.lastRecorded = historySaved;
10671075

1068-
// set current to null so that the tab gets updated
1069-
// http://dev.processing.org/bugs/show_bug.cgi?id=515
1070-
current = null;
10711076
// nuke previous files and settings, just get things loaded
1072-
load();
1077+
load(true);
10731078
}
10741079

10751080
// // handle preprocessing the main file's code

0 commit comments

Comments
 (0)