Search in sources :

Example 1 with FocusCommand

use of com.intellij.openapi.wm.FocusCommand in project intellij-community by JetBrains.

the class RequestFocusInToolWindowCmd method requestFocus.

@NotNull
private ActionCallback requestFocus(@NotNull final Component c) {
    final ActionCallback result = new ActionCallback();
    final Alarm checkerAlarm = new Alarm(result);
    Runnable checker = new Runnable() {

        final long startTime = System.currentTimeMillis();

        @Override
        public void run() {
            if (System.currentTimeMillis() - startTime > 10000) {
                result.setRejected();
                return;
            }
            if (c.isShowing()) {
                final Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
                if (owner != null && owner == c) {
                    myManager.getFocusManager().requestFocus(new FocusCommand() {

                        @Override
                        @NotNull
                        public ActionCallback run() {
                            return ActionCallback.DONE;
                        }
                    }, false).doWhenProcessed(() -> updateToolWindow(c)).notify(result);
                } else {
                    myManager.getFocusManager().requestFocus(new FocusCommand.ByComponent(c, myToolWindow.getComponent(), myProject, new Exception()), false).doWhenProcessed(() -> updateToolWindow(c)).notify(result);
                }
            } else {
                checkerAlarm.addRequest(this, 100);
            }
        }
    };
    checkerAlarm.addRequest(checker, 0);
    return result;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback) Alarm(com.intellij.util.Alarm) FocusCommand(com.intellij.openapi.wm.FocusCommand) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with FocusCommand

use of com.intellij.openapi.wm.FocusCommand in project intellij-community by JetBrains.

the class ProjectViewSelectInGroupTarget method selectIn.

@Override
public void selectIn(final SelectInContext context, final boolean requestFocus) {
    ProjectView projectView = ProjectView.getInstance(context.getProject());
    Collection<SelectInTarget> targets = projectView.getSelectInTargets();
    Collection<SelectInTarget> targetsToCheck = new LinkedHashSet<>();
    String currentId = projectView.getCurrentViewId();
    for (SelectInTarget projectViewTarget : targets) {
        if (Comparing.equal(currentId, projectViewTarget.getMinorViewId())) {
            targetsToCheck.add(projectViewTarget);
            break;
        }
    }
    targetsToCheck.addAll(targets);
    for (final SelectInTarget target : targetsToCheck) {
        if (target.canSelect(context)) {
            if (requestFocus) {
                IdeFocusManager.getInstance(context.getProject()).requestFocus(new FocusCommand() {

                    @NotNull
                    @Override
                    public ActionCallback run() {
                        target.selectIn(context, requestFocus);
                        return ActionCallback.DONE;
                    }
                }, true);
            } else {
                target.selectIn(context, requestFocus);
            }
            break;
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ActionCallback(com.intellij.openapi.util.ActionCallback) CompositeSelectInTarget(com.intellij.ide.CompositeSelectInTarget) SelectInTarget(com.intellij.ide.SelectInTarget) ProjectView(com.intellij.ide.projectView.ProjectView) FocusCommand(com.intellij.openapi.wm.FocusCommand) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ActionCallback (com.intellij.openapi.util.ActionCallback)2 FocusCommand (com.intellij.openapi.wm.FocusCommand)2 NotNull (org.jetbrains.annotations.NotNull)2 CompositeSelectInTarget (com.intellij.ide.CompositeSelectInTarget)1 SelectInTarget (com.intellij.ide.SelectInTarget)1 ProjectView (com.intellij.ide.projectView.ProjectView)1 Alarm (com.intellij.util.Alarm)1 LinkedHashSet (java.util.LinkedHashSet)1