Search in sources :

Example 11 with MessageBusConnection

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

the class MessageBusImpl method connect.

@Override
@NotNull
public MessageBusConnection connect(@NotNull Disposable parentDisposable) {
    checkNotDisposed();
    final MessageBusConnection connection = new MessageBusConnectionImpl(this);
    Disposer.register(parentDisposable, connection);
    return connection;
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with MessageBusConnection

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

the class MessageListenerList method add.

public void add(@NotNull final T listener, @NotNull Disposable parentDisposable) {
    Disposer.register(parentDisposable, new Disposable() {

        @Override
        public void dispose() {
            myListenerToConnectionMap.remove(listener);
        }
    });
    final MessageBusConnection connection = myMessageBus.connect(parentDisposable);
    connection.subscribe(myTopic, listener);
    myListenerToConnectionMap.put(listener, connection);
}
Also used : Disposable(com.intellij.openapi.Disposable) MessageBusConnection(com.intellij.util.messages.MessageBusConnection)

Example 13 with MessageBusConnection

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

the class StartupManagerImpl method scheduleInitialVfsRefresh.

public void scheduleInitialVfsRefresh() {
    GuiUtils.invokeLaterIfNeeded(() -> {
        if (myProject.isDisposed() || myInitialRefreshScheduled)
            return;
        myInitialRefreshScheduled = true;
        markContentRootsForRefresh();
        Application app = ApplicationManager.getApplication();
        if (!app.isCommandLine()) {
            final long sessionId = VirtualFileManager.getInstance().asyncRefresh(null);
            final MessageBusConnection connection = app.getMessageBus().connect();
            connection.subscribe(ProjectLifecycleListener.TOPIC, new ProjectLifecycleListener() {

                @Override
                public void afterProjectClosed(@NotNull Project project) {
                    if (project != myProject)
                        return;
                    RefreshQueue.getInstance().cancelSession(sessionId);
                    connection.disconnect();
                }
            });
        } else {
            VirtualFileManager.getInstance().syncRefresh();
        }
    }, ModalityState.defaultModalityState());
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ProjectLifecycleListener(com.intellij.openapi.project.impl.ProjectLifecycleListener)

Example 14 with MessageBusConnection

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

the class EditorUtil method runBatchFoldingOperationOutsideOfBulkUpdate.

public static void runBatchFoldingOperationOutsideOfBulkUpdate(@NotNull Editor editor, @NotNull Runnable operation) {
    DocumentEx document = ObjectUtils.tryCast(editor.getDocument(), DocumentEx.class);
    if (document != null && document.isInBulkUpdate()) {
        MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect();
        disposeWithEditor(editor, connection);
        connection.subscribe(DocumentBulkUpdateListener.TOPIC, new DocumentBulkUpdateListener.Adapter() {

            @Override
            public void updateFinished(@NotNull Document doc) {
                if (doc == editor.getDocument()) {
                    editor.getFoldingModel().runBatchFoldingOperation(operation);
                    connection.disconnect();
                }
            }
        });
    } else {
        editor.getFoldingModel().runBatchFoldingOperation(operation);
    }
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) DocumentBulkUpdateListener(com.intellij.openapi.editor.ex.DocumentBulkUpdateListener)

Example 15 with MessageBusConnection

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

the class DumbServiceImpl method runWhenPowerSaveModeChanges.

private void runWhenPowerSaveModeChanges(Runnable r) {
    MessageBusConnection connection = myProject.getMessageBus().connect();
    connection.subscribe(PowerSaveMode.TOPIC, () -> {
        r.run();
        connection.disconnect();
    });
}
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