diff --git a/app/src/processing/app/ChangeDetector.java b/app/src/processing/app/ChangeDetector.java index 024c7a10b..3895b924f 100644 --- a/app/src/processing/app/ChangeDetector.java +++ b/app/src/processing/app/ChangeDetector.java @@ -15,7 +15,8 @@ public class ChangeDetector implements WindowFocusListener { private Sketch sketch; private Editor editor; - private boolean enabled = true; + // Set true if the user selected 'no'. TODO this can't just skip once, + // because subsequent returns to the window w/o saving will keep firing. private boolean skip = false; @@ -25,6 +26,34 @@ public class ChangeDetector implements WindowFocusListener { } + @Override + public void windowGainedFocus(WindowEvent e) { + // Keep the listener instantiated and check this to avoid a maze of + // adding and removing and re-adding with Preferences changes. + if (Preferences.getBoolean("editor.watcher")) { + // if they selected no, skip the next focus event + if (skip) { + skip = false; + + } else { + new Thread(new Runnable() { + @Override + public void run() { + checkFileChange(); + } + }).start(); + } + } + } + + + @Override + public void windowLostFocus(WindowEvent e) { + // Shouldn't need to do anything here, and not storing anything here b/c we + // don't want to assume a loss of focus is required before change detection + } + + private void checkFileChange() { //check that the content of each of the files in sketch matches what is in memory if (sketch == null) { @@ -143,36 +172,6 @@ public class ChangeDetector implements WindowFocusListener { } - @Override - public void windowLostFocus(WindowEvent e) { - //shouldn't need to do anything here - } - - - @Override - public void windowGainedFocus(WindowEvent e) { - if (enabled) { - //remove the detector from main if it is disabled during runtime (due to an error?) - //if (!enabled || !Preferences.getBoolean("editor.watcher")) { - //editor.removeWindowFocusListener(this); - //} else if (skip) { - - // if they selected no, skip the next focus event - if (skip) { - skip = false; - - } else { - new Thread(new Runnable() { - @Override - public void run() { - checkFileChange(); - } - }).start(); - } - } - } - - private void showErrorEDT(final String title, final String message, final Exception e) { EventQueue.invokeLater(new Runnable() { diff --git a/build/shared/lib/defaults.txt b/build/shared/lib/defaults.txt index 350cad614..a1ff701e8 100644 --- a/build/shared/lib/defaults.txt +++ b/build/shared/lib/defaults.txt @@ -148,7 +148,7 @@ editor.tabs.size = 2 # automatically indent each line editor.indent = true -# Whether to automatically reload modified tabs +# Whether to check files to see if they've been modified externally editor.watcher = true # Hide the background image. Gross because this is a pref that diff --git a/todo.txt b/todo.txt index a60a9c4e7..5489199f5 100644 --- a/todo.txt +++ b/todo.txt @@ -29,6 +29,8 @@ X https://github.com/processing/processing/commit/0a14835e6f5f4766b022e73a8fe5 X the .macosx, .linux, etc prefs should be stripped X only use them on first load, and merge into preferences.txt X auto-insert after antlr @SuppressWarnings({ "unused", "unchecked", "cast" }) +X fix file change detection on OS X +X https://github.com/processing/processing/issues/2852 _ editor window draws in stages (at least on OS X) on first view _ "sketch modified" message still happening @@ -270,8 +272,6 @@ _ how are we going to handle fonts for other languages? _ two new fonts have been added, other languages will need more _ need a decent sans with with Unicode coverage _ i.e. https://github.com/processing/processing/pull/3025 -_ fix file change detection on OS X -_ https://github.com/processing/processing/issues/2852 _ make examples pull/build automatic during dist _ add span screens pref (near the display pref) _ add checkbox for spans to export dialog