Search in sources :

Example 1 with TransactionGuardImpl

use of com.intellij.openapi.application.TransactionGuardImpl in project intellij-community by JetBrains.

the class DocumentImpl method assertWriteAccess.

private void assertWriteAccess() {
    if (myAssertThreading) {
        final Application application = ApplicationManager.getApplication();
        if (application != null) {
            application.assertWriteAccessAllowed();
            VirtualFile file = FileDocumentManager.getInstance().getFile(this);
            if (file != null && file.isInLocalFileSystem()) {
                ((TransactionGuardImpl) TransactionGuard.getInstance()).assertWriteActionAllowed();
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TransactionGuardImpl(com.intellij.openapi.application.TransactionGuardImpl) Application(com.intellij.openapi.application.Application)

Example 2 with TransactionGuardImpl

use of com.intellij.openapi.application.TransactionGuardImpl in project intellij-community by JetBrains.

the class FileDocumentManagerImpl method saveAllDocuments.

/**
   * @param isExplicit caused by user directly (Save action) or indirectly (e.g. Compile)
   */
public void saveAllDocuments(boolean isExplicit) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    ((TransactionGuardImpl) TransactionGuard.getInstance()).assertWriteActionAllowed();
    myMultiCaster.beforeAllDocumentsSaving();
    if (myUnsavedDocuments.isEmpty())
        return;
    final Map<Document, IOException> failedToSave = new HashMap<>();
    final Set<Document> vetoed = new HashSet<>();
    while (true) {
        int count = 0;
        for (Document document : myUnsavedDocuments) {
            if (failedToSave.containsKey(document))
                continue;
            if (vetoed.contains(document))
                continue;
            try {
                doSaveDocument(document, isExplicit);
            } catch (IOException e) {
                //noinspection ThrowableResultOfMethodCallIgnored
                failedToSave.put(document, e);
            } catch (SaveVetoException e) {
                vetoed.add(document);
            }
            count++;
        }
        if (count == 0)
            break;
    }
    if (!failedToSave.isEmpty()) {
        handleErrorsOnSave(failedToSave);
    }
}
Also used : TransactionGuardImpl(com.intellij.openapi.application.TransactionGuardImpl) IOException(java.io.IOException) Document(com.intellij.openapi.editor.Document)

Example 3 with TransactionGuardImpl

use of com.intellij.openapi.application.TransactionGuardImpl in project intellij-community by JetBrains.

the class AbstractProgressIndicatorBase method setModalityProgress.

@Override
public void setModalityProgress(ProgressIndicator modalityProgress) {
    LOG.assertTrue(!isRunning());
    myModalityProgress = modalityProgress;
    ModalityState currentModality = ApplicationManager.getApplication().getCurrentModalityState();
    myModalityState = myModalityProgress != null ? ((ModalityStateEx) currentModality).appendProgress(myModalityProgress) : currentModality;
    if (modalityProgress != null) {
        ((TransactionGuardImpl) TransactionGuard.getInstance()).enteredModality(myModalityState);
    }
}
Also used : ModalityStateEx(com.intellij.openapi.application.impl.ModalityStateEx) ModalityState(com.intellij.openapi.application.ModalityState) TransactionGuardImpl(com.intellij.openapi.application.TransactionGuardImpl)

Example 4 with TransactionGuardImpl

use of com.intellij.openapi.application.TransactionGuardImpl in project intellij-community by JetBrains.

the class AbstractPopup method dispose.

@Override
public void dispose() {
    if (myState == State.SHOWN) {
        LOG.debug("shown popup must be cancelled");
        cancel();
    }
    if (myState == State.DISPOSE) {
        return;
    }
    debugState("dispose popup", State.INIT, State.CANCEL);
    myState = State.DISPOSE;
    if (myDisposed) {
        return;
    }
    myDisposed = true;
    if (LOG.isDebugEnabled()) {
        LOG.debug("start disposing " + myContent);
    }
    Disposer.dispose(this, false);
    ApplicationManager.getApplication().assertIsDispatchThread();
    if (myPopup != null) {
        cancel(myDisposeEvent);
    }
    if (myContent != null) {
        Container parent = myContent.getParent();
        if (parent != null)
            parent.remove(myContent);
        myContent.removeAll();
        myContent.removeKeyListener(mySearchKeyListener);
    }
    myContent = null;
    myPreferredFocusedComponent = null;
    myComponent = null;
    myFocusTrackback = null;
    myCallBack = null;
    myListeners = null;
    if (myMouseOutCanceller != null) {
        final Toolkit toolkit = Toolkit.getDefaultToolkit();
        // http://www.jetbrains.net/jira/browse/IDEADEV-21265
        if (toolkit != null) {
            toolkit.removeAWTEventListener(myMouseOutCanceller);
        }
    }
    myMouseOutCanceller = null;
    if (myFinalRunnable != null) {
        final ActionCallback typeAheadDone = new ActionCallback();
        IdeFocusManager.getInstance(myProject).typeAheadUntil(typeAheadDone);
        ModalityState modalityState = ModalityState.current();
        Runnable finalRunnable = myFinalRunnable;
        getFocusManager().doWhenFocusSettlesDown(() -> {
            //noinspection SSBasedInspection
            SwingUtilities.invokeLater(() -> {
                if (ModalityState.current().equals(modalityState)) {
                    ((TransactionGuardImpl) TransactionGuard.getInstance()).performUserActivity(finalRunnable);
                }
            // Otherwise the UI has changed unexpectedly and the action is likely not applicable.
            // And we don't want finalRunnable to perform potentially destructive actions
            //   in the context of a suddenly appeared modal dialog.
            });
            //noinspection SSBasedInspection
            SwingUtilities.invokeLater(typeAheadDone.createSetDoneRunnable());
            myFinalRunnable = null;
        });
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("stop disposing content");
    }
}
Also used : ModalityState(com.intellij.openapi.application.ModalityState) TransactionGuardImpl(com.intellij.openapi.application.TransactionGuardImpl)

Aggregations

TransactionGuardImpl (com.intellij.openapi.application.TransactionGuardImpl)4 ModalityState (com.intellij.openapi.application.ModalityState)2 Application (com.intellij.openapi.application.Application)1 ModalityStateEx (com.intellij.openapi.application.impl.ModalityStateEx)1 Document (com.intellij.openapi.editor.Document)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 IOException (java.io.IOException)1