Search in sources :

Example 1 with VFileCreateEvent

use of com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent in project intellij-community by JetBrains.

the class PushedFilePropertiesUpdaterImpl method processAfterVfsChanges.

public void processAfterVfsChanges(@NotNull List<? extends VFileEvent> events) {
    boolean pushedSomething = false;
    List<Runnable> delayedTasks = ContainerUtil.newArrayList();
    for (VFileEvent event : events) {
        VirtualFile file = event.getFile();
        if (event instanceof VFileCopyEvent) {
            file = ((VFileCopyEvent) event).getNewParent().findChild(((VFileCopyEvent) event).getNewChildName());
        }
        if (file == null)
            continue;
        final FilePropertyPusher[] pushers = file.isDirectory() ? myPushers : myFilePushers;
        if (pushers.length == 0)
            continue;
        if (event instanceof VFileCreateEvent) {
            if (!event.isFromRefresh() || !file.isDirectory()) {
                // push synchronously to avoid entering dumb mode in the middle of a meaningful write action
                // avoid dumb mode for just one file
                doPushRecursively(file, pushers, ProjectRootManager.getInstance(myProject).getFileIndex());
                pushedSomething = true;
            } else if (!ProjectUtil.isProjectOrWorkspaceFile(file)) {
                ContainerUtil.addIfNotNull(delayedTasks, createRecursivePushTask(file, pushers));
            }
        } else if (event instanceof VFileMoveEvent || event instanceof VFileCopyEvent) {
            for (FilePropertyPusher<?> pusher : pushers) {
                file.putUserData(pusher.getFileDataKey(), null);
            }
            // push synchronously to avoid entering dumb mode in the middle of a meaningful write action
            doPushRecursively(file, pushers, ProjectRootManager.getInstance(myProject).getFileIndex());
            pushedSomething = true;
        }
    }
    if (!delayedTasks.isEmpty()) {
        queueTasks(delayedTasks);
    }
    if (pushedSomething) {
        GuiUtils.invokeLaterIfNeeded(() -> scheduleDumbModeReindexingIfNeeded(), ModalityState.defaultModalityState());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) EmptyRunnable(com.intellij.openapi.util.EmptyRunnable) VFileCopyEvent(com.intellij.openapi.vfs.newvfs.events.VFileCopyEvent) VFileCreateEvent(com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent) VFileMoveEvent(com.intellij.openapi.vfs.newvfs.events.VFileMoveEvent)

Example 2 with VFileCreateEvent

use of com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent 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 3 with VFileCreateEvent

use of com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent in project intellij-leiningen-plugin by derkork.

the class LeiningenProjectsManagerWatcher method start.

public synchronized void start() {
    final MessageBusConnection myBusConnection = project.getMessageBus().connect(myQueue);
    myBusConnection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {

        public void before(List<? extends VFileEvent> vFileEvents) {
        }

        public void after(List<? extends VFileEvent> vFileEvents) {
            for (VFileEvent vFileEvent : vFileEvents) {
                //                    }
                if (vFileEvent instanceof VFileCreateEvent) {
                    if (isRelevant(vFileEvent.getPath())) {
                        manager.importLeiningenProject(vFileEvent.getFileSystem().findFileByPath(vFileEvent.getPath()), project);
                    }
                }
            }
        }

        private boolean isRelevant(String path) {
            return path != null && path.endsWith(LeiningenConstants.PROJECT_CLJ);
        }
    });
    myBusConnection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {

        public void beforeRootsChange(ModuleRootEvent moduleRootEvent) {
        }

        public void rootsChanged(ModuleRootEvent moduleRootEvent) {
        }
    });
    myQueue.activate();
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener) ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent) VFileCreateEvent(com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent) ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener)

Example 4 with VFileCreateEvent

use of com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent in project intellij-community by JetBrains.

the class VirtualDirectoryImpl method createAndFindChildWithEventFire.

@Nullable
private VirtualFileSystemEntry createAndFindChildWithEventFire(@NotNull String name, @NotNull NewVirtualFileSystem delegate) {
    final VirtualFile fake = new FakeVirtualFile(this, name);
    final FileAttributes attributes = delegate.getAttributes(fake);
    if (attributes == null)
        return null;
    final String realName = delegate.getCanonicallyCasedName(fake);
    final VFileCreateEvent event = new VFileCreateEvent(null, this, realName, attributes.isDirectory(), true);
    RefreshQueue.getInstance().processSingleEvent(event);
    return findChild(realName);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) VFileCreateEvent(com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent) FileAttributes(com.intellij.openapi.util.io.FileAttributes) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with VFileCreateEvent

use of com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent in project intellij-community by JetBrains.

the class LocalFileSystemTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(getTestRootDisposable());
    connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {

        @Override
        public void before(@NotNull List<? extends VFileEvent> events) {
            checkFiles(events, true);
        }

        @Override
        public void after(@NotNull List<? extends VFileEvent> events) {
            checkFiles(events, false);
        }

        private void checkFiles(List<? extends VFileEvent> events, boolean before) {
            for (VFileEvent event : events) {
                VirtualFile file = event.getFile();
                if (file != null) {
                    boolean shouldBeInvalid = event instanceof VFileCreateEvent && before && !((VFileCreateEvent) event).isReCreation() || event instanceof VFileDeleteEvent && !before;
                    assertEquals(event.toString(), !shouldBeInvalid, file.isValid());
                }
            }
        }
    });
    myFS = LocalFileSystem.getInstance();
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) VFileCreateEvent(com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent) VFileDeleteEvent(com.intellij.openapi.vfs.newvfs.events.VFileDeleteEvent)

Aggregations

VFileCreateEvent (com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent)6 VFileEvent (com.intellij.openapi.vfs.newvfs.events.VFileEvent)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 VFileMoveEvent (com.intellij.openapi.vfs.newvfs.events.VFileMoveEvent)2 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)2 MockVirtualFile (com.intellij.mock.MockVirtualFile)1 Application (com.intellij.openapi.application.Application)1 ModuleRootEvent (com.intellij.openapi.roots.ModuleRootEvent)1 ModuleRootListener (com.intellij.openapi.roots.ModuleRootListener)1 EmptyRunnable (com.intellij.openapi.util.EmptyRunnable)1 FileAttributes (com.intellij.openapi.util.io.FileAttributes)1 LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)1 BulkFileListener (com.intellij.openapi.vfs.newvfs.BulkFileListener)1 NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)1 VFileCopyEvent (com.intellij.openapi.vfs.newvfs.events.VFileCopyEvent)1 VFileDeleteEvent (com.intellij.openapi.vfs.newvfs.events.VFileDeleteEvent)1 VFilePropertyChangeEvent (com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1