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;
}
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;
}
}
}
Aggregations