use of com.intellij.openapi.application.ex.ApplicationEx in project intellij-community by JetBrains.
the class IdeEventQueue method fixStickyFocusedComponents.
public void fixStickyFocusedComponents(@Nullable AWTEvent e) {
if (e != null && !(e instanceof InputEvent))
return;
final KeyboardFocusManager mgr = KeyboardFocusManager.getCurrentKeyboardFocusManager();
if (Registry.is("actionSystem.fixStickyFocusedWindows")) {
fixStickyWindow(mgr, mgr.getActiveWindow(), "setGlobalActiveWindow");
fixStickyWindow(mgr, mgr.getFocusedWindow(), "setGlobalFocusedWindow");
}
if (Registry.is("actionSystem.fixNullFocusedComponent")) {
final Component focusOwner = mgr.getFocusOwner();
if (focusOwner == null || !focusOwner.isShowing() || focusOwner instanceof JFrame || focusOwner instanceof JDialog) {
final Application app = ApplicationManager.getApplication();
if (app instanceof ApplicationEx && !((ApplicationEx) app).isLoaded()) {
return;
}
boolean mouseEventsAhead = isMouseEventAhead(e);
boolean focusTransferredNow = IdeFocusManager.getGlobalInstance().isFocusBeingTransferred();
boolean okToFixFocus = !mouseEventsAhead && !focusTransferredNow;
if (okToFixFocus) {
Window showingWindow = mgr.getActiveWindow();
if (showingWindow == null) {
Method getNativeFocusOwner = ReflectionUtil.getDeclaredMethod(KeyboardFocusManager.class, "getNativeFocusOwner");
if (getNativeFocusOwner != null) {
try {
Object owner = getNativeFocusOwner.invoke(mgr);
if (owner instanceof Component) {
showingWindow = UIUtil.getWindow((Component) owner);
}
} catch (Exception e1) {
LOG.debug(e1);
}
}
}
if (showingWindow != null) {
final IdeFocusManager fm = IdeFocusManager.findInstanceByComponent(showingWindow);
ExpirableRunnable maybeRequestDefaultFocus = new ExpirableRunnable() {
@Override
public void run() {
if (getPopupManager().requestDefaultFocus(false))
return;
final Application app = ApplicationManager.getApplication();
if (app != null && app.isActive()) {
fm.requestDefaultFocus(false);
}
}
@Override
public boolean isExpired() {
return !UIUtil.isMeaninglessFocusOwner(mgr.getFocusOwner());
}
};
fm.revalidateFocus(maybeRequestDefaultFocus);
}
}
}
}
}
Aggregations