diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/actions/ChangeProjectViewAction.java b/platform/lang-impl/src/com/intellij/ide/projectView/actions/ChangeProjectViewAction.java index 62949c8893f2..7a5dbb0460c0 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/actions/ChangeProjectViewAction.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/actions/ChangeProjectViewAction.java @@ -1,5 +1,4 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - package com.intellij.ide.projectView.actions; import com.intellij.ide.projectView.ProjectView; @@ -11,27 +10,27 @@ import com.intellij.openapi.wm.ToolWindowId; import com.intellij.openapi.wm.ToolWindowManager; import org.jetbrains.annotations.NotNull; -public final class ChangeProjectViewAction extends AnAction { +final class ChangeProjectViewAction extends AnAction { @Override public void actionPerformed(@NotNull AnActionEvent e) { Project project = e.getProject(); if (project == null) { return; } - ProjectView projectView = ProjectView.getInstance(project); - projectView.changeView(); + ProjectView.getInstance(project).changeView(); } @Override public void update(@NotNull AnActionEvent event){ Presentation presentation = event.getPresentation(); Project project = event.getProject(); - if (project == null){ + if (project == null) { presentation.setEnabled(false); return; } + ToolWindowManager windowManager = ToolWindowManager.getInstance(project); String id = windowManager.getActiveToolWindowId(); - presentation.setEnabled(ToolWindowId.PROJECT_VIEW.equals(id) && !windowManager.isEditorComponentActive()); + presentation.setEnabled(ToolWindowId.PROJECT_VIEW.equals(id)); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/FrameWrapper.java b/platform/platform-impl/src/com/intellij/openapi/ui/FrameWrapper.java index 074187509959..163c64c1b881 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/FrameWrapper.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/FrameWrapper.java @@ -274,6 +274,10 @@ public class FrameWrapper implements Disposable, DataProvider { return myFrame; } + public boolean isActive() { + return myFrame != null && myFrame.isActive(); + } + @NotNull protected JFrame createJFrame(@NotNull IdeFrame parent) { return new MyJFrame(this, parent); 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 5de0b264ffdf..9308cbc37102 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 @@ -50,6 +50,7 @@ import com.intellij.openapi.wm.ex.ToolWindowManagerEx import com.intellij.openapi.wm.ex.ToolWindowManagerListener import com.intellij.openapi.wm.ex.WindowManagerEx import com.intellij.openapi.wm.impl.commands.RequestFocusInToolWindowCommand +import com.intellij.openapi.wm.impl.content.ToolWindowContentUi import com.intellij.ui.BalloonImpl import com.intellij.ui.ComponentUtil import com.intellij.ui.GuiUtils @@ -591,9 +592,31 @@ open class ToolWindowManagerImpl(val project: Project) : ToolWindowManagerEx(), override val activeToolWindowId: String? get() { ApplicationManager.getApplication().assertIsDispatchThread() - return idToEntry.values.firstOrNull { - it.readOnlyWindowInfo.isActive - }?.toolWindow?.id + val frame = frame?.frame ?: return null + if (frame.isActive) { + val focusOwner = focusManager.getLastFocusedFor(frame) ?: return null + + var parent: Component? = focusOwner + while (parent != null) { + if (parent is InternalDecorator) { + return parent.toolWindow.id + } + else if (parent is ToolWindowContentUi) { + return parent.toolWindowId + } + + parent = parent.parent + } + } + else { + // let's check floating and windowed + for (entry in idToEntry.values) { + if (entry.floatingDecorator?.isActive == true || entry.windowedDecorator?.isActive == true) { + return entry.id + } + } + } + return null } override fun getLastActiveToolWindowId(): String? { diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ToolWindowContentUi.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ToolWindowContentUi.java index c9ab255adb3d..404b3963d87b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ToolWindowContentUi.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ToolWindowContentUi.java @@ -101,6 +101,11 @@ public final class ToolWindowContentUi extends JPanel implements ContentUI, Data }); } + @NotNull + public String getToolWindowId() { + return myWindow.getId(); + } + @Override public void uiSettingsChanged(@NotNull UISettings uiSettings) { revalidate();