@Override public void contentsChanged(VirtualFileEvent event) { if (event.isFromSave()) return; final VirtualFile file = event.getFile(); final Document document = getCachedDocument(file); if (document == null) { myMultiCaster.fileWithNoDocumentChanged(file); return; } if (isBinaryWithDecompiler(file)) { myMultiCaster.fileWithNoDocumentChanged( file); // This will generate PSI event at FileManagerImpl } long documentStamp = document.getModificationStamp(); long oldFileStamp = event.getOldModificationStamp(); if (documentStamp != oldFileStamp) { LOG.info("reload from disk?"); LOG.info(" documentStamp:" + documentStamp); LOG.info(" oldFileStamp:" + oldFileStamp); if (file.isValid() && askReloadFromDisk(file, document)) { reloadFromDisk(document); } } else { reloadFromDisk(document); } }
@Override public void fileDeleted(@NotNull final VirtualFileEvent event) { final VirtualFile vFile = event.getFile(); VirtualFile parent = event.getParent(); final PsiDirectory parentDir = getCachedDirectory(parent); final PsiFile psiFile = myFileManager.getCachedPsiFileInner(vFile); if (psiFile != null) { myFileManager.setViewProvider(vFile, null); if (parentDir != null) { ApplicationManager.getApplication() .runWriteAction( new ExternalChangeAction() { @Override public void run() { PsiTreeChangeEventImpl treeEvent = new PsiTreeChangeEventImpl(myManager); treeEvent.setParent(parentDir); treeEvent.setChild(psiFile); myManager.childRemoved(treeEvent); } }); } else if (parent != null) { handleVfsChangeWithoutPsi(parent); } } else { final PsiDirectory psiDir = myFileManager.getCachedDirectory(vFile); if (psiDir != null) { myFileManager.removeInvalidFilesAndDirs(false); if (parentDir != null) { ApplicationManager.getApplication() .runWriteAction( new ExternalChangeAction() { @Override public void run() { PsiTreeChangeEventImpl treeEvent = new PsiTreeChangeEventImpl(myManager); treeEvent.setParent(parentDir); treeEvent.setChild(psiDir); myManager.childRemoved(treeEvent); } }); } } else if (parent != null) { handleVfsChangeWithoutPsi(parent); } } }
@Override public void fileDeleted(VirtualFileEvent event) { Document doc = getCachedDocument(event.getFile()); if (doc != null) { myTrailingSpacesStripper.documentDeleted(doc); } }
@Override public void beforeFileDeletion(@NotNull VirtualFileEvent event) { final VirtualFile vFile = event.getFile(); VirtualFile parent = vFile.getParent(); final PsiDirectory parentDir = getCachedDirectory(parent); if (parentDir == null) return; // do not notify listeners if parent directory was never accessed via PSI ApplicationManager.getApplication() .runWriteAction( new ExternalChangeAction() { @Override public void run() { if (!vFile.isDirectory()) { PsiFile psiFile = myFileManager.getCachedPsiFile(vFile); if (psiFile != null) { PsiTreeChangeEventImpl treeEvent = new PsiTreeChangeEventImpl(myManager); treeEvent.setParent(parentDir); treeEvent.setChild(psiFile); myManager.beforeChildRemoval(treeEvent); } } else { PsiDirectory psiDir = myFileManager.findDirectory(vFile); if (psiDir != null) { PsiTreeChangeEventImpl treeEvent = new PsiTreeChangeEventImpl(myManager); treeEvent.setParent(parentDir); treeEvent.setChild(psiDir); myManager.beforeChildRemoval(treeEvent); } } } }); }
@Override public void fileCreated(@NotNull VirtualFileEvent event) { final VirtualFile vFile = event.getFile(); ApplicationManager.getApplication() .runWriteAction( new ExternalChangeAction() { @Override public void run() { VirtualFile parent = vFile.getParent(); PsiDirectory parentDir = getCachedDirectory(parent); if (parentDir == null) { // parent directory was never accessed via PSI handleVfsChangeWithoutPsi(vFile); return; } if (!vFile.isDirectory()) { PsiFile psiFile = myFileManager.findFile(vFile); if (psiFile != null && psiFile.getProject() == myManager.getProject()) { PsiTreeChangeEventImpl treeEvent = new PsiTreeChangeEventImpl(myManager); treeEvent.setParent(parentDir); myManager.beforeChildAddition(treeEvent); treeEvent.setChild(psiFile); myManager.childAdded(treeEvent); } } else { PsiDirectory psiDir = myFileManager.findDirectory(vFile); if (psiDir != null && psiDir.getProject() == myManager.getProject()) { PsiTreeChangeEventImpl treeEvent = new PsiTreeChangeEventImpl(myManager); treeEvent.setParent(parentDir); myManager.beforeChildAddition(treeEvent); treeEvent.setChild(psiDir); myManager.childAdded(treeEvent); } } } }); }
@Override public void fileCreated(@NotNull VirtualFileEvent event) { if (GoConstants.VENDOR.equals(event.getFileName()) && event.getFile().isDirectory()) { showVendoringNotification(); } }
private void processEvent(VirtualFileEvent event) { if (event.isFromRefresh() && ANNOTATIONS_XML.equals(event.getFileName())) { dropCache(); notifyChangedExternally(); } }
@Override public void fileDeleted(@NotNull VirtualFileEvent event) { fileChanged(myProject, event.getFile()); }