Search in sources :

Example 1 with VFilePropertyChangeEvent

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();
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VFilePropertyChangeEvent(com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent) VFileCreateEvent(com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent) VFileMoveEvent(com.intellij.openapi.vfs.newvfs.events.VFileMoveEvent) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) Collection(java.util.Collection) Application(com.intellij.openapi.application.Application)

Example 2 with VFilePropertyChangeEvent

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);
}
Also used : VFilePropertyChangeEvent(com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener) ArrayList(java.util.ArrayList) List(java.util.List) Application(com.intellij.openapi.application.Application)

Example 3 with VFilePropertyChangeEvent

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);
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) VFilePropertyChangeEvent(com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener) THashSet(gnu.trove.THashSet)

Example 4 with VFilePropertyChangeEvent

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));
}
Also used : VFilePropertyChangeEvent(com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Document(com.intellij.openapi.editor.Document)

Aggregations

VFilePropertyChangeEvent (com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent)4 Application (com.intellij.openapi.application.Application)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 BulkFileListener (com.intellij.openapi.vfs.newvfs.BulkFileListener)2 VFileEvent (com.intellij.openapi.vfs.newvfs.events.VFileEvent)2 Document (com.intellij.openapi.editor.Document)1 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1 LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)1 VFileCreateEvent (com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent)1 VFileMoveEvent (com.intellij.openapi.vfs.newvfs.events.VFileMoveEvent)1 THashSet (gnu.trove.THashSet)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1