Search in sources :

Example 1 with FinalizableCommand

use of com.intellij.openapi.wm.impl.commands.FinalizableCommand in project intellij-community by JetBrains.

the class ToolWindowImpl method getReady.

@NotNull
@Override
public ActionCallback getReady(@NotNull final Object requestor) {
    final ActionCallback result = new ActionCallback();
    myShowing.getReady(this).doWhenDone(() -> {
        ArrayList<FinalizableCommand> cmd = new ArrayList<>();
        cmd.add(new FinalizableCommand(null) {

            @Override
            public void run() {
                IdeFocusManager.getInstance(myToolWindowManager.getProject()).doWhenFocusSettlesDown(() -> {
                    if (myContentManager.isDisposed())
                        return;
                    myContentManager.getReady(requestor).notify(result);
                });
            }
        });
        myToolWindowManager.execute(cmd);
    });
    return result;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback) ArrayList(java.util.ArrayList) FinalizableCommand(com.intellij.openapi.wm.impl.commands.FinalizableCommand) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with FinalizableCommand

use of com.intellij.openapi.wm.impl.commands.FinalizableCommand in project intellij-community by JetBrains.

the class CommandProcessor method run.

private boolean run(boolean synchronously) {
    synchronized (myLock) {
        final CommandGroup commandGroup = getNextCommandGroup();
        if (commandGroup == null || commandGroup.isEmpty())
            return false;
        final Condition conditionForGroup = commandGroup.getExpireCondition();
        final FinalizableCommand command = commandGroup.takeNextCommand();
        myCommandCount--;
        Condition expire = command.getExpireCondition() != null ? command.getExpireCondition() : conditionForGroup;
        if (expire == null)
            expire = ApplicationManager.getApplication().getDisposed();
        if (expire.value(null))
            return true;
        if (LOG.isDebugEnabled()) {
            LOG.debug("CommandProcessor.run " + command);
        }
        if (synchronously) {
            command.run();
            return true;
        }
        // max. I'm not actually quite sure this should have NON_MODAL modality but it should
        // definitely have some since runnables in command list may (and do) request some PSI activity
        final boolean queueNext = myCommandCount > 0;
        Application application = ApplicationManager.getApplication();
        ModalityState modalityState = Registry.is("ide.perProjectModality") ? ModalityState.current() : ModalityState.NON_MODAL;
        application.getInvokator().invokeLater(command, modalityState, expire).doWhenDone(() -> {
            if (queueNext) {
                run(false);
            }
        });
        return true;
    }
}
Also used : Condition(com.intellij.openapi.util.Condition) ModalityState(com.intellij.openapi.application.ModalityState) FinalizableCommand(com.intellij.openapi.wm.impl.commands.FinalizableCommand) Application(com.intellij.openapi.application.Application)

Aggregations

FinalizableCommand (com.intellij.openapi.wm.impl.commands.FinalizableCommand)2 Application (com.intellij.openapi.application.Application)1 ModalityState (com.intellij.openapi.application.ModalityState)1 ActionCallback (com.intellij.openapi.util.ActionCallback)1 Condition (com.intellij.openapi.util.Condition)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1