Search in sources :

Example 21 with MessageBusConnection

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

the class LightPlatformTestCase method doSetup.

public static void doSetup(@NotNull LightProjectDescriptor descriptor, @NotNull LocalInspectionTool[] localInspectionTools, @NotNull Disposable parentDisposable) throws Exception {
    assertNull("Previous test " + ourTestCase + " hasn't called tearDown(). Probably overridden without super call.", ourTestCase);
    IdeaLogger.ourErrorsOccurred = null;
    ApplicationManager.getApplication().assertIsDispatchThread();
    boolean reusedProject = true;
    if (ourProject == null || ourProjectDescriptor == null || !ourProjectDescriptor.equals(descriptor)) {
        initProject(descriptor);
        reusedProject = false;
    }
    ProjectManagerEx projectManagerEx = ProjectManagerEx.getInstanceEx();
    projectManagerEx.openTestProject(ourProject);
    if (reusedProject) {
        DumbService.getInstance(ourProject).queueTask(new UnindexedFilesUpdater(ourProject));
    }
    MessageBusConnection connection = ourProject.getMessageBus().connect(parentDisposable);
    connection.subscribe(ProjectTopics.MODULES, new ModuleListener() {

        @Override
        public void moduleAdded(@NotNull Project project, @NotNull Module module) {
            fail("Adding modules is not permitted in LightIdeaTestCase.");
        }
    });
    clearUncommittedDocuments(getProject());
    InspectionsKt.configureInspections(localInspectionTools, getProject(), parentDisposable);
    assertFalse(getPsiManager().isDisposed());
    Boolean passed = null;
    try {
        passed = StartupManagerEx.getInstanceEx(getProject()).startupActivityPassed();
    } catch (Exception ignored) {
    }
    assertTrue("open: " + getProject().isOpen() + "; disposed:" + getProject().isDisposed() + "; startup passed:" + passed + "; all open projects: " + Arrays.asList(ProjectManager.getInstance().getOpenProjects()), getProject().isInitialized());
    CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(new CodeStyleSettings());
    final FileDocumentManager manager = FileDocumentManager.getInstance();
    if (manager instanceof FileDocumentManagerImpl) {
        Document[] unsavedDocuments = manager.getUnsavedDocuments();
        manager.saveAllDocuments();
        ApplicationManager.getApplication().runWriteAction(((FileDocumentManagerImpl) manager)::dropAllUnsavedDocuments);
        assertEmpty("There are unsaved documents", Arrays.asList(unsavedDocuments));
    }
    // startup activities
    UIUtil.dispatchAllInvocationEvents();
    ((FileTypeManagerImpl) FileTypeManager.getInstance()).drainReDetectQueue();
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ModuleListener(com.intellij.openapi.project.ModuleListener) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) FileDocumentManagerImpl(com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl) Document(com.intellij.openapi.editor.Document) FileTypeManagerImpl(com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl) IncorrectOperationException(com.intellij.util.IncorrectOperationException) IOException(java.io.IOException) Project(com.intellij.openapi.project.Project) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) Module(com.intellij.openapi.module.Module) ProjectManagerEx(com.intellij.openapi.project.ex.ProjectManagerEx) UnindexedFilesUpdater(com.intellij.util.indexing.UnindexedFilesUpdater)

Example 22 with MessageBusConnection

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

the class EncodingUtil method reloadIn.

static void reloadIn(@NotNull final VirtualFile virtualFile, @NotNull final Charset charset) {
    final FileDocumentManager documentManager = FileDocumentManager.getInstance();
    if (documentManager.getCachedDocument(virtualFile) == null) {
        // no need to reload document
        EncodingManager.getInstance().setEncoding(virtualFile, charset);
        return;
    }
    final Disposable disposable = Disposer.newDisposable();
    MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(disposable);
    connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() {

        @Override
        public void beforeFileContentReload(VirtualFile file, @NotNull Document document) {
            if (!file.equals(virtualFile))
                return;
            // disconnect
            Disposer.dispose(disposable);
            EncodingManager.getInstance().setEncoding(file, charset);
            LoadTextUtil.setCharsetWasDetectedFromBytes(file, null);
        }
    });
    // if file was modified, the user will be asked here
    try {
        EncodingProjectManagerImpl.suppressReloadDuring(() -> ((VirtualFileListener) documentManager).contentsChanged(new VirtualFileEvent(null, virtualFile, virtualFile.getName(), virtualFile.getParent())));
    } finally {
        Disposer.dispose(disposable);
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) FileDocumentManagerAdapter(com.intellij.openapi.fileEditor.FileDocumentManagerAdapter) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Document(com.intellij.openapi.editor.Document)

Example 23 with MessageBusConnection

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

the class FileTypeManagerImpl method addFileTypeListener.

@Override
public void addFileTypeListener(@NotNull FileTypeListener listener) {
    final MessageBusConnection connection = myMessageBus.connect();
    connection.subscribe(TOPIC, listener);
    myAdapters.put(listener, connection);
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection)

Example 24 with MessageBusConnection

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

the class LibraryDependentToolWindowManager method projectOpened.

@Override
public void projectOpened() {
    final ModuleRootListener rootListener = new ModuleRootListener() {

        @Override
        public void rootsChanged(ModuleRootEvent event) {
            if (!myProject.isDisposed()) {
                checkToolWindowStatuses(myProject);
            }
        }
    };
    StartupManager.getInstance(myProject).runWhenProjectIsInitialized(() -> {
        if (!myProject.isDisposed()) {
            checkToolWindowStatuses(myProject);
            final MessageBusConnection connection = myProject.getMessageBus().connect(myProject);
            connection.subscribe(ProjectTopics.PROJECT_ROOTS, rootListener);
        }
    });
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent) ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener)

Example 25 with MessageBusConnection

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

the class GradleSyncState method subscribe.

@NotNull
public static MessageBusConnection subscribe(@NotNull Project project, @NotNull GradleSyncListener listener, @NotNull Disposable parentDisposable) {
    MessageBusConnection connection = project.getMessageBus().connect(parentDisposable);
    connection.subscribe(GRADLE_SYNC_TOPIC, listener);
    return connection;
}
Also used : 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