Search in sources :

Example 71 with MessageBusConnection

use of com.intellij.util.messages.MessageBusConnection 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)

Example 72 with MessageBusConnection

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

the class NavBarListener method unsubscribeFrom.

static void unsubscribeFrom(NavBarPanel panel) {
    final NavBarListener listener = (NavBarListener) panel.getClientProperty(LISTENER);
    panel.putClientProperty(LISTENER, null);
    if (listener != null) {
        final Project project = panel.getProject();
        KeyboardFocusManager.getCurrentKeyboardFocusManager().removePropertyChangeListener(listener);
        FileStatusManager.getInstance(project).removeFileStatusListener(listener);
        PsiManager.getInstance(project).removePsiTreeChangeListener(listener);
        WolfTheProblemSolver.getInstance(project).removeProblemListener(listener);
        ActionManager.getInstance().removeAnActionListener(listener);
        final MessageBusConnection connection = (MessageBusConnection) panel.getClientProperty(BUS);
        panel.putClientProperty(BUS, null);
        if (connection != null) {
            connection.disconnect();
        }
        LafManager.getInstance().removeLafManagerListener(listener);
    }
}
Also used : Project(com.intellij.openapi.project.Project) MessageBusConnection(com.intellij.util.messages.MessageBusConnection)

Example 73 with MessageBusConnection

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

the class Alarm method addRequest.

public void addRequest(@NotNull final Runnable request, final int delay, boolean runWithActiveFrameOnly) {
    if (runWithActiveFrameOnly && !ApplicationManager.getApplication().isActive()) {
        final MessageBus bus = ApplicationManager.getApplication().getMessageBus();
        final MessageBusConnection connection = bus.connect(this);
        connection.subscribe(ApplicationActivationListener.TOPIC, new ApplicationActivationListener.Adapter() {

            @Override
            public void applicationActivated(IdeFrame ideFrame) {
                connection.disconnect();
                addRequest(request, delay);
            }
        });
    } else {
        addRequest(request, delay);
    }
}
Also used : MessageBus(com.intellij.util.messages.MessageBus) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) IdeFrame(com.intellij.openapi.wm.IdeFrame) ApplicationActivationListener(com.intellij.openapi.application.ApplicationActivationListener)

Example 74 with MessageBusConnection

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

the class MessageListenerList method add.

public void add(@NotNull T listener) {
    final MessageBusConnection connection = myMessageBus.connect();
    connection.subscribe(myTopic, listener);
    myListenerToConnectionMap.put(listener, connection);
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection)

Example 75 with MessageBusConnection

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

the class GitLogProvider method subscribeToRootRefreshEvents.

@NotNull
@Override
public Disposable subscribeToRootRefreshEvents(@NotNull final Collection<VirtualFile> roots, @NotNull final VcsLogRefresher refresher) {
    MessageBusConnection connection = myProject.getMessageBus().connect(myProject);
    connection.subscribe(GitRepository.GIT_REPO_CHANGE, repository -> {
        VirtualFile root = repository.getRoot();
        if (roots.contains(root)) {
            refresher.refresh(root);
        }
    });
    return connection;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) NotNull(org.jetbrains.annotations.NotNull)

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