diff --git a/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileSystemTreeImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileSystemTreeImpl.java index a3e31eabf090..7cbc6fc5beee 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileSystemTreeImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileSystemTreeImpl.java @@ -77,6 +77,7 @@ public class FileSystemTreeImpl implements FileSystemTree { private final Project myProject; private final ArrayList myOkActions = new ArrayList<>(2); private final FileChooserDescriptor myDescriptor; + private final FileTreeModel myFileTreeModel; private final AsyncTreeModel myAsyncTreeModel; private final List myListeners = ContainerUtil.createLockFreeCopyOnWriteList(); @@ -99,10 +100,12 @@ public class FileSystemTreeImpl implements FileSystemTree { myProject = project; if (renderer == null && Registry.is("file.chooser.async.tree.model")) { renderer = new FileRenderer().forTree(); - myAsyncTreeModel = new AsyncTreeModel(new FileTreeModel(descriptor, new FileRefresher(true, 3))); + myFileTreeModel = new FileTreeModel(descriptor, new FileRefresher(true, 3)); + myAsyncTreeModel = new AsyncTreeModel(myFileTreeModel); myTreeStructure = null; } else { + myFileTreeModel = null; myAsyncTreeModel = null; myTreeStructure = new FileTreeStructure(project, descriptor); } @@ -244,7 +247,7 @@ public class FileSystemTreeImpl implements FileSystemTree { public void showHiddens(boolean showHidden) { if (myAsyncTreeModel != null) { myDescriptor.withShowHiddenFiles(showHidden); - //TODO:refresh + if (myFileTreeModel != null) myFileTreeModel.invalidate(); } else { myTreeStructure.showHiddens(showHidden); diff --git a/platform/platform-impl/src/com/intellij/openapi/fileChooser/tree/FileTreeModel.java b/platform/platform-impl/src/com/intellij/openapi/fileChooser/tree/FileTreeModel.java index c3de14d49758..73dd78cab9d5 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileChooser/tree/FileTreeModel.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileChooser/tree/FileTreeModel.java @@ -79,6 +79,17 @@ public final class FileTreeModel extends AbstractTreeModel implements Disposable }); } + public void invalidate() { + invoker.invokeLaterIfNeeded(() -> { + if (roots != null) { + for (Root root : roots) { + root.tree.invalidate(); + } + } + treeStructureChanged(state.path, null, null); + }); + } + @Override public void dispose() { } diff --git a/platform/platform-impl/src/com/intellij/ui/tree/MapBasedTree.java b/platform/platform-impl/src/com/intellij/ui/tree/MapBasedTree.java index 836f286ac969..891bf2ec5702 100644 --- a/platform/platform-impl/src/com/intellij/ui/tree/MapBasedTree.java +++ b/platform/platform-impl/src/com/intellij/ui/tree/MapBasedTree.java @@ -57,6 +57,11 @@ public final class MapBasedTree { this.path = path; } + public void invalidate() { + if (root != null) root.invalidate(); + map.values().forEach(entry -> entry.invalidate()); + } + public void onRemove(@NotNull Consumer consumer) { Consumer old = nodeRemoved; nodeRemoved = old == null ? consumer : old.andThen(consumer); @@ -146,6 +151,7 @@ public final class MapBasedTree { } parent.leaf = children == null; parent.children = guard(newChildren); + parent.valid = true; List> removed = oldChildren; List> inserted = newChildren; @@ -218,6 +224,7 @@ public final class MapBasedTree { private volatile boolean leaf; private volatile List> children; private volatile N loading; + private volatile boolean valid; private Entry(TreePath path, N parent, N node, Boolean leaf) { super(path, node); @@ -225,6 +232,11 @@ public final class MapBasedTree { this.parent = parent; this.leaf = Boolean.TRUE.equals(leaf); if (this.leaf) children = emptyList(); + invalidate(); + } + + public void invalidate() { + valid = leaf; } public N getNode() { @@ -240,7 +252,7 @@ public final class MapBasedTree { } public boolean isLoadingRequired() { - return children == null; + return !valid || children == null; } public int getChildCount() { @@ -272,6 +284,7 @@ public final class MapBasedTree { if (children != null) LOG.warn("MapBasedTree: rewrite loaded nodes"); this.loading = loading; children = loading == null ? emptyList() : singletonList(new Entry<>(this, node, loading, true)); + valid = true; } }