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();
}
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);
}
}
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);
}
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);
}
});
}
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;
}
Aggregations