VCS: vcs dirty scope manager to use application-level vfs listener and check what...
[fedora-idea.git] / vcs-impl / src / com / intellij / openapi / vcs / impl / BasicDefaultVcsRootPolicy.java
blobe35fdefeda841981a233ddb4ab0fc4a02a2132f6
1 package com.intellij.openapi.vcs.impl;
3 import com.intellij.openapi.project.Project;
4 import com.intellij.openapi.vcs.AbstractVcs;
5 import com.intellij.openapi.vcs.FilePathImpl;
6 import com.intellij.openapi.vcs.changes.DirtBuilder;
7 import com.intellij.openapi.vcs.changes.VcsGuess;
8 import com.intellij.openapi.vcs.changes.FilePathUnderVcs;
9 import com.intellij.openapi.vcs.impl.projectlevelman.NewMappings;
10 import com.intellij.openapi.vfs.VfsUtil;
11 import com.intellij.openapi.vfs.VirtualFile;
12 import com.intellij.platform.ProjectBaseDirectory;
13 import org.jetbrains.annotations.Nullable;
15 import java.util.List;
17 /**
18 * @author yole
20 public class BasicDefaultVcsRootPolicy extends DefaultVcsRootPolicy {
21 private final Project myProject;
22 private final VirtualFile myBaseDir;
24 public BasicDefaultVcsRootPolicy(Project project) {
25 myProject = project;
26 myBaseDir = project.getBaseDir();
29 public void addDefaultVcsRoots(final NewMappings mappingList, final AbstractVcs vcs, final List<VirtualFile> result) {
30 final VirtualFile baseDir = ProjectBaseDirectory.getInstance(myProject).getBaseDir(myBaseDir);
31 if (baseDir != null && vcs.getName().equals(mappingList.getVcsFor(baseDir))) {
32 result.add(baseDir);
36 public boolean matchesDefaultMapping(final VirtualFile file, final Object matchContext) {
37 return VfsUtil.isAncestor(ProjectBaseDirectory.getInstance(myProject).getBaseDir(myBaseDir), file, false);
40 @Nullable
41 public Object getMatchContext(final VirtualFile file) {
42 return null;
45 @Nullable
46 public VirtualFile getVcsRootFor(final VirtualFile file) {
47 return ProjectBaseDirectory.getInstance(myProject).getBaseDir(myBaseDir);
50 public void markDefaultRootsDirty(final DirtBuilder builder, final VcsGuess vcsGuess) {
51 final FilePathImpl fp = new FilePathImpl(ProjectBaseDirectory.getInstance(myProject).getBaseDir(myBaseDir));
52 final AbstractVcs vcs = vcsGuess.getVcsForDirty(fp);
53 if (vcs != null) {
54 builder.addDirtyDirRecursively(new FilePathUnderVcs(fp, vcs));