Skip to content

Commit 5dc6b65

Browse files
committed
watcher: move repaint to main thread
1 parent 257ad63 commit 5dc6b65

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

Diff for: app/src/processing/app/Editor.java

+4
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ public void windowActivated(WindowEvent e) {
242242
watcher = null;
243243
}
244244
base.handleActivated(Editor.this);
245+
getTabs().forEach(tab -> tab.reload());
245246
}
246247

247248
// added for 1.0.5
@@ -1723,6 +1724,9 @@ public synchronized void addTab(SketchFile file, String contents) throws IOExcep
17231724
public synchronized void removeTab(SketchFile file) throws IOException {
17241725
int index = findTabIndex(file);
17251726
tabs.remove(index);
1727+
if (index == currentTabIndex) {
1728+
currentTabIndex = currentTabIndex -1;
1729+
}
17261730
}
17271731

17281732
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Diff for: app/src/processing/app/tools/WatchDir.java

+7-10
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,15 @@ public void processEvents(Editor editor) {
153153
}
154154
} catch (IOException e) {}
155155
} else if (kind == ENTRY_DELETE) {
156-
List<EditorTab> tabs = editor.getTabs();
157-
Iterator<EditorTab> iter = tabs.iterator();
158-
while (iter.hasNext()) {
159-
EditorTab tab = iter.next();
160-
if (name.getFileName().toString().equals(tab.getSketchFile().getFileName())) {
161-
try {
162-
editor.removeTab(tab.getSketchFile());
163-
} catch (IOException e) {}
164-
}
156+
try {
157+
Thread.sleep(100);
158+
int index = editor.getSketch().findFileIndex(child.toAbsolutePath().toFile());
159+
editor.removeTab(editor.getSketch().getFile(index));
160+
} catch (Exception e1) {
161+
// Totally fine, if the sleep gets interrupted it means that
162+
// the action was executed in the UI, not externally
165163
}
166164
}
167-
editor.getTabs().forEach(tab -> tab.reload());
168165

169166
// if directory is created, and watching recursively, then
170167
// register it and its sub-directories

0 commit comments

Comments
 (0)