use of com.intellij.openapi.application.ModalityState in project intellij-community by JetBrains.
the class QueueProcessor method startProcessing.
private boolean startProcessing() {
LOG.assertTrue(Thread.holdsLock(myQueue));
if (isProcessing || !myStarted) {
return false;
}
isProcessing = true;
final T item = myQueue.removeFirst();
final Runnable runnable = () -> {
if (myDeathCondition.value(null))
return;
runSafely(() -> myProcessor.consume(item, myContinuationContext));
};
final Application application = ApplicationManager.getApplication();
if (myThreadToUse == ThreadToUse.AWT) {
final ModalityState state = myModalityState.remove(item);
if (state != null) {
application.invokeLater(runnable, state);
} else {
application.invokeLater(runnable);
}
} else {
application.executeOnPooledThread(runnable);
}
return true;
}
use of com.intellij.openapi.application.ModalityState in project intellij-community by JetBrains.
the class VirtualFileDiffElement method refreshFile.
public static void refreshFile(boolean userInitiated, VirtualFile virtualFile) {
if (userInitiated) {
final List<Document> docsToSave = new ArrayList<>();
final FileDocumentManager manager = FileDocumentManager.getInstance();
for (Document document : manager.getUnsavedDocuments()) {
VirtualFile file = manager.getFile(document);
if (file != null && VfsUtilCore.isAncestor(virtualFile, file, false)) {
docsToSave.add(document);
}
}
if (!docsToSave.isEmpty()) {
new WriteAction() {
@Override
protected void run(@NotNull Result result) throws Throwable {
for (Document document : docsToSave) {
manager.saveDocument(document);
}
}
}.execute();
}
ModalityState modalityState = ProgressManager.getInstance().getProgressIndicator().getModalityState();
VfsUtil.markDirty(true, true, virtualFile);
RefreshQueue.getInstance().refresh(false, true, null, modalityState, virtualFile);
}
}
use of com.intellij.openapi.application.ModalityState in project intellij-community by JetBrains.
the class TypeCommand method inWriteSafeContext.
static void inWriteSafeContext(Runnable runnable) {
ModalityState modality = ModalityState.current();
ApplicationManager.getApplication().invokeLater(() -> IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(runnable, modality), modality);
}
use of com.intellij.openapi.application.ModalityState in project intellij-community by JetBrains.
the class CvsTree method loadChildren.
@Override
public void loadChildren(final CvsElement element) {
element.setLoading(true);
myLoadingNodeManager.addTo(myModel, element);
final Application application = ApplicationManager.getApplication();
final ModalityState modalityState = application.getCurrentModalityState();
application.executeOnPooledThread(() -> {
final RemoteResourceDataProvider dataProvider = element.getDataProvider();
dataProvider.fillContentFor(new MyGetContentCallback(element, modalityState, myProject), myErrorCallback);
});
}
use of com.intellij.openapi.application.ModalityState in project intellij-community by JetBrains.
the class LaterInvocatorTest method testInvokeLaterWithNonexistentModalityStateIsInvokedInLowerModalityState.
public void testInvokeLaterWithNonexistentModalityStateIsInvokedInLowerModalityState() throws Exception {
SwingUtilities.invokeAndWait(() -> {
LaterInvocator.enterModal(myWindow2);
ModalityState window2State = ModalityState.current();
LaterInvocator.leaveModal(myWindow2);
LaterInvocator.invokeLater(new MyRunnable("1"), window2State);
LaterInvocator.enterModal(myWindow1);
flushSwingQueue();
checkOrder(0);
LaterInvocator.leaveModal(myWindow1);
flushSwingQueue();
checkOrder(1);
LaterInvocator.invokeLater(new MyRunnable("2"), window2State);
flushSwingQueue();
checkOrder(2);
});
}
Aggregations