diff --git a/platform/platform-api/src/com/intellij/openapi/wm/ToolWindowContextMenuActionBase.java b/platform/platform-api/src/com/intellij/openapi/wm/ToolWindowContextMenuActionBase.java deleted file mode 100644 index 18fddfb0cf60..000000000000 --- a/platform/platform-api/src/com/intellij/openapi/wm/ToolWindowContextMenuActionBase.java +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2000-2018 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.openapi.wm; - -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.ui.content.Content; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public abstract class ToolWindowContextMenuActionBase extends AnAction { - @Override - public void actionPerformed(@NotNull AnActionEvent e) { - final ToolWindow toolWindow = ToolWindowManager.getActiveToolWindow(); - if (toolWindow == null) - return; - Content selectedContent = toolWindow.getContentManager().getSelectedContent(); - actionPerformed(e, toolWindow, selectedContent); - } - - @Override - public void update(@NotNull AnActionEvent e) { - super.update(e); - final ToolWindow toolWindow = ToolWindowManager.getActiveToolWindow(); - if (toolWindow == null) - return; - Content selectedContent = toolWindow.getContentManager().getSelectedContent(); - update(e, toolWindow, selectedContent); - } - - public abstract void update(@NotNull AnActionEvent e, @NotNull ToolWindow activeToolWindow, @Nullable Content selectedContent); - public abstract void actionPerformed(@NotNull AnActionEvent e, @NotNull ToolWindow activeToolWindow, @Nullable Content selectedContent); -} diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/ToolWindowContextMenuActionBase.java b/platform/platform-impl/src/com/intellij/openapi/wm/ToolWindowContextMenuActionBase.java new file mode 100644 index 000000000000..d0e324c85059 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/wm/ToolWindowContextMenuActionBase.java @@ -0,0 +1,47 @@ +// Copyright 2000-2018 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.openapi.wm; + +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.PlatformDataKeys; +import com.intellij.openapi.wm.impl.content.BaseLabel; +import com.intellij.ui.content.Content; +import com.intellij.util.ObjectUtils; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public abstract class ToolWindowContextMenuActionBase extends AnAction { + @Override + public final void actionPerformed(@NotNull AnActionEvent e) { + ToolWindow toolWindow = e.getDataContext().getData(PlatformDataKeys.TOOL_WINDOW); + if (toolWindow == null) { + return; + } + Content content = getContextContent(e, toolWindow); + actionPerformed(e, toolWindow, content); + } + + @Override + public final void update(@NotNull AnActionEvent e) { + ToolWindow toolWindow = e.getDataContext().getData(PlatformDataKeys.TOOL_WINDOW); + if (toolWindow == null) { + e.getPresentation().setEnabledAndVisible(false); + return; + } + Content content = getContextContent(e, toolWindow); + update(e, toolWindow, content); + } + + public abstract void update(@NotNull AnActionEvent e, @NotNull ToolWindow toolWindow, @Nullable Content content); + public abstract void actionPerformed(@NotNull AnActionEvent e, @NotNull ToolWindow toolWindow, @Nullable Content content); + + @Nullable + private static Content getContextContent(@NotNull AnActionEvent e, @NotNull ToolWindow toolWindow) { + BaseLabel baseLabel = ObjectUtils.tryCast(e.getData(PlatformDataKeys.CONTEXT_COMPONENT), BaseLabel.class); + Content selectedContent = baseLabel != null ? baseLabel.getContent() : null; + if (selectedContent == null) { + selectedContent = toolWindow.getContentManager().getSelectedContent(); + } + return selectedContent; + } +}