mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
move findArea from ProjectFileListener to ProjectFileNode
This commit is contained in:
@@ -79,7 +79,7 @@ import static com.intellij.openapi.util.io.FileUtil.getLocationRelativeToUserHom
|
||||
import static com.intellij.openapi.vfs.VfsUtilCore.VFS_SEPARATOR_CHAR;
|
||||
import static com.intellij.openapi.vfs.VfsUtilCore.getRelativePath;
|
||||
import static com.intellij.openapi.vfs.VfsUtilCore.isAncestor;
|
||||
import static com.intellij.ui.tree.project.ProjectFileListener.findArea;
|
||||
import static com.intellij.ui.tree.project.ProjectFileNode.findArea;
|
||||
import static java.util.Collections.emptyList;
|
||||
|
||||
public final class ScopeViewTreeModel extends BaseTreeModel<AbstractTreeNode> implements InvokerSupplier {
|
||||
@@ -587,8 +587,8 @@ public final class ScopeViewTreeModel extends BaseTreeModel<AbstractTreeNode> im
|
||||
});
|
||||
if (provider == null) return children;
|
||||
children.addAll(provider.modify(parent, files.stream()
|
||||
.map(file -> new PsiFileNode(getProject(), file, getSettings()))
|
||||
.collect(Collectors.toList()), getSettings()));
|
||||
.map(file -> new PsiFileNode(getProject(), file, getSettings()))
|
||||
.collect(Collectors.toList()), getSettings()));
|
||||
return children;
|
||||
}
|
||||
|
||||
@@ -1017,7 +1017,7 @@ public final class ScopeViewTreeModel extends BaseTreeModel<AbstractTreeNode> im
|
||||
@Nullable
|
||||
RootNode getFirstRoot() {
|
||||
if (!roots.isEmpty()) return roots.get(0);
|
||||
for (Group group: groups.values()) {
|
||||
for (Group group : groups.values()) {
|
||||
RootNode root = group.getFirstRoot();
|
||||
if (root != null) return root;
|
||||
}
|
||||
@@ -1031,7 +1031,7 @@ public final class ScopeViewTreeModel extends BaseTreeModel<AbstractTreeNode> im
|
||||
ModuleRootManager manager = getModuleRootManager(getModule(node.getVirtualFile(), node.getProject()));
|
||||
if (manager == null) return null;
|
||||
// ensure that a content root is not a source root or test root
|
||||
for (VirtualFile file: manager.getSourceRoots()) {
|
||||
for (VirtualFile file : manager.getSourceRoots()) {
|
||||
if (!isAncestor(node.getVirtualFile(), file, true)) return null;
|
||||
}
|
||||
return node;
|
||||
@@ -1050,7 +1050,7 @@ public final class ScopeViewTreeModel extends BaseTreeModel<AbstractTreeNode> im
|
||||
char separator = manager != null && manager.hasModuleGroups() ? VFS_SEPARATOR_CHAR : '.';
|
||||
boolean compactDirectories = parent.getSettings().isCompactDirectories();
|
||||
List<AbstractTreeNode> children = new SmartList<>();
|
||||
for (Group group: groups.values()) {
|
||||
for (Group group : groups.values()) {
|
||||
Object id = group.id;
|
||||
Group single = !compactDirectories ? null : group.getSingleGroup();
|
||||
if (single != null) {
|
||||
|
||||
@@ -2,12 +2,9 @@
|
||||
package com.intellij.ui.tree.project;
|
||||
|
||||
import com.intellij.openapi.extensions.AreaInstance;
|
||||
import com.intellij.openapi.fileTypes.FileTypeRegistry;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ModuleRootEvent;
|
||||
import com.intellij.openapi.roots.ModuleRootListener;
|
||||
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.newvfs.BulkFileListener;
|
||||
import com.intellij.openapi.vfs.newvfs.events.*;
|
||||
@@ -20,10 +17,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.ProjectTopics.PROJECT_ROOTS;
|
||||
import static com.intellij.openapi.util.registry.Registry.is;
|
||||
import static com.intellij.openapi.vfs.VfsUtilCore.isAncestor;
|
||||
import static com.intellij.openapi.vfs.VirtualFileManager.VFS_CHANGES;
|
||||
import static com.intellij.psi.util.PsiUtilCore.getVirtualFile;
|
||||
import static com.intellij.ui.tree.project.ProjectFileNode.findArea;
|
||||
|
||||
public abstract class ProjectFileListener {
|
||||
private final Project project;
|
||||
@@ -43,7 +39,7 @@ public abstract class ProjectFileListener {
|
||||
@Override
|
||||
public void after(@NotNull List<? extends VFileEvent> events) {
|
||||
invoker.invokeLaterIfNeeded(() -> {
|
||||
for (VFileEvent event: events) {
|
||||
for (VFileEvent event : events) {
|
||||
if (event instanceof VFileCreateEvent) {
|
||||
VFileCreateEvent create = (VFileCreateEvent)event;
|
||||
updateFromFile(create.getParent());
|
||||
@@ -127,15 +123,4 @@ public abstract class ProjectFileListener {
|
||||
updateFromFile(file.getParent());
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static AreaInstance findArea(@NotNull VirtualFile file, @Nullable Project project) {
|
||||
if (project == null || project.isDisposed() || !file.isValid()) return null;
|
||||
Module module = ProjectFileIndex.getInstance(project).getModuleForFile(file, false);
|
||||
if (module != null) return module.isDisposed() ? null : module;
|
||||
if (!is("projectView.show.base.dir")) return null;
|
||||
VirtualFile ancestor = project.getBaseDir();
|
||||
// file does not belong to any content root, but it is located under the project directory and not ignored
|
||||
return ancestor == null || FileTypeRegistry.getInstance().isFileIgnored(file) || !isAncestor(ancestor, file, false) ? null : project;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,16 @@
|
||||
package com.intellij.ui.tree.project;
|
||||
|
||||
import com.intellij.openapi.extensions.AreaInstance;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.fileTypes.FileTypeRegistry;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static com.intellij.openapi.util.registry.Registry.is;
|
||||
import static com.intellij.openapi.vfs.VfsUtilCore.isAncestor;
|
||||
|
||||
public interface ProjectFileNode {
|
||||
@NotNull
|
||||
@@ -16,6 +23,17 @@ public interface ProjectFileNode {
|
||||
default boolean contains(@NotNull VirtualFile file, @NotNull AreaInstance area, boolean strict) {
|
||||
Object id = getRootID();
|
||||
if (id instanceof AreaInstance && !id.equals(area)) return false;
|
||||
return VfsUtilCore.isAncestor(getVirtualFile(), file, strict);
|
||||
return isAncestor(getVirtualFile(), file, strict);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static AreaInstance findArea(@NotNull VirtualFile file, @Nullable Project project) {
|
||||
if (project == null || project.isDisposed() || !file.isValid()) return null;
|
||||
Module module = ProjectFileIndex.getInstance(project).getModuleForFile(file, false);
|
||||
if (module != null) return module.isDisposed() ? null : module;
|
||||
if (!is("projectView.show.base.dir")) return null;
|
||||
VirtualFile ancestor = project.getBaseDir();
|
||||
// file does not belong to any content root, but it is located under the project directory and not ignored
|
||||
return ancestor == null || FileTypeRegistry.getInstance().isFileIgnored(file) || !isAncestor(ancestor, file, false) ? null : project;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import java.util.function.Predicate;
|
||||
|
||||
import static com.intellij.openapi.vfs.VfsUtilCore.isAncestor;
|
||||
import static com.intellij.ui.tree.TreePathUtil.pathToCustomNode;
|
||||
import static com.intellij.ui.tree.project.ProjectFileListener.findArea;
|
||||
import static com.intellij.ui.tree.project.ProjectFileNode.findArea;
|
||||
import static java.util.Collections.emptyList;
|
||||
|
||||
public final class ProjectFileTreeModel extends BaseTreeModel<ProjectFileNode> implements InvokerSupplier {
|
||||
@@ -96,7 +96,7 @@ public final class ProjectFileTreeModel extends BaseTreeModel<ProjectFileNode> i
|
||||
if (children.isEmpty()) return emptyList();
|
||||
List<ProjectFileNode> result = new SmartList<>();
|
||||
VirtualFileFilter filter = root.filter;
|
||||
for (Object child: children) {
|
||||
for (Object child : children) {
|
||||
if (child instanceof FileNode && isVisible((FileNode)child, filter)) {
|
||||
result.add((FileNode)child);
|
||||
}
|
||||
@@ -244,8 +244,8 @@ public final class ProjectFileTreeModel extends BaseTreeModel<ProjectFileNode> i
|
||||
list.add(mapper.apply(ancestor, project));
|
||||
}
|
||||
}
|
||||
for (Module module: getModules(project)) {
|
||||
for (VirtualFile file: getContentRoots(module)) {
|
||||
for (Module module : getModules(project)) {
|
||||
for (VirtualFile file : getContentRoots(module)) {
|
||||
if (collector != null) {
|
||||
collector.add(file);
|
||||
}
|
||||
@@ -305,7 +305,7 @@ public final class ProjectFileTreeModel extends BaseTreeModel<ProjectFileNode> i
|
||||
|
||||
List<FileNode> list = new SmartList<>();
|
||||
Mapper<FileNode> mapper = new Mapper<>(oldList, FileNode::new);
|
||||
for (VirtualFile child: children) {
|
||||
for (VirtualFile child : children) {
|
||||
if (child.is(VFileProperty.SYMLINK) && VfsUtilCore.isInvalidLink(child)) {
|
||||
continue; // ignore invalid symlink
|
||||
}
|
||||
@@ -324,7 +324,7 @@ public final class ProjectFileTreeModel extends BaseTreeModel<ProjectFileNode> i
|
||||
validator = null; // all children will be invalid
|
||||
valid = false;
|
||||
}
|
||||
for (FileNode node: children) {
|
||||
for (FileNode node : children) {
|
||||
node.invalidateChildren(validator);
|
||||
}
|
||||
}
|
||||
@@ -348,7 +348,7 @@ public final class ProjectFileTreeModel extends BaseTreeModel<ProjectFileNode> i
|
||||
boolean invalidate(VirtualFile file) {
|
||||
List<VirtualFile> list = accumulator;
|
||||
if (!list.isEmpty()) {
|
||||
for (VirtualFile ancestor: list) {
|
||||
for (VirtualFile ancestor : list) {
|
||||
if (isAncestor(ancestor, file, false)) {
|
||||
return false; // the file or its parent is already added
|
||||
}
|
||||
@@ -374,7 +374,7 @@ public final class ProjectFileTreeModel extends BaseTreeModel<ProjectFileNode> i
|
||||
List<FileNode> list = new SmartList<>();
|
||||
invalidateNow(node -> list.add(node));
|
||||
if (parent.filter == null) {
|
||||
for (FileNode node: list) {
|
||||
for (FileNode node : list) {
|
||||
TreePath path = pathToCustomNode((Node)node, child -> child.parent);
|
||||
if (path != null) consumer.accept(path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user