public boolean isFocused() { IdeFocusManager fm = IdeFocusManager.getInstance(myProject); Component component = fm.getFocusedDescendantFor(myToolWindow.getComponent()); if (component != null) return true; Component owner = fm.getLastFocusedFor(WindowManager.getInstance().getIdeFrame(myProject)); return owner != null && SwingUtilities.isDescendingFrom(owner, myToolWindow.getComponent()); }
@Nullable private ToolWindow getWindow(AnActionEvent event) { if (myWindow != null) return myWindow; Project project = CommonDataKeys.PROJECT.getData(event.getDataContext()); if (project == null) return null; ToolWindowManager manager = ToolWindowManager.getInstance(project); final ToolWindow window = manager.getToolWindow(manager.getActiveToolWindowId()); if (window == null) return null; final Component context = PlatformDataKeys.CONTEXT_COMPONENT.getData(event.getDataContext()); if (context == null) return null; return SwingUtilities.isDescendingFrom(window.getComponent(), context) ? window : null; }
private void disposeFocusTrackbackIfNoChildWindowFocused( @Nullable IdeFocusManager focusManager) { if (myFocusTrackback == null) return; final DialogWrapper wrapper = myDialogWrapper.get(); if (wrapper == null || !wrapper.isShowing()) { myFocusTrackback.dispose(); return; } if (focusManager != null) { final Component c = focusManager.getFocusedDescendantFor(wrapper.getContentPane()); if (c == null) { myFocusTrackback.dispose(); } } else { final Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); if (owner == null || !SwingUtilities.isDescendingFrom(owner, wrapper.getContentPane())) { myFocusTrackback.dispose(); } } }