Search in sources :

Example 6 with ModalityState

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;
}
Also used : ModalityState(com.intellij.openapi.application.ModalityState) Application(com.intellij.openapi.application.Application)

Example 7 with ModalityState

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);
    }
}
Also used : WriteAction(com.intellij.openapi.application.WriteAction) ArrayList(java.util.ArrayList) ModalityState(com.intellij.openapi.application.ModalityState) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Document(com.intellij.openapi.editor.Document) Result(com.intellij.openapi.application.Result)

Example 8 with ModalityState

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);
}
Also used : ModalityState(com.intellij.openapi.application.ModalityState)

Example 9 with ModalityState

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);
    });
}
Also used : ModalityState(com.intellij.openapi.application.ModalityState) Application(com.intellij.openapi.application.Application)

Example 10 with ModalityState

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);
    });
}
Also used : ModalityState(com.intellij.openapi.application.ModalityState)

Aggregations

ModalityState (com.intellij.openapi.application.ModalityState)40 Application (com.intellij.openapi.application.Application)6 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)6 NotNull (org.jetbrains.annotations.NotNull)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Nullable (org.jetbrains.annotations.Nullable)5 Disposable (com.intellij.openapi.Disposable)4 ListSelectionListener (javax.swing.event.ListSelectionListener)4 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)3 Project (com.intellij.openapi.project.Project)3 List (java.util.List)3 CommonBundle (com.intellij.CommonBundle)2 com.intellij.find (com.intellij.find)2 ShowUsagesAction (com.intellij.find.actions.ShowUsagesAction)2 BaseProjectTreeBuilder (com.intellij.ide.projectView.BaseProjectTreeBuilder)2 AbstractProjectTreeStructure (com.intellij.ide.projectView.impl.AbstractProjectTreeStructure)2 ProjectAbstractTreeStructureBase (com.intellij.ide.projectView.impl.ProjectAbstractTreeStructureBase)2 ProjectTreeBuilder (com.intellij.ide.projectView.impl.ProjectTreeBuilder)2 NodeRenderer (com.intellij.ide.util.treeView.NodeRenderer)2 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)2