auto test: simplify ToggleAutoTestAction creation (no need in ExecutionEnvironment) appcode/140.2302 clion/140.2303 dbe/140.2307 pycharm/140.2301 rubymine/140.2304
authorSergey Simonchik <sergey.simonchik@jetbrains.com>
Sun, 8 Feb 2015 22:55:28 +0000 (01:55 +0300)
committerSergey Simonchik <sergey.simonchik@jetbrains.com>
Sun, 8 Feb 2015 22:55:28 +0000 (01:55 +0300)
platform/testRunner/src/com/intellij/execution/testframework/ToolbarPanel.java
platform/testRunner/src/com/intellij/execution/testframework/autotest/AdjustAutotestDelayActionGroup.java
platform/testRunner/src/com/intellij/execution/testframework/autotest/AutoTestManager.java
platform/testRunner/src/com/intellij/execution/testframework/autotest/ToggleAutoTestAction.java

index 71dd853d0722972f1507dd079fe06ca21b6e4d2f..7eaf9c1754d530126764d230d87f428982c33493 100644 (file)
@@ -102,7 +102,7 @@ public class ToolbarPanel extends JPanel implements OccurenceNavigator, Disposab
                                                     properties, TestConsoleProperties.OPEN_FAILURE_LINE)).setAsSecondary(true);
 
     actionGroup.addAction(new ShowStatisticsAction(properties)).setAsSecondary(true);
-    actionGroup.addAction(new AdjustAutotestDelayActionGroup(environment)).setAsSecondary(true);
+    actionGroup.addAction(new AdjustAutotestDelayActionGroup(environment.getProject(), parent)).setAsSecondary(true);
 
     for (ToggleModelActionProvider actionProvider : Extensions.getExtensions(ToggleModelActionProvider.EP_NAME)) {
       final ToggleModelAction toggleModelAction = actionProvider.createToggleModelAction(properties);
index c6536cdb0f615e35f7705ee7010bd6e019441055..4b8a2ffa75ec8091ffe47e10b477eb3b966c7220 100644 (file)
  */
 package com.intellij.execution.testframework.autotest;
 
-import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.openapi.actionSystem.ActionGroup;
-import com.intellij.openapi.actionSystem.AnAction;
-import com.intellij.openapi.actionSystem.AnActionEvent;
-import com.intellij.openapi.actionSystem.ToggleAction;
+import com.intellij.execution.ui.RunContentDescriptor;
+import com.intellij.ide.DataManager;
+import com.intellij.openapi.actionSystem.*;
 import com.intellij.openapi.project.Project;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
+import javax.swing.*;
+
 /**
  * @author Dennis.Ushakov
  */
 public class AdjustAutotestDelayActionGroup extends ActionGroup {
   public static final int MAX_DELAY = 10;
-  private final ExecutionEnvironment myEnvironment;
+  private final Project myProject;
+  private final DataContext myDataContext;
 
-  public AdjustAutotestDelayActionGroup(ExecutionEnvironment environment) {
+  public AdjustAutotestDelayActionGroup(@NotNull Project project, @NotNull JComponent parent) {
     super("Set AutoTest Delay", true);
-    myEnvironment = environment;
+    myProject = project;
+    myDataContext = DataManager.getInstance().getDataContext(parent);
   }
 
   @Override
   public void update(AnActionEvent e) {
-    e.getPresentation().setVisible(Boolean.TRUE == myEnvironment.getUserData(AutoTestManager.AUTOTESTABLE));
+    RunContentDescriptor descriptor = LangDataKeys.RUN_CONTENT_DESCRIPTOR.getData(myDataContext);
+    boolean visible = false;
+    if (descriptor != null) {
+      for (AnAction action : descriptor.getRestartActions()) {
+        if (action instanceof ToggleAutoTestAction) {
+          visible = true;
+          break;
+        }
+      }
+    }
+    e.getPresentation().setVisible(visible);
   }
 
   @NotNull
@@ -46,7 +58,7 @@ public class AdjustAutotestDelayActionGroup extends ActionGroup {
   public AnAction[] getChildren(@Nullable AnActionEvent e) {
     final AnAction[] actions = new AnAction[MAX_DELAY];
     for (int i = 0; i < MAX_DELAY; i++) {
-      actions[i] = new SetAutoTestDelayAction(myEnvironment.getProject(), i + 1);
+      actions[i] = new SetAutoTestDelayAction(myProject, i + 1);
     }
     return actions;
   }
index b02adb8c0c67aba5b3d045c6c45a43d5968ea582..cb7cc00f0276daeaf378e21c5d2af092a261ad70 100644 (file)
@@ -47,7 +47,6 @@ import javax.swing.*;
  * @author yole
  */
 public class AutoTestManager {
-  static final Key<Boolean> AUTOTESTABLE = Key.create("auto.test.manager.supported");
   private static final String AUTO_TEST_MANAGER_DELAY = "auto.test.manager.delay";
   private static final Key<ProcessListener> ON_TERMINATION_RESTARTER_KEY = Key.create("auto.test.manager.on.termination.restarter");
   private static final Key<ExecutionEnvironment> EXECUTION_ENVIRONMENT_KEY = Key.create("auto.test.manager.execution.environment");
index 8338625e34ece2c7c111aa5903ab1fd730ecfd09..1031ed63644e69aa2f8a84abfca8c1b1edc4337b 100644 (file)
@@ -13,10 +13,19 @@ import com.intellij.openapi.project.Project;
  * @author yole
  */
 public class ToggleAutoTestAction extends ToggleAction {
+  /**
+   * @deprecated use default constructor instead
+   * @param environment
+   * To be removed in IDEA 16
+   */
+  @Deprecated
   public ToggleAutoTestAction(ExecutionEnvironment environment) {
+    this();
+  }
+
+  public ToggleAutoTestAction() {
     super("Toggle auto-test", "Toggle automatic rerun of tests on code changes",
           AllIcons.Actions.SwapPanels);
-    environment.putUserData(AutoTestManager.AUTOTESTABLE, true);
   }
 
   @Override