1 package com
.intellij
.openapi
.vcs
.changes
;
3 import com
.intellij
.openapi
.application
.ApplicationManager
;
4 import com
.intellij
.openapi
.components
.ApplicationComponent
;
5 import com
.intellij
.openapi
.project
.Project
;
6 import com
.intellij
.openapi
.project
.ProjectLocator
;
7 import com
.intellij
.openapi
.vcs
.FilePathImpl
;
8 import com
.intellij
.openapi
.vfs
.*;
9 import org
.jetbrains
.annotations
.NotNull
;
10 import org
.jetbrains
.annotations
.Nullable
;
14 public class VcsDirtyScopeVfsListener
extends VirtualFileAdapter
implements ApplicationComponent
{
15 private final ProjectLocator myProjectLocator
;
17 public VcsDirtyScopeVfsListener() {
18 myProjectLocator
= ProjectLocator
.getInstance();
22 public String
getComponentName() {
23 return VcsDirtyScopeVfsListener
.class.getName();
26 public void initComponent() {
27 VirtualFileManager
.getInstance().addVirtualFileListener(this, ApplicationManager
.getApplication());
30 public void disposeComponent() {
31 VirtualFileManager
.getInstance().removeVirtualFileListener(this);
35 VcsDirtyScopeManager
getManager(final VirtualFileEvent event
) {
36 final Project project
= myProjectLocator
.guessProjectForFile(event
.getFile());
37 if (project
== null) return null;
38 return VcsDirtyScopeManager
.getInstance(project
);
42 public void contentsChanged(VirtualFileEvent event
) {
43 final VcsDirtyScopeManager manager
= getManager(event
);
44 if (manager
!= null) {
45 manager
.fileDirty(event
.getFile());
50 public void propertyChanged(VirtualFilePropertyEvent event
) {
51 final VcsDirtyScopeManager manager
= getManager(event
);
52 if (manager
!= null) {
53 if (event
.getPropertyName().equals(VirtualFile
.PROP_NAME
)) {
54 VirtualFile renamed
= event
.getFile();
55 if (renamed
.getParent() != null) {
56 renamed
= renamed
.getParent();
58 dirtyFileOrDir(manager
, renamed
);
61 manager
.fileDirty(event
.getFile());
66 private static void dirtyFileOrDir(@NotNull final VcsDirtyScopeManager manager
, final VirtualFile file
) {
67 if (file
.isDirectory()) {
68 manager
.dirDirtyRecursively(file
);
71 manager
.fileDirty(file
);
76 public void fileCreated(VirtualFileEvent event
) {
77 final VcsDirtyScopeManager manager
= getManager(event
);
78 if (manager
!= null) {
79 manager
.fileDirty(event
.getFile());
84 public void beforePropertyChange(VirtualFilePropertyEvent event
) {
85 final VcsDirtyScopeManager manager
= getManager(event
);
86 if (manager
!= null) {
87 manager
.fileDirty(event
.getFile());
92 public void beforeFileDeletion(VirtualFileEvent event
) {
93 if (!event
.getFile().isInLocalFileSystem()) return;
95 final VcsDirtyScopeManager manager
= getManager(event
);
96 if (manager
!= null) {
97 // need to keep track of whether the deleted file was a directory
98 final boolean directory
= event
.getFile().isDirectory();
99 final FilePathImpl path
= new FilePathImpl(new File(event
.getFile().getPath()), directory
);
101 manager
.dirDirtyRecursively(path
); // IDEADEV-12752
104 manager
.fileDirty(path
);
110 public void beforeFileMovement(VirtualFileMoveEvent event
) {
111 final VcsDirtyScopeManager manager
= getManager(event
);
112 if (manager
!= null) {
113 // need to create FilePath explicitly without referring to VirtualFile because otherwise the FilePath
114 // will reference the path after the move
115 manager
.fileDirty(new FilePathImpl(new File(event
.getFile().getPath()), event
.getFile().isDirectory()));
120 public void fileMoved(VirtualFileMoveEvent event
) {
121 final VcsDirtyScopeManager manager
= getManager(event
);
122 if (manager
!= null) {
123 dirtyFileOrDir(manager
, event
.getFile());