Search in sources :

Example 41 with MessageBusConnection

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

the class ScopeTreeViewPanel method initListeners.

public void initListeners() {
    final MessageBusConnection connection = myProject.getMessageBus().connect(this);
    connection.subscribe(ProjectTopics.PROJECT_ROOTS, new MyModuleRootListener());
    PsiManager.getInstance(myProject).addPsiTreeChangeListener(myPsiTreeChangeAdapter);
    WolfTheProblemSolver.getInstance(myProject).addProblemListener(myProblemListener);
    ChangeListManager.getInstance(myProject).addChangeListListener(myChangesListListener);
    FileStatusManager.getInstance(myProject).addFileStatusListener(myFileStatusListener, myProject);
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection)

Example 42 with MessageBusConnection

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

the class AutoScrollFromSourceHandler method install.

public void install() {
    final MessageBusConnection connection = myProject.getMessageBus().connect(myProject);
    connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {

        @Override
        public void selectionChanged(@NotNull FileEditorManagerEvent event) {
            final FileEditor editor = event.getNewEditor();
            if (editor != null && myComponent.isShowing() && isAutoScrollEnabled()) {
                myAlarm.cancelAllRequests();
                myAlarm.addRequest(() -> selectElementFromEditor(editor), getAlarmDelay(), getModalityState());
            }
        }
    });
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) FileEditor(com.intellij.openapi.fileEditor.FileEditor) FileEditorManagerEvent(com.intellij.openapi.fileEditor.FileEditorManagerEvent) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener)

Example 43 with MessageBusConnection

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

the class JavaFxHtmlPanel method subscribeForGrayscaleSetting.

private void subscribeForGrayscaleSetting() {
    MessageBusConnection settingsConnection = ApplicationManager.getApplication().getMessageBus().connect(this);
    MarkdownApplicationSettings.SettingsChangedListener settingsChangedListener = new MarkdownApplicationSettings.SettingsChangedListener() {

        @Override
        public void onSettingsChange(@NotNull final MarkdownApplicationSettings settings) {
            runInPlatformWhenAvailable(() -> {
                if (myWebView != null) {
                    updateFontSmoothingType(myWebView, settings.getMarkdownPreviewSettings().isUseGrayscaleRendering());
                }
            });
        }
    };
    settingsConnection.subscribe(MarkdownApplicationSettings.SettingsChangedListener.TOPIC, settingsChangedListener);
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) MarkdownApplicationSettings(org.intellij.plugins.markdown.settings.MarkdownApplicationSettings) NotNull(org.jetbrains.annotations.NotNull)

Example 44 with MessageBusConnection

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

the class OsmorcPostStartupActivity method runActivity.

@Override
public void runActivity(@NotNull Project project) {
    if (project.isDefault()) {
        return;
    }
    MessageBusConnection connection = project.getMessageBus().connect();
    connection.subscribe(FacetManager.FACETS_TOPIC, new FacetManagerAdapter() {

        @Override
        public void facetAdded(@NotNull Facet facet) {
            handleFacetChange(facet, project);
        }

        @Override
        public void facetConfigurationChanged(@NotNull Facet facet) {
            handleFacetChange(facet, project);
        }
    });
    connection.subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {

        @Override
        public void projectClosing(Project project) {
            for (Module module : ModuleManager.getInstance(project).getModules()) {
                AdditionalJARContentsWatcherManager.getInstance(module).cleanup();
            }
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ProjectManagerListener(com.intellij.openapi.project.ProjectManagerListener) Module(com.intellij.openapi.module.Module) FacetManagerAdapter(com.intellij.facet.FacetManagerAdapter) Facet(com.intellij.facet.Facet)

Example 45 with MessageBusConnection

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

the class DesignerApplicationManager method attachProjectAndModuleListeners.

void attachProjectAndModuleListeners(Disposable parentDisposable) {
    MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(parentDisposable);
    connection.subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {

        @Override
        public void projectClosed(Project project) {
            if (isApplicationClosed()) {
                return;
            }
            Client client = Client.getInstance();
            if (client.getRegisteredProjects().contains(project)) {
                client.closeProject(project);
            }
        }
    });
    // unregistered module is more complicated - we cannot just remove all document factories which belong to project as in case of close project
    // we must remove all document factories belong to module and all dependents (dependent may be from another module, so, we process moduleRemoved synchronous
    // one by one)
    connection.subscribe(ProjectTopics.MODULES, new ModuleListener() {

        @Override
        public void moduleRemoved(@NotNull Project project, @NotNull Module module) {
            Client client = Client.getInstance();
            if (!client.isModuleRegistered(module)) {
                return;
            }
            if (unregisterTaskQueueProcessor == null) {
                unregisterTaskQueueProcessor = new QueueProcessor<>(module1 -> {
                    boolean hasError = true;
                    final ActionCallback callback;
                    initialRenderQueue.suspend();
                    try {
                        callback = Client.getInstance().unregisterModule(module1);
                        hasError = false;
                    } finally {
                        if (hasError) {
                            initialRenderQueue.resume();
                        }
                    }
                    callback.doWhenProcessed(() -> initialRenderQueue.resume());
                });
            }
            unregisterTaskQueueProcessor.add(module);
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ProjectManagerListener(com.intellij.openapi.project.ProjectManagerListener) ModuleListener(com.intellij.openapi.project.ModuleListener) QueueProcessor(com.intellij.util.concurrency.QueueProcessor) ActionCallback(com.intellij.openapi.util.ActionCallback) Module(com.intellij.openapi.module.Module)

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