diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/InternalDecorator.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/InternalDecorator.java index b0fd7783c901..7dc3573975ea 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/InternalDecorator.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/InternalDecorator.java @@ -95,15 +95,20 @@ public final class InternalDecorator extends JPanel implements Queryable, DataPr return toolWindow.getId(); } - public boolean isFocused() { + public boolean isFocused(@NotNull IdeFrame ideFrame) { IdeFocusManager focusManager = toolWindow.getToolWindowManager().getFocusManager(); - Component component = focusManager.getFocusedDescendantFor(toolWindow.getComponent()); + JComponent toolWindowComponent = toolWindow.getComponentIfInitialized(); + if (toolWindowComponent == null) { + return false; + } + + Component component = focusManager.getFocusedDescendantFor(toolWindowComponent); if (component != null) { return true; } - Component owner = focusManager.getLastFocusedFor(WindowManager.getInstance().getIdeFrame(toolWindow.getToolWindowManager().getProject())); - return owner != null && SwingUtilities.isDescendingFrom(owner, toolWindow.getComponent()); + Component owner = focusManager.getLastFocusedFor(ideFrame); + return owner != null && SwingUtilities.isDescendingFrom(owner, toolWindowComponent); } void applyWindowInfo(@NotNull WindowInfo info) { diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowImpl.kt b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowImpl.kt index 55c22459bc67..524d67d9c5d2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowImpl.kt +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowImpl.kt @@ -19,7 +19,6 @@ import com.intellij.openapi.util.BusyObject import com.intellij.openapi.util.Disposer import com.intellij.openapi.wm.* import com.intellij.openapi.wm.ex.ToolWindowEx -import com.intellij.openapi.wm.ex.WindowManagerEx import com.intellij.openapi.wm.impl.content.ToolWindowContentUi import com.intellij.ui.LayeredIcon import com.intellij.ui.UIBundle @@ -169,8 +168,9 @@ class ToolWindowImpl internal constructor(val toolWindowManager: ToolWindowManag override fun isActive(): Boolean { ApplicationManager.getApplication().assertIsDispatchThread() - val frame = WindowManagerEx.getInstanceEx().getFrame(toolWindowManager.project) - if (frame == null || !frame.isActive || toolWindowManager.isEditorComponentActive) { + val frameHelper = toolWindowManager.getFrame() ?: return false + val frame = frameHelper.frame + if (!frame.isActive || toolWindowManager.isEditorComponentActive) { return false } @@ -179,7 +179,7 @@ class ToolWindowImpl internal constructor(val toolWindowManager: ToolWindowManag return false } else { - return windowInfo.isActive || (decorator?.isFocused ?: false) + return windowInfo.isActive || (windowInfo.isVisible && (decorator?.isFocused(frameHelper) ?: false)) } } @@ -267,7 +267,9 @@ class ToolWindowImpl internal constructor(val toolWindowManager: ToolWindowManag override fun getDecorator() = decorator!! val isFocused: Boolean - get() = decorator?.isFocused ?: false + get() { + return decorator?.isFocused(toolWindowManager.getFrame() ?: return false) ?: false + } override fun setAdditionalGearActions(value: ActionGroup?) { additionalGearActions = value diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.kt b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.kt index 6ad474815c5b..adf442ba449b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.kt +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.kt @@ -124,6 +124,8 @@ open class ToolWindowManagerImpl(val project: Project) : ToolWindowManagerEx(), } } + internal fun getFrame() = frame + @Service private class ToolWindowManagerAppLevelHelper { private var awtFocusListener: AWTEventListener? = null