Search in sources :

Example 6 with MessageBusConnection

use of com.intellij.util.messages.MessageBusConnection in project intellij-community by JetBrains.

the class SvnVcs method upgradeIfNeeded.

private void upgradeIfNeeded(final MessageBus bus) {
    final MessageBusConnection connection = bus.connect();
    connection.subscribe(ChangeListManagerImpl.LISTS_LOADED, lists -> {
        if (lists.isEmpty())
            return;
        try {
            ChangeListManager.getInstance(myProject).setReadOnly(LocalChangeList.DEFAULT_NAME, true);
            if (!myConfiguration.changeListsSynchronized()) {
                processChangeLists(lists);
            }
        } catch (ProcessCanceledException e) {
        } finally {
            myConfiguration.upgrade();
        }
        connection.disconnect();
    });
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 7 with MessageBusConnection

use of com.intellij.util.messages.MessageBusConnection in project intellij-community by JetBrains.

the class BreadcrumbsInitializingActivity method runActivity.

@Override
public void runActivity(@NotNull Project project) {
    if (project.isDefault()) {
        return;
    }
    MessageBusConnection connection = project.getMessageBus().connect();
    connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new MyFileEditorManagerListener());
    connection.subscribe(FileTypeManager.TOPIC, new MyFileTypeListener(project));
    VirtualFileManager.getInstance().addVirtualFileListener(new MyVirtualFileListener(project), project);
    connection.subscribe(UISettingsListener.TOPIC, new MyUISettingsListener(project));
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection)

Example 8 with MessageBusConnection

use of com.intellij.util.messages.MessageBusConnection in project intellij-community by JetBrains.

the class MvcModuleStructureSynchronizer method initComponent.

@Override
public void initComponent() {
    final MessageBusConnection connection = myProject.getMessageBus().connect();
    connection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {

        @Override
        public void rootsChanged(ModuleRootEvent event) {
            myModificationTracker.incModificationCount();
            queue(SyncAction.SyncLibrariesInPluginsModule, myProject);
            queue(SyncAction.UpgradeFramework, myProject);
            queue(SyncAction.CreateAppStructureIfNeeded, myProject);
            queue(SyncAction.UpdateProjectStructure, myProject);
            queue(SyncAction.EnsureRunConfigurationExists, myProject);
            updateProjectViewVisibility();
        }
    });
    connection.subscribe(ProjectTopics.MODULES, new ModuleListener() {

        @Override
        public void moduleAdded(@NotNull Project project, @NotNull Module module) {
            queue(SyncAction.UpdateProjectStructure, module);
            queue(SyncAction.CreateAppStructureIfNeeded, module);
        }
    });
    connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkVirtualFileListenerAdapter(new VirtualFileAdapter() {

        @Override
        public void fileCreated(@NotNull final VirtualFileEvent event) {
            myModificationTracker.incModificationCount();
            final VirtualFile file = event.getFile();
            final String fileName = event.getFileName();
            if (MvcModuleStructureUtil.APPLICATION_PROPERTIES.equals(fileName) || isApplicationDirectoryName(fileName)) {
                queue(SyncAction.UpdateProjectStructure, file);
                queue(SyncAction.EnsureRunConfigurationExists, file);
            } else if (isLibDirectory(file) || isLibDirectory(event.getParent())) {
                queue(SyncAction.UpdateProjectStructure, file);
            } else {
                if (!myProject.isInitialized())
                    return;
                final Module module = ProjectRootManager.getInstance(myProject).getFileIndex().getModuleForFile(file);
                if (module == null) {
                    // Maybe it is creation of a plugin in plugin directory.
                    if (file.isDirectory()) {
                        if (myPluginRoots.contains(file.getParent())) {
                            queue(SyncAction.UpdateProjectStructure, myProject);
                            return;
                        }
                        if (!myOutOfModuleDirectoryCreatedActionAdded) {
                            queue(SyncAction.OutOfModuleDirectoryCreated, myProject);
                            myOutOfModuleDirectoryCreatedActionAdded = true;
                        }
                    }
                    return;
                }
                if (!MvcConsole.isUpdatingVfsByConsoleProcess(module))
                    return;
                final MvcFramework framework = MvcFramework.getInstance(module);
                if (framework == null)
                    return;
                if (framework.isToReformatOnCreation(file) || file.isDirectory()) {
                    ApplicationManager.getApplication().invokeLater(() -> {
                        if (!file.isValid())
                            return;
                        if (!framework.hasSupport(module))
                            return;
                        final List<VirtualFile> files = new ArrayList<>();
                        if (file.isDirectory()) {
                            ModuleRootManager.getInstance(module).getFileIndex().iterateContentUnderDirectory(file, new ContentIterator() {

                                @Override
                                public boolean processFile(VirtualFile fileOrDir) {
                                    if (!fileOrDir.isDirectory() && framework.isToReformatOnCreation(fileOrDir)) {
                                        files.add(file);
                                    }
                                    return true;
                                }
                            });
                        } else {
                            files.add(file);
                        }
                        PsiManager manager = PsiManager.getInstance(myProject);
                        for (VirtualFile virtualFile : files) {
                            PsiFile psiFile = manager.findFile(virtualFile);
                            if (psiFile != null) {
                                new ReformatCodeProcessor(myProject, psiFile, null, false).run();
                            }
                        }
                    }, module.getDisposed());
                }
            }
        }

        @Override
        public void fileDeleted(@NotNull VirtualFileEvent event) {
            myModificationTracker.incModificationCount();
            final VirtualFile file = event.getFile();
            if (isLibDirectory(file) || isLibDirectory(event.getParent())) {
                queue(SyncAction.UpdateProjectStructure, file);
            }
        }

        @Override
        public void contentsChanged(@NotNull VirtualFileEvent event) {
            final String fileName = event.getFileName();
            if (MvcModuleStructureUtil.APPLICATION_PROPERTIES.equals(fileName)) {
                queue(SyncAction.UpdateProjectStructure, event.getFile());
            }
        }

        @Override
        public void fileMoved(@NotNull VirtualFileMoveEvent event) {
            myModificationTracker.incModificationCount();
        }

        @Override
        public void propertyChanged(@NotNull VirtualFilePropertyEvent event) {
            if (VirtualFile.PROP_NAME.equals(event.getPropertyName())) {
                myModificationTracker.incModificationCount();
            }
        }
    }));
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ModuleListener(com.intellij.openapi.project.ModuleListener) PsiManager(com.intellij.psi.PsiManager) ReformatCodeProcessor(com.intellij.codeInsight.actions.ReformatCodeProcessor) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) BulkVirtualFileListenerAdapter(com.intellij.openapi.vfs.impl.BulkVirtualFileListenerAdapter) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module)

Example 9 with MessageBusConnection

use of com.intellij.util.messages.MessageBusConnection in project ideavim by JetBrains.

the class EventFacade method addFileEditorManagerListener.

public void addFileEditorManagerListener(@NotNull Project project, @NotNull FileEditorManagerListener listener) {
    final MessageBusConnection connection = project.getMessageBus().connect();
    connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, listener);
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection)

Example 10 with MessageBusConnection

use of com.intellij.util.messages.MessageBusConnection in project intellij-community by JetBrains.

the class CompilerManagerImpl method addCompilationStatusListener.

@Override
public void addCompilationStatusListener(@NotNull CompilationStatusListener listener, @NotNull Disposable parentDisposable) {
    final MessageBusConnection connection = myProject.getMessageBus().connect(parentDisposable);
    connection.subscribe(CompilerTopics.COMPILATION_STATUS, listener);
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection)

Aggregations

MessageBusConnection (com.intellij.util.messages.MessageBusConnection)81 Project (com.intellij.openapi.project.Project)16 NotNull (org.jetbrains.annotations.NotNull)15 Module (com.intellij.openapi.module.Module)11 ModuleRootEvent (com.intellij.openapi.roots.ModuleRootEvent)10 ModuleListener (com.intellij.openapi.project.ModuleListener)8 ModuleRootListener (com.intellij.openapi.roots.ModuleRootListener)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 Disposable (com.intellij.openapi.Disposable)6 Document (com.intellij.openapi.editor.Document)6 VFileEvent (com.intellij.openapi.vfs.newvfs.events.VFileEvent)5 Update (com.intellij.util.ui.update.Update)5 ApplicationManager (com.intellij.openapi.application.ApplicationManager)4 StringUtil (com.intellij.openapi.util.text.StringUtil)4 ProcessHandler (com.intellij.execution.process.ProcessHandler)3 Application (com.intellij.openapi.application.Application)3 FileDocumentManagerAdapter (com.intellij.openapi.fileEditor.FileDocumentManagerAdapter)3 ModuleRootAdapter (com.intellij.openapi.roots.ModuleRootAdapter)3 VFileCreateEvent (com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent)3 File (java.io.File)3