Search in sources :

Example 6 with VFileEvent

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

the class GitRepositoryUpdater method after.

@Override
public void after(@NotNull List<? extends VFileEvent> events) {
    // which files in .git were changed
    boolean configChanged = false;
    boolean headChanged = false;
    boolean branchFileChanged = false;
    boolean packedRefsChanged = false;
    boolean rebaseFileChanged = false;
    boolean mergeFileChanged = false;
    boolean tagChanged = false;
    for (VFileEvent event : events) {
        String filePath = GitFileUtils.stripFileProtocolPrefix(event.getPath());
        if (myRepositoryFiles.isConfigFile(filePath)) {
            configChanged = true;
        } else if (myRepositoryFiles.isHeadFile(filePath)) {
            headChanged = true;
        } else if (myRepositoryFiles.isBranchFile(filePath)) {
            // it is also possible, that a local branch with complex name ("folder/branch") was created => the folder also to be watched.
            branchFileChanged = true;
            DvcsUtil.ensureAllChildrenInVfs(myHeadsDir);
        } else if (myRepositoryFiles.isRemoteBranchFile(filePath)) {
            // it is possible, that a branch from a new remote was fetch => we need to add new remote folder to the VFS
            branchFileChanged = true;
            DvcsUtil.ensureAllChildrenInVfs(myRemotesDir);
        } else if (myRepositoryFiles.isPackedRefs(filePath)) {
            packedRefsChanged = true;
        } else if (myRepositoryFiles.isRebaseFile(filePath)) {
            rebaseFileChanged = true;
        } else if (myRepositoryFiles.isMergeFile(filePath)) {
            mergeFileChanged = true;
        } else if (myRepositoryFiles.isTagFile(filePath)) {
            DvcsUtil.ensureAllChildrenInVfs(myTagsDir);
            tagChanged = true;
        }
    }
    if (headChanged || configChanged || branchFileChanged || packedRefsChanged || rebaseFileChanged || mergeFileChanged) {
        myUpdateQueue.add(DUMMY_UPDATE_OBJECT);
    } else if (tagChanged) {
        myRepository.getProject().getMessageBus().syncPublisher(GitRepository.GIT_REPO_CHANGE).repositoryChanged(myRepository);
    }
}
Also used : VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent)

Example 7 with VFileEvent

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

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

the class JrtFileSystemImpl method checkSubscription.

private void checkSubscription() {
    if (mySubscribed.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) {
            Set<VirtualFile> toRefresh = null;
            for (VFileEvent event : events) {
                if (event.getFileSystem() instanceof LocalFileSystem && event instanceof VFileContentChangeEvent) {
                    VirtualFile file = event.getFile();
                    if (file != null && "release".equals(file.getName())) {
                        String homePath = file.getParent().getPath();
                        ArchiveHandler handler = myHandlers.remove(homePath);
                        if (handler != null) {
                            handler.dispose();
                            VirtualFile root = findFileByPath(composeRootPath(homePath));
                            if (root != null) {
                                ((NewVirtualFile) root).markDirtyRecursively();
                                if (toRefresh == null)
                                    toRefresh = ContainerUtil.newHashSet();
                                toRefresh.add(root);
                            }
                        }
                    }
                }
            }
            if (toRefresh != null) {
                boolean async = !ApplicationManager.getApplication().isUnitTestMode();
                RefreshQueue.getInstance().refresh(async, true, null, toRefresh);
            }
        }
    });
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArchiveHandler(com.intellij.openapi.vfs.impl.ArchiveHandler) Set(java.util.Set) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) VFileContentChangeEvent(com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener) Application(com.intellij.openapi.application.Application)

Example 9 with VFileEvent

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

the class RefResolveServiceImpl method initListeners.

private void initListeners(@NotNull MessageBus messageBus, @NotNull PsiManager psiManager) {
    messageBus.connect().subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {

        @Override
        public void after(@NotNull List<? extends VFileEvent> events) {
            fileCount.set(0);
            List<VirtualFile> files = ContainerUtil.mapNotNull(events, new Function<VFileEvent, VirtualFile>() {

                @Override
                public VirtualFile fun(VFileEvent event) {
                    return event.getFile();
                }
            });
            queue(files, "VFS events " + events.size());
        }
    });
    psiManager.addPsiTreeChangeListener(new PsiTreeChangeAdapter() {

        @Override
        public void childrenChanged(@NotNull PsiTreeChangeEvent event) {
            PsiFile file = event.getFile();
            VirtualFile virtualFile = PsiUtilCore.getVirtualFile(file);
            if (virtualFile != null) {
                queue(Collections.singletonList(virtualFile), event);
            }
        }

        @Override
        public void propertyChanged(@NotNull PsiTreeChangeEvent event) {
            childrenChanged(event);
        }
    });
    messageBus.connect().subscribe(DumbService.DUMB_MODE, new DumbService.DumbModeListener() {

        @Override
        public void enteredDumbMode() {
            disable();
        }

        @Override
        public void exitDumbMode() {
            enable();
        }
    });
    messageBus.connect().subscribe(PowerSaveMode.TOPIC, new PowerSaveMode.Listener() {

        @Override
        public void powerSaveStateChanged() {
            if (PowerSaveMode.isEnabled()) {
                enable();
            } else {
                disable();
            }
        }
    });
    myApplication.addApplicationListener(new ApplicationAdapter() {

        @Override
        public void beforeWriteActionStart(@NotNull Object action) {
            disable();
        }

        @Override
        public void writeActionFinished(@NotNull Object action) {
            enable();
        }

        @Override
        public void applicationExiting() {
            disable();
        }
    }, this);
    VirtualFileManager.getInstance().addVirtualFileManagerListener(new VirtualFileManagerListener() {

        @Override
        public void beforeRefreshStart(boolean asynchronous) {
            disable();
        }

        @Override
        public void afterRefreshFinish(boolean asynchronous) {
            enable();
        }
    }, this);
    HeavyProcessLatch.INSTANCE.addListener(new HeavyProcessLatch.HeavyProcessListener() {

        @Override
        public void processStarted() {
        }

        @Override
        public void processFinished() {
            wakeUp();
        }
    }, this);
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener) PowerSaveMode(com.intellij.ide.PowerSaveMode) Function(com.intellij.util.Function) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) HeavyProcessLatch(com.intellij.util.io.storage.HeavyProcessLatch) ApplicationAdapter(com.intellij.openapi.application.ApplicationAdapter)

Example 10 with VFileEvent

use of com.intellij.openapi.vfs.newvfs.events.VFileEvent in project android by JetBrains.

the class CapturesToolWindow method after.

@Override
public void after(@NotNull List<? extends VFileEvent> events) {
    CaptureService service = CaptureService.getInstance(myProject);
    VirtualFile captures = service.getCapturesDirectory();
    if (captures == null) {
        if (!service.getCaptures().isEmpty()) {
            queueUpdate();
        }
        return;
    }
    for (VFileEvent event : events) {
        if (event.getFile() != null && VfsUtilCore.isAncestor(captures, event.getFile(), false)) {
            queueUpdate();
            return;
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) CaptureService(com.android.tools.idea.profiling.capture.CaptureService)

Aggregations

VFileEvent (com.intellij.openapi.vfs.newvfs.events.VFileEvent)16 VFileCreateEvent (com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 BulkFileListener (com.intellij.openapi.vfs.newvfs.BulkFileListener)5 VFileContentChangeEvent (com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent)5 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)5 File (java.io.File)4 VFileDeleteEvent (com.intellij.openapi.vfs.newvfs.events.VFileDeleteEvent)3 GeneralSettings (com.intellij.ide.GeneralSettings)2 Application (com.intellij.openapi.application.Application)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 WriteAction (com.intellij.openapi.application.WriteAction)2 SystemInfo (com.intellij.openapi.util.SystemInfo)2 FileAttributes (com.intellij.openapi.util.io.FileAttributes)2 FileSystemUtil (com.intellij.openapi.util.io.FileSystemUtil)2 FileUtil (com.intellij.openapi.util.io.FileUtil)2 IoTestUtil (com.intellij.openapi.util.io.IoTestUtil)2 StringUtil (com.intellij.openapi.util.text.StringUtil)2 com.intellij.openapi.vfs (com.intellij.openapi.vfs)2 LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)2