Search in sources :

Example 16 with MessageBusConnection

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

the class EditorPlaybackCall method waitDaemonForFinish.

public static AsyncResult<String> waitDaemonForFinish(final PlaybackContext context) {
    final AsyncResult<String> result = new AsyncResult<>();
    final Disposable connection = Disposer.newDisposable();
    result.doWhenProcessed(() -> Disposer.dispose(connection));
    WindowSystemPlaybackCall.findProject().doWhenDone(new Consumer<Project>() {

        @Override
        public void consume(Project project) {
            final MessageBusConnection bus = project.getMessageBus().connect(connection);
            bus.subscribe(DaemonCodeAnalyzer.DAEMON_EVENT_TOPIC, new DaemonCodeAnalyzer.DaemonListenerAdapter() {

                @Override
                public void daemonFinished() {
                    context.flushAwtAndRunInEdt(result.createSetDoneRunnable());
                }

                @Override
                public void daemonCancelEventOccurred(@NotNull String reason) {
                    result.setDone();
                }
            });
        }
    }).doWhenRejected(() -> result.setRejected("Cannot find project"));
    return result;
}
Also used : Disposable(com.intellij.openapi.Disposable) Project(com.intellij.openapi.project.Project) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) Consumer(com.intellij.util.Consumer) DaemonCodeAnalyzer(com.intellij.codeInsight.daemon.DaemonCodeAnalyzer) AsyncResult(com.intellij.openapi.util.AsyncResult)

Example 17 with MessageBusConnection

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

the class LineSeparatorPanel method install.

@Override
public void install(@NotNull StatusBar statusBar) {
    super.install(statusBar);
    MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(this);
    connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() {

        @Override
        public void fileContentReloaded(@NotNull VirtualFile file, @NotNull Document document) {
            update();
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) FileDocumentManagerAdapter(com.intellij.openapi.fileEditor.FileDocumentManagerAdapter) Document(com.intellij.openapi.editor.Document)

Example 18 with MessageBusConnection

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

the class PositionPanel method install.

public void install(@NotNull StatusBar statusBar) {
    super.install(statusBar);
    EditorEventMulticaster multicaster = EditorFactory.getInstance().getEventMulticaster();
    multicaster.addCaretListener(this, this);
    multicaster.addSelectionListener(this, this);
    multicaster.addDocumentListener(this, this);
    MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(this);
    connection.subscribe(DocumentBulkUpdateListener.TOPIC, this);
    ObjectUtils.consumeIfCast(multicaster, EditorEventMulticasterEx.class, multicasterEx -> multicasterEx.addFocusChangeListner(this, this));
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection)

Example 19 with MessageBusConnection

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

the class LocalFileSystemTest method doTestInterruptedRefresh.

public static void doTestInterruptedRefresh(@NotNull File top) throws Exception {
    for (int i = 1; i <= 3; i++) {
        File sub = IoTestUtil.createTestDir(top, "sub_" + i);
        for (int j = 1; j <= 3; j++) {
            IoTestUtil.createTestDir(sub, "sub_" + j);
        }
    }
    Files.walkFileTree(top.toPath(), new SimpleFileVisitor<Path>() {

        @Override
        public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
            for (int k = 1; k <= 3; k++) {
                IoTestUtil.createTestFile(dir.toFile(), "file_" + k, ".");
            }
            return FileVisitResult.CONTINUE;
        }
    });
    VirtualFile topDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(top);
    assertNotNull(topDir);
    Set<VirtualFile> files = ContainerUtil.newHashSet();
    VfsUtilCore.processFilesRecursively(topDir, file -> {
        if (!file.isDirectory())
            files.add(file);
        return true;
    });
    // 13 dirs of 3 files
    assertEquals(39, files.size());
    topDir.refresh(false, true);
    Set<VirtualFile> processed = ContainerUtil.newHashSet();
    MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect();
    connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {

        @Override
        public void after(@NotNull List<? extends VFileEvent> events) {
            events.forEach(e -> processed.add(e.getFile()));
        }
    });
    try {
        files.forEach(f -> IoTestUtil.updateFile(new File(f.getPath()), "+++"));
        ((NewVirtualFile) topDir).markDirtyRecursively();
        RefreshWorker.setCancellingCondition(file -> file.getPath().endsWith(top.getName() + "/sub_2/file_2"));
        topDir.refresh(false, true);
        assertThat(processed.size()).isGreaterThan(0).isLessThan(files.size());
        RefreshWorker.setCancellingCondition(null);
        topDir.refresh(false, true);
        assertThat(processed).isEqualTo(files);
    } finally {
        connection.disconnect();
        RefreshWorker.setCancellingCondition(null);
    }
}
Also used : Path(java.nio.file.Path) VfsRootAccess(com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess) java.util(java.util) WriteAction(com.intellij.openapi.application.WriteAction) ArrayUtil(com.intellij.util.ArrayUtil) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) FileAttributes(com.intellij.openapi.util.io.FileAttributes) ContainerUtil(com.intellij.util.containers.ContainerUtil) FileSystemUtil(com.intellij.openapi.util.io.FileSystemUtil) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) com.intellij.openapi.vfs.newvfs(com.intellij.openapi.vfs.newvfs) PersistentFSImpl(com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl) VFileCreateEvent(com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent) FileUtil(com.intellij.openapi.util.io.FileUtil) VFileDeleteEvent(com.intellij.openapi.vfs.newvfs.events.VFileDeleteEvent) Path(java.nio.file.Path) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) RefreshWorker(com.intellij.openapi.vfs.newvfs.persistent.RefreshWorker) PlatformTestUtil(com.intellij.testFramework.PlatformTestUtil) Files(java.nio.file.Files) StringUtil(com.intellij.openapi.util.text.StringUtil) PlatformTestCase(com.intellij.testFramework.PlatformTestCase) PersistentFS(com.intellij.openapi.vfs.newvfs.persistent.PersistentFS) IOException(java.io.IOException) VirtualDirectoryImpl(com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl) VFileContentChangeEvent(com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent) SystemInfo(com.intellij.openapi.util.SystemInfo) File(java.io.File) FileVisitResult(java.nio.file.FileVisitResult) ApplicationManager(com.intellij.openapi.application.ApplicationManager) IoTestUtil(com.intellij.openapi.util.io.IoTestUtil) com.intellij.openapi.vfs(com.intellij.openapi.vfs) GeneralSettings(com.intellij.ide.GeneralSettings) VirtualFileSystemEntry(com.intellij.openapi.vfs.newvfs.impl.VirtualFileSystemEntry) ObjectUtils(com.intellij.util.ObjectUtils) NotNull(org.jetbrains.annotations.NotNull) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) File(java.io.File)

Example 20 with MessageBusConnection

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

the class LocalFileSystemTest method testFileContentChangeEvents.

public void testFileContentChangeEvents() throws IOException {
    File file = IoTestUtil.createTestFile("file.txt");
    long stamp = file.lastModified();
    VirtualFile vFile = myFS.refreshAndFindFileByIoFile(file);
    assertNotNull(vFile);
    int[] updated = { 0 };
    MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(getTestRootDisposable());
    connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {

        @Override
        public void after(@NotNull List<? extends VFileEvent> events) {
            for (VFileEvent event : events) {
                if (event instanceof VFileContentChangeEvent && vFile.equals(event.getFile())) {
                    updated[0]++;
                    break;
                }
            }
        }
    });
    FileUtil.writeToFile(file, "content");
    assertTrue(file.setLastModified(stamp));
    vFile.refresh(false, false);
    assertEquals(1, updated[0]);
    FileUtil.writeToFile(file, "more content");
    assertTrue(file.setLastModified(stamp));
    vFile.refresh(false, false);
    assertEquals(2, updated[0]);
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) VFileContentChangeEvent(com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent) File(java.io.File)

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