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