IDEA-27603 (Indicate which branch is being worked on)
[fedora-idea.git] / platform / vcs-impl / src / com / intellij / openapi / vcs / changes / IgnoredFilesComponent.java
blob5b6a5cf8c9c56ea7e333ae8dcc7bf96e60359bbe
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.vfs.VirtualFile;
20 import com.intellij.openapi.vfs.VirtualFileManager;
21 import com.intellij.openapi.vfs.newvfs.BulkFileListener;
22 import com.intellij.openapi.vfs.newvfs.events.VFileEvent;
23 import org.jetbrains.annotations.NotNull;
25 import java.util.Collections;
26 import java.util.HashSet;
27 import java.util.List;
28 import java.util.Set;
30 public class IgnoredFilesComponent {
31 private final Project myProject;
32 private final Set<IgnoredFileBean> myFilesToIgnore;
34 public IgnoredFilesComponent(final Project project) {
35 myProject = project;
36 myFilesToIgnore = new HashSet<IgnoredFileBean>();
38 project.getMessageBus().connect().subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
39 public void before(List<? extends VFileEvent> events) {}
41 public void after(List<? extends VFileEvent> events) {
42 resetCaches();
44 });
47 public void add(final IgnoredFileBean... filesToIgnore) {
48 synchronized(myFilesToIgnore) {
49 Collections.addAll(myFilesToIgnore, filesToIgnore);
53 public void clear() {
54 synchronized (myFilesToIgnore) {
55 myFilesToIgnore.clear();
58 public boolean isEmpty() {
59 synchronized (myFilesToIgnore) {
60 return myFilesToIgnore.isEmpty();
64 public void set(final IgnoredFileBean... filesToIgnore) {
65 synchronized(myFilesToIgnore) {
66 myFilesToIgnore.clear();
67 Collections.addAll(myFilesToIgnore, filesToIgnore);
71 public IgnoredFileBean[] getFilesToIgnore() {
72 synchronized(myFilesToIgnore) {
73 return myFilesToIgnore.toArray(new IgnoredFileBean[myFilesToIgnore.size()]);
77 private void resetCaches() {
78 synchronized (myFilesToIgnore) {
79 for (IgnoredFileBean bean : myFilesToIgnore) {
80 bean.resetCache();
85 public boolean isIgnoredFile(@NotNull VirtualFile file) {
86 synchronized(myFilesToIgnore) {
87 if (myFilesToIgnore.size() == 0) return false;
89 for(IgnoredFileBean bean: myFilesToIgnore) {
90 if (bean.matchesFile(file)) return true;
92 return false;