ComponentWithBrowseButton - optional remove listener on hide
[fedora-idea.git] / platform / vcs-impl / src / com / intellij / openapi / vcs / changes / Scopes.java
blob568d9f8b183084c426600147efa6a7514118b50d
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.openapi.vcs.changes;
18 import com.intellij.openapi.project.Project;
19 import com.intellij.openapi.vcs.AbstractVcs;
20 import com.intellij.openapi.vcs.FilePath;
21 import com.intellij.openapi.vcs.impl.DefaultVcsRootPolicy;
22 import org.jetbrains.annotations.NotNull;
24 import java.util.*;
26 public class Scopes {
27 private final Project myProject;
28 private final VcsGuess myGuess;
30 private boolean myEverythingDirty;
31 private final Map<AbstractVcs, VcsDirtyScopeImpl> myScopes;
33 public Scopes(final Project project, final VcsGuess guess) {
34 myProject = project;
35 myGuess = guess;
36 myScopes = new HashMap<AbstractVcs, VcsDirtyScopeImpl>();
39 private void markEverythingDirty() {
40 myScopes.clear();
41 myEverythingDirty = true;
42 final DirtBuilder builder = new DirtBuilder(myGuess);
43 DefaultVcsRootPolicy.getInstance(myProject).markDefaultRootsDirty(builder, myGuess);
44 takeDirt(builder);
47 public void takeDirt(final DirtBuilderReader dirt) {
48 if (dirt.isEverythingDirty()) {
49 markEverythingDirty();
50 return;
52 final Collection<FilePathUnderVcs> dirs = dirt.getDirsForVcs();
53 for (FilePathUnderVcs dir : dirs) {
54 getScope(dir.getVcs()).addDirtyDirRecursively(dir.getPath());
56 final Collection<FilePathUnderVcs> files = dirt.getFilesForVcs();
57 for (FilePathUnderVcs file : files) {
58 getScope(file.getVcs()).addDirtyFile(file.getPath());
62 public void addDirtyDirRecursively(@NotNull final AbstractVcs vcs, @NotNull final FilePath newcomer) {
63 getScope(vcs).addDirtyDirRecursively(newcomer);
66 public void addDirtyFile(@NotNull final AbstractVcs vcs, @NotNull final FilePath newcomer) {
67 getScope(vcs).addDirtyFile(newcomer);
70 @NotNull
71 public VcsInvalidated retrieveAndClear() {
72 final ArrayList<VcsDirtyScope> scopesList = new ArrayList<VcsDirtyScope>(myScopes.values());
73 final VcsInvalidated result = new VcsInvalidated(scopesList, myEverythingDirty);
74 myEverythingDirty = false;
75 myScopes.clear();
76 return result;
79 private VcsDirtyScopeImpl getScope(final AbstractVcs vcs) {
80 VcsDirtyScopeImpl scope = myScopes.get(vcs);
81 if (scope == null) {
82 scope = new VcsDirtyScopeImpl(vcs, myProject);
83 myScopes.put(vcs, scope);
85 return scope;