Example usage for com.intellij.openapi.wm IdeFocusManager getLastFocusedFor

List of usage examples for com.intellij.openapi.wm IdeFocusManager getLastFocusedFor

Introduction

In this page you can find the example usage for com.intellij.openapi.wm IdeFocusManager getLastFocusedFor.

Prototype

@Nullable
public abstract Component getLastFocusedFor(@Nullable Window frame);

Source Link

Document

Returns last focused component for the given IDE Window .

Usage

From source file:com.intellij.designer.LightToolWindow.java

License:Apache License

private boolean isActive() {
    IdeFocusManager fm = IdeFocusManager.getInstance(myProject);
    Component component = fm.getFocusedDescendantFor(this);
    if (component != null) {
        return true;
    }/*from  w  w  w.  j  a v a  2s .co  m*/
    Component owner = fm.getLastFocusedFor(WindowManager.getInstance().getIdeFrame(myProject));
    return owner != null && SwingUtilities.isDescendingFrom(owner, this);
}

From source file:com.intellij.ui.mac.MacMessagesImpl.java

License:Apache License

private static Window getForemostWindow(final Window window) {
    Window _window = null;/*from  www  . j a  v a2  s.co m*/
    IdeFocusManager ideFocusManager = IdeFocusManager.getGlobalInstance();

    Component focusOwner = IdeFocusManager.findInstance().getFocusOwner();
    // Let's ask for a focused component first
    if (focusOwner != null) {
        _window = SwingUtilities.getWindowAncestor(focusOwner);
    }

    if (_window == null) {
        // Looks like ide lost focus, let's ask about the last focused component
        focusOwner = ideFocusManager.getLastFocusedFor(ideFocusManager.getLastFocusedFrame());
        if (focusOwner != null) {
            _window = SwingUtilities.getWindowAncestor(focusOwner);
        }
    }

    if (_window == null) {
        _window = WindowManager.getInstance().findVisibleFrame();
    }

    if (_window == null && window != null) {
        // It might be we just has not opened a frame yet.
        // So let's ask AWT
        focusOwner = window.getMostRecentFocusOwner();
        if (focusOwner != null) {
            _window = SwingUtilities.getWindowAncestor(focusOwner);
        }
    }

    if (_window != null) {
        // We have successfully found the window
        // Let's check that we have not missed a blocker
        if (ModalityHelper.isModalBlocked(_window)) {
            _window = ModalityHelper.getModalBlockerFor(_window);
        }
    }

    if (SystemInfo.isAppleJvm && MacUtil.getWindowTitle(_window) == null) {
        // With Apple JDK we cannot find a window if it does not have a title
        // Let's show a dialog instead of the message.
        throw new MacMessageException("MacMessage parent does not have a title.");
    }
    while (_window != null && MacUtil.getWindowTitle(_window) == null) {
        _window = _window.getOwner();
        //At least our frame should have a title
    }

    while (Registry.is("skip.untitled.windows.for.mac.messages") && _window != null
            && _window instanceof JDialog && !((JDialog) _window).isModal()) {
        _window = _window.getOwner();
    }

    return _window;
}