use of com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent in project intellij-community by JetBrains.
the class VfsImplUtil method checkSubscription.
private static void checkSubscription() {
if (ourSubscribed.getAndSet(true))
return;
Application app = ApplicationManager.getApplication();
app.getMessageBus().connect(app).subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
@Override
public void after(@NotNull List<? extends VFileEvent> events) {
InvalidationState state = null;
synchronized (ourLock) {
for (VFileEvent event : events) {
if (!(event.getFileSystem() instanceof LocalFileSystem))
continue;
// created file should not invalidate + getFile is costly
if (event instanceof VFileCreateEvent)
continue;
if (event instanceof VFilePropertyChangeEvent && !VirtualFile.PROP_NAME.equals(((VFilePropertyChangeEvent) event).getPropertyName())) {
continue;
}
String path = event.getPath();
if (event instanceof VFilePropertyChangeEvent) {
path = ((VFilePropertyChangeEvent) event).getOldPath();
} else if (event instanceof VFileMoveEvent) {
path = ((VFileMoveEvent) event).getOldPath();
}
VirtualFile file = event.getFile();
if (file == null || !file.isDirectory()) {
state = InvalidationState.invalidate(state, path);
} else {
Collection<String> affectedPaths = ourDominatorsMap.get(path);
if (affectedPaths != null) {
// defensive copying; original may be updated on invalidation
affectedPaths = ContainerUtil.newArrayList(affectedPaths);
for (String affectedPath : affectedPaths) {
state = InvalidationState.invalidate(state, affectedPath);
}
}
}
}
}
if (state != null)
state.scheduleRefresh();
}
});
}
use of com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent in project intellij-community by JetBrains.
the class VirtualFileManagerImpl method notifyPropertyChanged.
@Override
public void notifyPropertyChanged(@NotNull final VirtualFile virtualFile, @NotNull final String property, final Object oldValue, final Object newValue) {
final Application application = ApplicationManager.getApplication();
final Runnable runnable = new Runnable() {
@Override
public void run() {
if (virtualFile.isValid() && !application.isDisposed()) {
application.runWriteAction(new Runnable() {
@Override
public void run() {
List<VFilePropertyChangeEvent> events = Collections.singletonList(new VFilePropertyChangeEvent(this, virtualFile, property, oldValue, newValue, false));
BulkFileListener listener = application.getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES);
listener.before(events);
listener.after(events);
}
});
}
}
};
application.invokeLater(runnable, ModalityState.NON_MODAL);
}
use of com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent in project intellij-community by JetBrains.
the class FileContentUtilCore method reparseFiles.
/**
* Forces a reparse of the specified collection of files.
*
* @param files the files to reparse.
*/
public static void reparseFiles(@NotNull final Collection<VirtualFile> files) {
ApplicationManager.getApplication().runWriteAction(() -> {
// files must be processed under one write action to prevent firing event for invalid files.
final Set<VFilePropertyChangeEvent> events = new THashSet<>();
for (VirtualFile file : files) {
saveOrReload(file, events);
}
BulkFileListener publisher = ApplicationManager.getApplication().getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES);
List<VFileEvent> eventList = new ArrayList<>(events);
publisher.before(eventList);
publisher.after(eventList);
});
}
use of com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent in project intellij-community by JetBrains.
the class FileContentUtilCore method saveOrReload.
private static void saveOrReload(VirtualFile file, @NotNull Collection<VFilePropertyChangeEvent> events) {
if (file == null || file.isDirectory() || !file.isValid()) {
return;
}
FileDocumentManager documentManager = FileDocumentManager.getInstance();
if (documentManager.isFileModified(file)) {
Document document = documentManager.getDocument(file);
if (document != null) {
// this can be called e.g. in context of undo, so we shouldn't modify document
documentManager.saveDocumentAsIs(document);
}
}
events.add(new VFilePropertyChangeEvent(FORCE_RELOAD_REQUESTOR, file, VirtualFile.PROP_NAME, file.getName(), file.getName(), false));
}
Aggregations