[service-view] make Show Services action enabled only in Services tool window
authorKonstantin Aleev <konstantin.aleev@jetbrains.com>
Wed, 6 May 2020 09:32:53 +0000 (12:32 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Wed, 6 May 2020 09:45:40 +0000 (09:45 +0000)
GitOrigin-RevId: bad66ec273a4800e77ea251593722f5565f6a62f

platform/lang-impl/src/com/intellij/execution/services/ShowServicesAction.java

index 42b07902c30d418e0d890aef19b6f0dae6ec4a36..802509117a190d7da7a44be6c2fc109ea83807a8 100644 (file)
@@ -2,13 +2,30 @@
 package com.intellij.execution.services;
 
 import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.PlatformDataKeys;
+import com.intellij.openapi.actionSystem.Presentation;
 import com.intellij.openapi.actionSystem.ToggleAction;
 import com.intellij.openapi.project.DumbAware;
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.wm.ToolWindow;
+import com.intellij.ui.content.Content;
 import org.jetbrains.annotations.NotNull;
 
 public class ShowServicesAction extends ToggleAction implements DumbAware {
   @Override
+  public void update(@NotNull AnActionEvent e) {
+    super.update(e);
+    Presentation presentation = e.getPresentation();
+    ToolWindow toolWindow = e.getData(PlatformDataKeys.TOOL_WINDOW);
+    if (toolWindow == null) {
+      presentation.setEnabledAndVisible(false);
+      return;
+    }
+    Content content = toolWindow.getContentManager().getSelectedContent();
+    presentation.setEnabledAndVisible(content != null && content.getComponent() instanceof ServiceView);
+  }
+
+  @Override
   public boolean isSelected(@NotNull AnActionEvent e) {
     Project project = e.getProject();
     if (project == null) return true;