Search in sources :

Example 1 with FloatingDecorator

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

the class IdeKeyEventDispatcher method isModalContext.

/**
   * @return {@code true} if and only if the {@code component} represents
   * modal context.
   * @throws IllegalArgumentException if {@code component} is {@code null}.
   */
public static boolean isModalContext(@NotNull Component component) {
    Window window = UIUtil.getWindow(component);
    if (window instanceof IdeFrameImpl) {
        final Component pane = ((IdeFrameImpl) window).getGlassPane();
        if (pane instanceof IdeGlassPaneEx) {
            return ((IdeGlassPaneEx) pane).isInModalContext();
        }
    }
    if (window instanceof JDialog) {
        final JDialog dialog = (JDialog) window;
        if (!dialog.isModal()) {
            final Window owner = dialog.getOwner();
            return owner != null && isModalContext(owner);
        }
    }
    if (window instanceof JFrame) {
        return false;
    }
    boolean isFloatingDecorator = window instanceof FloatingDecorator;
    boolean isPopup = !(component instanceof JFrame) && !(component instanceof JDialog);
    if (isPopup) {
        if (component instanceof JWindow) {
            JBPopup popup = (JBPopup) ((JWindow) component).getRootPane().getClientProperty(JBPopup.KEY);
            if (popup != null) {
                return popup.isModalContext();
            }
        }
    }
    return !isFloatingDecorator;
}
Also used : IdeFrameImpl(com.intellij.openapi.wm.impl.IdeFrameImpl) IdeGlassPaneEx(com.intellij.openapi.wm.impl.IdeGlassPaneEx) FloatingDecorator(com.intellij.openapi.wm.impl.FloatingDecorator) JTextComponent(javax.swing.text.JTextComponent) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 2 with FloatingDecorator

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

the class RequestFocusInEditorComponentCmd method run.

public final void run() {
    try {
        if (myTimestamp.isExpired()) {
            final Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
            if (owner != null && owner == myComponent) {
                myDoneCallback.setDone();
            } else {
                myDoneCallback.setRejected();
            }
        }
        final Window owner = myComponent != null ? SwingUtilities.getWindowAncestor(myComponent) : null;
        if (owner == null) {
            myDoneCallback.setRejected();
            return;
        }
        final Window activeFrame = IdeFrameImpl.getActiveFrame();
        if (activeFrame != null && owner instanceof IdeFrameImpl && activeFrame != owner) {
            myDoneCallback.setRejected();
            return;
        }
        if (myComponent != null) {
            final boolean forced = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() == null;
            myFocusManager.requestFocus(myComponent, myForced || forced).notifyWhenDone(myDoneCallback).doWhenDone(() -> {
                if (SystemInfo.isLinux && Registry.is("suppress.focus.stealing"))
                    return;
                // isn't active.
                if (!owner.isActive()) {
                    final Window activeWindow = getActiveWindow(owner.getOwnedWindows());
                    if (activeWindow == null || (activeWindow instanceof FloatingDecorator)) {
                        //Thread.dumpStack();
                        //System.out.println("------------------------------------------------------");
                        owner.toFront();
                    }
                }
            });
        } else {
            myDoneCallback.setRejected();
        }
    } finally {
        finish();
    }
}
Also used : EditorWindow(com.intellij.openapi.fileEditor.impl.EditorWindow) IdeFrameImpl(com.intellij.openapi.wm.impl.IdeFrameImpl) FloatingDecorator(com.intellij.openapi.wm.impl.FloatingDecorator)

Example 3 with FloatingDecorator

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

the class DataManagerImpl method getFocusedComponent.

@Nullable
private Component getFocusedComponent() {
    if (myWindowManager == null) {
        return null;
    }
    Window activeWindow = myWindowManager.getMostRecentFocusedWindow();
    if (activeWindow == null) {
        activeWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
        if (activeWindow == null) {
            activeWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
            if (activeWindow == null)
                return null;
        }
    }
    if (Registry.is("actionSystem.noContextComponentWhileFocusTransfer")) {
        IdeFocusManager fm = IdeFocusManager.findInstanceByComponent(activeWindow);
        if (fm.isFocusBeingTransferred()) {
            return null;
        }
    }
    // whereas we want to be able to type in other frames as well.
    if (activeWindow instanceof FloatingDecorator) {
        IdeFocusManager ideFocusManager = IdeFocusManager.findInstanceByComponent(activeWindow);
        IdeFrame lastFocusedFrame = ideFocusManager.getLastFocusedFrame();
        JComponent frameComponent = lastFocusedFrame != null ? lastFocusedFrame.getComponent() : null;
        Window lastFocusedWindow = frameComponent != null ? SwingUtilities.getWindowAncestor(frameComponent) : null;
        boolean toolWindowIsNotFocused = myWindowManager.getFocusedComponent(activeWindow) == null;
        if (toolWindowIsNotFocused && lastFocusedWindow != null) {
            activeWindow = lastFocusedWindow;
        }
    }
    // try to find first parent window that has focus
    Window window = activeWindow;
    Component focusedComponent = null;
    while (window != null) {
        focusedComponent = myWindowManager.getFocusedComponent(window);
        if (focusedComponent != null) {
            break;
        }
        window = window.getOwner();
    }
    if (focusedComponent == null) {
        focusedComponent = activeWindow;
    }
    return focusedComponent;
}
Also used : FloatingDecorator(com.intellij.openapi.wm.impl.FloatingDecorator) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) IdeFrame(com.intellij.openapi.wm.IdeFrame) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

FloatingDecorator (com.intellij.openapi.wm.impl.FloatingDecorator)3 IdeFrameImpl (com.intellij.openapi.wm.impl.IdeFrameImpl)2 EditorWindow (com.intellij.openapi.fileEditor.impl.EditorWindow)1 JBPopup (com.intellij.openapi.ui.popup.JBPopup)1 IdeFocusManager (com.intellij.openapi.wm.IdeFocusManager)1 IdeFrame (com.intellij.openapi.wm.IdeFrame)1 IdeGlassPaneEx (com.intellij.openapi.wm.impl.IdeGlassPaneEx)1 JTextComponent (javax.swing.text.JTextComponent)1 Nullable (org.jetbrains.annotations.Nullable)1