public static void runBatchFoldingOperationOutsideOfBulkUpdate(@Nonnull Editor editor, @Nonnull Runnable operation) { DocumentEx document = ObjectUtils.tryCast(editor.getDocument(), DocumentEx.class); if (document != null && document.isInBulkUpdate()) { MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(); disposeWithEditor(editor, connection); connection.subscribe(DocumentBulkUpdateListener.TOPIC, new DocumentBulkUpdateListener.Adapter() { @Override public void updateFinished(@Nonnull Document doc) { if (doc == editor.getDocument()) { editor.getFoldingModel().runBatchFoldingOperation(operation); connection.disconnect(); } } }); } else { editor.getFoldingModel().runBatchFoldingOperation(operation); } }
public PsiDocumentManagerImpl(@Nonnull final Project project, @Nonnull PsiManager psiManager, @Nonnull EditorFactory editorFactory, @Nonnull MessageBus bus, @NonNls @Nonnull final DocumentCommitProcessor documentCommitThread) { super(project, psiManager, bus, documentCommitThread); myDocumentCommitThread = documentCommitThread; editorFactory.getEventMulticaster().addDocumentListener(this, project); MessageBusConnection connection = bus.connect(); connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() { @Override public void fileContentLoaded(@Nonnull final VirtualFile virtualFile, @Nonnull Document document) { PsiFile psiFile = ReadAction.compute(() -> myProject.isDisposed() || !virtualFile.isValid() ? null : getCachedPsiFile(virtualFile)); fireDocumentCreated(document, psiFile); } }); connection.subscribe(DocumentBulkUpdateListener.TOPIC, new DocumentBulkUpdateListener.Adapter() { @Override public void updateFinished(@Nonnull Document doc) { documentCommitThread.commitAsynchronously(project, doc, "Bulk update finished", TransactionGuard.getInstance().getContextTransaction()); } }); Disposer.register(project, () -> ((DocumentCommitThread)myDocumentCommitThread).cancelTasksOnProjectDispose(project)); }
public BlockSupportImpl(Project project) { project.getMessageBus().connect().subscribe(DocumentBulkUpdateListener.TOPIC, new DocumentBulkUpdateListener.Adapter() { @Override public void updateStarted(@NotNull final Document doc) { doc.putUserData(DO_NOT_REPARSE_INCREMENTALLY, Boolean.TRUE); } }); }
public PsiDocumentManagerImpl(@NotNull final Project project, @NotNull PsiManager psiManager, @NotNull EditorFactory editorFactory, @NotNull MessageBus bus, @NonNls @NotNull final DocumentCommitThread documentCommitThread) { super(project, psiManager, bus, documentCommitThread); myDocumentCommitThread = documentCommitThread; editorFactory.getEventMulticaster().addDocumentListener(this, project); MessageBusConnection busConnection = bus.connect(); busConnection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() { @Override public void fileContentLoaded(@NotNull final VirtualFile virtualFile, @NotNull Document document) { PsiFile psiFile = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile>() { @Override public PsiFile compute() { return myProject.isDisposed() || !virtualFile.isValid() ? null : getCachedPsiFile(virtualFile); } }); fireDocumentCreated(document, psiFile); } }); busConnection.subscribe(DocumentBulkUpdateListener.TOPIC, new DocumentBulkUpdateListener.Adapter() { @Override public void updateFinished(@NotNull Document doc) { documentCommitThread.queueCommit(project, doc, "Bulk update finished", ApplicationManager.getApplication().getDefaultModalityState()); } }); }
CodeFoldingManagerImpl(Project project) { myProject = project; project.getMessageBus().connect().subscribe(DocumentBulkUpdateListener.TOPIC, new DocumentBulkUpdateListener.Adapter() { @Override public void updateStarted(@NotNull final Document doc) { resetFoldingInfo(doc); } }); }
public BlockSupportImpl(Project project) { project.getMessageBus().connect().subscribe(DocumentBulkUpdateListener.TOPIC, new DocumentBulkUpdateListener.Adapter() { @Override public void updateStarted(@Nonnull final Document doc) { doc.putUserData(DO_NOT_REPARSE_INCREMENTALLY, Boolean.TRUE); } }); }
public GradleFileEditor(@NotNull VirtualFile virtualFile, @NotNull Project project) { myProject = project; myVirtualFile = virtualFile; myGroups = new GradleEditorModelParserFacade().parse(virtualFile, project); myComponent = new GradleEditorComponent(project, myGroups); myDocument = FileDocumentManager.getInstance().getDocument(virtualFile); if (myDocument == null) { myDocumentListener = null; myConnection = null; } else { myDocument.addDocumentListener(myDocumentListener = new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { Document document = e.getDocument(); if (document instanceof DocumentEx && ((DocumentEx)document).isInBulkUpdate()) { return; } if (!myEditorTriggeredModificationInProgress) { refresh(); } } }); myConnection = project.getMessageBus().connect(); myConnection.subscribe(DocumentBulkUpdateListener.TOPIC, new DocumentBulkUpdateListener.Adapter() { @Override public void updateFinished(@NotNull Document doc) { if (!myEditorTriggeredModificationInProgress) { refresh(); } } }); myConnection.subscribe(GradleEditorNotificationListener.TOPIC, new GradleEditorNotificationListener() { @Override public void beforeChange() { myEditorTriggeredModificationInProgress = true; } @Override public void afterChange() { myEditorTriggeredModificationInProgress = false; } }); } }