xdebug uses real Rerun action
authorVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Mon, 11 Aug 2014 14:03:49 +0000 (16:03 +0200)
committerVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Mon, 11 Aug 2014 14:06:24 +0000 (16:06 +0200)
15 files changed:
java/debugger/impl/src/com/intellij/debugger/DefaultDebugUIEnvironment.java
platform/lang-api/src/com/intellij/execution/ExecutionManager.java
platform/lang-api/src/com/intellij/execution/ExecutorRegistry.java
platform/lang-api/src/com/intellij/execution/runners/ExecutionUtil.java
platform/lang-api/src/com/intellij/execution/ui/RunContentDescriptor.java
platform/lang-api/src/com/intellij/execution/ui/RunContentManager.java
platform/lang-api/src/com/intellij/openapi/actionSystem/LangDataKeys.java
platform/lang-impl/src/com/intellij/execution/ExecutorRegistryImpl.java
platform/lang-impl/src/com/intellij/execution/impl/ExecutionManagerImpl.java
platform/lang-impl/src/com/intellij/execution/runners/FakeRerunAction.java
platform/lang-impl/src/com/intellij/execution/runners/RerunTestsAction.java
platform/lang-impl/src/com/intellij/execution/runners/RestartAction.java
platform/lang-impl/src/com/intellij/execution/runners/RunContentBuilder.java
platform/platform-resources/src/idea/LangActions.xml
platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionTab.java

index 27dbc15402cc414574b813ada31647f51db588ab..f3ebea41ee74cb2c114548f4deb376c064d1f711 100644 (file)
@@ -94,7 +94,7 @@ public class DefaultDebugUIEnvironment implements DebugUIEnvironment {
   @Override
   public void initActions(RunContentDescriptor content, DefaultActionGroup actionGroup) {
     Executor executor = myExecutionEnvironment.getExecutor();
-    RestartAction restartAction = new RestartAction(executor, content, myExecutionEnvironment);
+    RestartAction restartAction = new RestartAction(content, myExecutionEnvironment);
     actionGroup.add(restartAction, Constraints.FIRST);
     restartAction.registerShortcut(content.getComponent());
 
index 5e9029ebf93fe46b908279b2946942c0d97c00c8..bc1caec4df9dea67ff314d57256cf70bb03f892e 100644 (file)
@@ -104,4 +104,6 @@ public abstract class ExecutionManager {
   public abstract void restartRunProfile(@Nullable ProgramRunner runner,
                                          @NotNull ExecutionEnvironment environment,
                                          @Nullable RunContentDescriptor currentDescriptor);
+
+  public abstract void restartRunProfile(@NotNull ExecutionEnvironment environment, @Nullable RunContentDescriptor currentDescriptor);
 }
index 49139be54e5889f671c06d3e1a1b641107598ce4..9efd7bfec3b1799c39c295180df5839d3f75968b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2014 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
 
 package com.intellij.execution;
 
+import com.intellij.execution.runners.ExecutionEnvironment;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.components.ApplicationComponent;
 import com.intellij.openapi.project.Project;
@@ -25,7 +26,6 @@ import org.jetbrains.annotations.NotNull;
  * @author spleaner
  */
 public abstract class ExecutorRegistry implements ApplicationComponent {
-
   public static ExecutorRegistry getInstance() {
     return ApplicationManager.getApplication().getComponent(ExecutorRegistry.class);
   }
@@ -35,5 +35,12 @@ public abstract class ExecutorRegistry implements ApplicationComponent {
 
   public abstract Executor getExecutorById(final String executorId);
 
+  @Deprecated
+  /**
+   * @deprecated
+   * to remove in IDEA 15
+   */
   public abstract boolean isStarting(Project project, String executorId, String runnerId);
+
+  public abstract boolean isStarting(@NotNull ExecutionEnvironment environment);
 }
index f0d67274d61a450629e08b864ea93b8614a77a2c..8d6e716e3338408ea3ce90179b9ec06592d9fa82 100644 (file)
 
 package com.intellij.execution.runners;
 
-import com.intellij.execution.ExecutionBundle;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.RunCanceledByUserException;
+import com.intellij.execution.*;
 import com.intellij.execution.configurations.RunProfile;
 import com.intellij.execution.process.ProcessNotCreatedException;
+import com.intellij.execution.ui.RunContentDescriptor;
 import com.intellij.ide.util.PropertiesComponent;
 import com.intellij.notification.NotificationGroup;
 import com.intellij.notification.NotificationListener;
@@ -33,6 +32,7 @@ import com.intellij.openapi.wm.ToolWindowManager;
 import com.intellij.util.ObjectUtils;
 import com.intellij.util.ui.UIUtil;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 import javax.swing.event.HyperlinkEvent;
 import javax.swing.event.HyperlinkListener;
@@ -107,4 +107,14 @@ public class ExecutionUtil {
       }
     });
   }
+
+  public static void restart(@NotNull ExecutionEnvironment environment) {
+    restart(environment, null);
+  }
+
+  public static void restart(@NotNull ExecutionEnvironment environment, @Nullable RunContentDescriptor contentDescriptor) {
+    if (!ExecutorRegistry.getInstance().isStarting(environment)) {
+      ExecutionManager.getInstance(environment.getProject()).restartRunProfile(environment, contentDescriptor == null ? environment.getContentToReuse() : contentDescriptor);
+    }
+  }
 }
index a20843e2ea8dbceb56fe89ec827736dfacb36dd1..df1875591b300aa25bd7aaf19e804d9fbbbadeb6 100644 (file)
@@ -20,6 +20,7 @@ import com.intellij.ide.DataManager;
 import com.intellij.ide.HelpIdProvider;
 import com.intellij.openapi.Disposable;
 import com.intellij.openapi.actionSystem.DataProvider;
+import com.intellij.openapi.actionSystem.LangDataKeys;
 import com.intellij.openapi.util.Computable;
 import com.intellij.openapi.util.Disposer;
 import com.intellij.ui.content.Content;
@@ -73,10 +74,7 @@ public class RunContentDescriptor implements Disposable, DataProvider {
   @Nullable
   @Override
   public Object getData(@NonNls String dataId) {
-    if (RunContentManager.RUN_CONTENT_DESCRIPTOR.is(dataId)) {
-      return this;
-    }
-    return null;
+    return LangDataKeys.RUN_CONTENT_DESCRIPTOR.is(dataId) ? this : null;
   }
 
   public ExecutionConsole getExecutionConsole() {
index 4f192197b0f9a4bb473a3902139efe9f62a331cb..94acfeebfbb9d183527c7a0d2efeb1a5293f1522 100644 (file)
@@ -20,6 +20,7 @@ import com.intellij.execution.process.ProcessHandler;
 import com.intellij.execution.runners.ExecutionEnvironment;
 import com.intellij.openapi.actionSystem.DataContext;
 import com.intellij.openapi.actionSystem.DataKey;
+import com.intellij.openapi.actionSystem.LangDataKeys;
 import com.intellij.openapi.wm.ToolWindow;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -27,8 +28,8 @@ import org.jetbrains.annotations.Nullable;
 import java.util.List;
 
 public interface RunContentManager {
-
-  DataKey<RunContentDescriptor> RUN_CONTENT_DESCRIPTOR = DataKey.create("RUN_CONTENT_DESCRIPTOR");
+  @Deprecated
+  DataKey<RunContentDescriptor> RUN_CONTENT_DESCRIPTOR = LangDataKeys.RUN_CONTENT_DESCRIPTOR;
 
   @Nullable
   RunContentDescriptor getSelectedContent();
index d8ebce443323d8ef0ac474387c6e3b34916894b8..acc7f26ec6a5e8f72414c18ab09bb8f97c166698 100644 (file)
@@ -17,7 +17,9 @@
 package com.intellij.openapi.actionSystem;
 
 import com.intellij.execution.configurations.RunProfile;
+import com.intellij.execution.runners.ExecutionEnvironment;
 import com.intellij.execution.ui.ConsoleView;
+import com.intellij.execution.ui.RunContentDescriptor;
 import com.intellij.ide.IdeView;
 import com.intellij.lang.Language;
 import com.intellij.openapi.module.ModifiableModuleModel;
@@ -63,4 +65,6 @@ public class LangDataKeys extends PlatformDataKeys {
   public static final DataKey<Library> LIBRARY = DataKey.create("project.model.library");
 
   public static final DataKey<RunProfile> RUN_PROFILE = DataKey.create("runProfile");
+  public static final DataKey<ExecutionEnvironment> EXECUTION_ENVIRONMENT = DataKey.create("executionEnvironment");
+  public static final DataKey<RunContentDescriptor> RUN_CONTENT_DESCRIPTOR = DataKey.create("RUN_CONTENT_DESCRIPTORy6gfv");
 }
index b625606e677426aaa82543247d74084b977df339..359160d39f33957a46b246b83a924d40e4cf54cf 100644 (file)
@@ -178,7 +178,12 @@ public class ExecutorRegistryImpl extends ExecutorRegistry {
 
   @Override
   public boolean isStarting(Project project, final String executorId, final String runnerId) {
-    return myInProgress.contains(new Trinity<Project, String, String>(project, executorId, runnerId));
+    return myInProgress.contains(Trinity.create(project, executorId, runnerId));
+  }
+
+  @Override
+  public boolean isStarting(@NotNull ExecutionEnvironment environment) {
+    return isStarting(environment.getProject(), environment.getExecutor().getId(), environment.getRunnerId());
   }
 
   @Override
index 8d7489761d0cde81e18dbc33ca64586da2ef4d79..36cfaa2298c1008f8866120ee001444fa91b1ba3 100644 (file)
@@ -292,6 +292,11 @@ public class ExecutionManagerImpl extends ExecutionManager implements ProjectCom
     restartRunProfile(project, null, null, null, null, null, executor, target, configuration, currentDescriptor);
   }
 
+  @Override
+  public void restartRunProfile(@NotNull ExecutionEnvironment environment, @Nullable RunContentDescriptor currentDescriptor) {
+    restartRunProfile(RunnerRegistry.getInstance().findRunnerById(environment.getRunnerId()), environment, currentDescriptor);
+  }
+
   @Override
   public void restartRunProfile(@Nullable ProgramRunner runner,
                                 @NotNull ExecutionEnvironment environment,
@@ -378,7 +383,7 @@ public class ExecutionManagerImpl extends ExecutionManager implements ProjectCom
             return;
           }
         }
-        start(project, context, runner, runProfile, runnerSettings, configurationPerRunnerSettings, configuration, executor, target,
+        start(project, context, runner, runProfile, configuration, executor, target,
               currentDescriptor);
       }
     };
@@ -389,8 +394,6 @@ public class ExecutionManagerImpl extends ExecutionManager implements ProjectCom
                             @Nullable DataContext context,
                             @Nullable ProgramRunner runner,
                             @Nullable RunProfile runProfile,
-                            @Nullable RunnerSettings runnerSettings,
-                            @Nullable ConfigurationPerRunnerSettings configurationPerRunnerSettings,
                             @Nullable RunnerAndConfigurationSettings configuration,
                             @NotNull Executor executor,
                             @NotNull ExecutionTarget target,
index 45393c328e6979fc04d847ddfac620672efe16e5..30058177c853028b9d88ed9beb8e5b76e7d7831d 100644 (file)
  */
 package com.intellij.execution.runners;
 
+import com.intellij.execution.ExecutionBundle;
+import com.intellij.execution.ExecutorRegistry;
+import com.intellij.execution.process.ProcessHandler;
+import com.intellij.execution.ui.RunContentDescriptor;
+import com.intellij.icons.AllIcons;
 import com.intellij.openapi.actionSystem.AnAction;
 import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.LangDataKeys;
 import com.intellij.openapi.actionSystem.Presentation;
 import com.intellij.openapi.project.DumbAware;
 import com.intellij.util.containers.ContainerUtil;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
+import javax.swing.*;
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 
 /**
  * @author Roman.Chernyatchik
  */
-public class FakeRerunAction extends AnAction implements DumbAware {
-  protected static final List<RestartAction> registry = ContainerUtil.createLockFreeCopyOnWriteList();
+class FakeRerunAction extends AnAction implements DumbAware {
+  @SuppressWarnings("deprecation")
+  static final List<RestartAction> registry = ContainerUtil.createLockFreeCopyOnWriteList();
 
   @Override
-  public void actionPerformed(AnActionEvent e) {
-    RestartAction action = RestartAction.findActualAction();
-    if (action != null && action.isEnabled()) {
-      action.actionPerformed(e);
+  public void update(AnActionEvent event) {
+    Presentation presentation = event.getPresentation();
+    ExecutionEnvironment environment = getEnvironment(event);
+    if (environment != null) {
+      presentation.setText(ExecutionBundle.message("rerun.configuration.action.name", environment.getRunProfile().getName()));
+
+      RunContentDescriptor descriptor = getDescriptor(event);
+      ProcessHandler processHandler = descriptor == null ? null : descriptor.getProcessHandler();
+      presentation.setIcon(processHandler != null && !processHandler.isProcessTerminated() ? AllIcons.Actions.Restart : environment.getExecutor().getIcon());
+      presentation.setEnabledAndVisible(isEnabled(event));
+      return;
     }
+
+    FakeRerunAction action = findActualAction(event);
+    presentation.setEnabled(action != null && action.isEnabled(event));
+    presentation.setVisible(false);
   }
 
   @Override
-  public void update(AnActionEvent e) {
-    final Presentation presentation = e.getPresentation();
-    RestartAction action = RestartAction.findActualAction();
-    presentation.setEnabled(action != null && action.isEnabled());
-    presentation.setVisible(false);
+  public void actionPerformed(AnActionEvent event) {
+    ExecutionEnvironment environment = getEnvironment(event);
+    if (environment != null) {
+      ExecutionUtil.restart(environment, getDescriptor(event));
+      return;
+    }
+
+    FakeRerunAction action = findActualAction(event);
+    if (action != null && action.isEnabled(event)) {
+      action.actionPerformed(event);
+    }
+  }
+
+  @Nullable
+  protected RunContentDescriptor getDescriptor(AnActionEvent event) {
+    return event.getData(LangDataKeys.RUN_CONTENT_DESCRIPTOR);
+  }
+
+  @Nullable
+  protected ExecutionEnvironment getEnvironment(AnActionEvent event) {
+    return event.getData(LangDataKeys.EXECUTION_ENVIRONMENT);
+  }
+
+  protected boolean isEnabled(AnActionEvent event) {
+    RunContentDescriptor descriptor = getDescriptor(event);
+    ProcessHandler processHandler = descriptor == null ? null : descriptor.getProcessHandler();
+    ExecutionEnvironment environment = getEnvironment(event);
+    return environment != null &&
+           !ExecutorRegistry.getInstance().isStarting(environment) &&
+           !(processHandler != null && processHandler.isProcessTerminating());
+  }
+
+  @Nullable
+  private JComponent getRunComponent(@NotNull AnActionEvent event) {
+    RunContentDescriptor descriptor = getDescriptor(event);
+    return descriptor == null ? null : descriptor.getComponent();
+  }
+
+  @Nullable
+  private static FakeRerunAction findActualAction(@NotNull final AnActionEvent event) {
+    if (registry.isEmpty()) {
+      return null;
+    }
+
+    List<FakeRerunAction> candidates = new ArrayList<FakeRerunAction>(registry);
+    Collections.sort(candidates, new Comparator<FakeRerunAction>() {
+      @Override
+      public int compare(@NotNull FakeRerunAction action1, @NotNull FakeRerunAction action2) {
+        boolean isActive1 = action1.isEnabled(event);
+        if (isActive1 != action2.isEnabled(event)) {
+          return isActive1 ? -1 : 1;
+        }
+
+        JComponent component1 = action1.getRunComponent(event);
+        JComponent component2 = action2.getRunComponent(event);
+        Window window1 = component1 == null ? null : SwingUtilities.windowForComponent(component1);
+        Window window2 = component2 == null ? null : SwingUtilities.windowForComponent(component2);
+        if (window1 == null) {
+          return 1;
+        }
+        if (window2 == null) {
+          return -1;
+        }
+
+        boolean showing1 = component1.isShowing();
+        boolean showing2 = component2.isShowing();
+        if (showing1 && !showing2) {
+          return -1;
+        }
+        if (showing2 && !showing1) {
+          return 1;
+        }
+        return (window1.isActive() ? -1 : 1);
+      }
+    });
+    return candidates.get(0);
   }
 }
index c4e8fd0a3e0d0684b375061a5a805616ac6bb781..1ab1f5b592d15b20d3e858f50c865bd95a9a5aac 100644 (file)
@@ -1,7 +1,5 @@
 package com.intellij.execution.runners;
 
-import com.intellij.execution.ExecutionManager;
-import com.intellij.execution.ExecutorRegistry;
 import com.intellij.execution.process.ProcessHandler;
 import com.intellij.execution.ui.RunContentDescriptor;
 import com.intellij.openapi.Disposable;
@@ -29,10 +27,8 @@ public class RerunTestsAction extends DumbAwareAction implements AnAction.Transp
   public static final String ID = "RerunTests";
   private static final List<RerunInfo> REGISTRY = ContainerUtil.createLockFreeCopyOnWriteList();
 
-  public static void register(@NotNull RunContentDescriptor descriptor,
-                              @NotNull ExecutionEnvironment env,
-                              @NotNull ProgramRunner runner) {
-    final RerunInfo rerunInfo = new RerunInfo(descriptor, env, runner);
+  public static void register(@NotNull RunContentDescriptor descriptor, @NotNull ExecutionEnvironment environment) {
+    final RerunInfo rerunInfo = new RerunInfo(descriptor, environment);
     REGISTRY.add(rerunInfo);
     Disposer.register(descriptor, new Disposable() {
       @Override
@@ -49,17 +45,12 @@ public class RerunTestsAction extends DumbAwareAction implements AnAction.Transp
     if (project == null) {
       return;
     }
-    ExecutionManager executionManager = ExecutionManager.getInstance(project);
     for (RerunInfo rerunInfo : REGISTRY) {
       RunContentDescriptor descriptor = rerunInfo.getDescriptor();
       if (!Disposer.isDisposed(descriptor)) {
-        ExecutionEnvironment env = rerunInfo.getEnv();
-        ProgramRunner runner = rerunInfo.getRunner();
         ProcessHandler processHandler = descriptor.getProcessHandler();
         if (processHandler != null && processHandler.isProcessTerminated()) {
-          if (!ExecutorRegistry.getInstance().isStarting(project, env.getExecutor().getId(), runner.getRunnerId())) {
-            executionManager.restartRunProfile(runner, env, descriptor);
-          }
+          ExecutionUtil.restart(rerunInfo.getEnvironment(), descriptor);
         }
       }
     }
@@ -72,30 +63,20 @@ public class RerunTestsAction extends DumbAwareAction implements AnAction.Transp
   }
 
   private static class RerunInfo {
-
     private final RunContentDescriptor myDescriptor;
     private final ExecutionEnvironment myEnv;
-    private final ProgramRunner myRunner;
 
-    public RerunInfo(@NotNull RunContentDescriptor descriptor,
-                     @NotNull ExecutionEnvironment env,
-                     @NotNull ProgramRunner runner) {
+    public RerunInfo(@NotNull RunContentDescriptor descriptor, @NotNull ExecutionEnvironment env) {
       myDescriptor = descriptor;
       myEnv = env;
-      myRunner = runner;
     }
 
     private RunContentDescriptor getDescriptor() {
       return myDescriptor;
     }
 
-    private ExecutionEnvironment getEnv() {
+    private ExecutionEnvironment getEnvironment() {
       return myEnv;
     }
-
-    private ProgramRunner getRunner() {
-      return myRunner;
-    }
   }
-
 }
index 306b6963bd7fad6edf7180142453569ffd74b5f4..52d404eff8b8cc357e6910b4ee3574d5875b4082 100644 (file)
  */
 package com.intellij.execution.runners;
 
-import com.intellij.execution.*;
-import com.intellij.execution.process.ProcessHandler;
+import com.intellij.execution.Executor;
 import com.intellij.execution.ui.RunContentDescriptor;
-import com.intellij.icons.AllIcons;
 import com.intellij.openapi.Disposable;
-import com.intellij.openapi.actionSystem.*;
+import com.intellij.openapi.actionSystem.AnAction;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.CustomShortcutSet;
+import com.intellij.openapi.actionSystem.IdeActions;
 import com.intellij.openapi.keymap.KeymapManager;
 import com.intellij.openapi.project.DumbAware;
-import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.Disposer;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
-import java.awt.*;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
 
+@Deprecated
+/**
+ * to remove in IDEA 15
+ */
 public class RestartAction extends FakeRerunAction implements DumbAware, AnAction.TransparentUpdate, Disposable {
-  private final ProgramRunner myRunner;
-  @NotNull private final RunContentDescriptor myDescriptor;
-  @NotNull private final Executor myExecutor;
-  private final ExecutionEnvironment myEnvironment;
+  private final RunContentDescriptor descriptor;
+  private final ExecutionEnvironment environment;
 
-  public RestartAction(@NotNull Executor executor,
-                       @NotNull RunContentDescriptor descriptor,
-                       @NotNull ExecutionEnvironment environment) {
+  public RestartAction(@NotNull RunContentDescriptor descriptor, @NotNull ExecutionEnvironment environment) {
     //noinspection deprecation
-    this(executor, null, descriptor, environment);
+    this(environment.getExecutor(), null, descriptor, environment);
   }
 
   @Deprecated
@@ -53,100 +48,33 @@ public class RestartAction extends FakeRerunAction implements DumbAware, AnActio
    * @deprecated environment must provide runner id
    * to remove in IDEA 15
    */
-  public RestartAction(@NotNull Executor executor,
+  public RestartAction(@SuppressWarnings("UnusedParameters") @NotNull Executor executor,
                        @Nullable ProgramRunner runner,
                        @NotNull RunContentDescriptor descriptor,
                        @NotNull ExecutionEnvironment environment) {
     Disposer.register(descriptor, this);
-    registry.add(this);
+    FakeRerunAction.registry.add(this);
 
-    myEnvironment = environment;
+    this.environment = runner == null ? environment : ExecutionEnvironmentBuilder.fix(environment, runner);
     getTemplatePresentation().setEnabled(false);
-    myRunner = runner;
-    myDescriptor = descriptor;
-    myExecutor = executor;
-    // see IDEADEV-698
-
-    if (descriptor.getRestarter() == null) {
-      descriptor.setRestarter(new Runnable() {
-        @Override
-        public void run() {
-          restart();
-        }
-      });
-    }
+    this.descriptor = descriptor;
   }
 
   @Override
   public void dispose() {
-    registry.remove(this);
-  }
-
-  @Nullable
-  static RestartAction findActualAction() {
-    if (registry.isEmpty()) {
-      return null;
-    }
-
-    List<RestartAction> candidates = new ArrayList<RestartAction>(registry);
-    Collections.sort(candidates, new Comparator<RestartAction>() {
-      @Override
-      public int compare(@NotNull RestartAction action1, @NotNull RestartAction action2) {
-        boolean isActive1 = action1.isEnabled();
-        boolean isActive2 = action2.isEnabled();
-        if (isActive1 != isActive2)
-          return isActive1? - 1 : 1;
-        Window window1 = SwingUtilities.windowForComponent(action1.myDescriptor.getComponent());
-        Window window2 = SwingUtilities.windowForComponent(action2.myDescriptor.getComponent());
-        if (window1 == null)
-          return 1;
-        if (window2 == null)
-          return -1;
-        boolean showing1 = action1.myDescriptor.getComponent().isShowing();
-        boolean showing2 = action2.myDescriptor.getComponent().isShowing();
-        if (showing1 && !showing2)
-          return -1;
-        if (showing2 && !showing1)
-          return 1;
-        return (window1.isActive() ? -1 : 1);
-      }
-    });
-    return candidates.get(0);
+    FakeRerunAction.registry.remove(this);
   }
 
   @Override
-  public void actionPerformed(final AnActionEvent e) {
-    restart();
-  }
-
-  public void restart() {
-    Project project = myEnvironment.getProject();
-    if (!ExecutorRegistry.getInstance().isStarting(project, myExecutor.getId(), getRunnerId())) {
-      ProgramRunner runner = myRunner == null ? RunnerRegistry.getInstance().findRunnerById(myEnvironment.getRunnerId()) : myRunner;
-      ExecutionManager.getInstance(project).restartRunProfile(runner, myEnvironment, myDescriptor);
-    }
-  }
-
-  private String getRunnerId() {
-    return myRunner == null ? myEnvironment.getRunnerId() : myRunner.getRunnerId();
+  @NotNull
+  protected RunContentDescriptor getDescriptor(AnActionEvent event) {
+    return descriptor;
   }
 
   @Override
-  public void update(final AnActionEvent event) {
-    final Presentation presentation = event.getPresentation();
-    String name = myEnvironment.getRunProfile().getName();
-    ProcessHandler processHandler = myDescriptor.getProcessHandler();
-    final boolean isRunning = processHandler != null && !processHandler.isProcessTerminated();
-
-    presentation.setText(ExecutionBundle.message("rerun.configuration.action.name", name));
-    presentation.setIcon(isRunning ? AllIcons.Actions.Restart : myExecutor.getIcon());
-    presentation.setEnabled(isEnabled());
-  }
-
-  boolean isEnabled() {
-    ProcessHandler processHandler = myDescriptor.getProcessHandler();
-    return !ExecutorRegistry.getInstance().isStarting(myEnvironment.getProject(), myExecutor.getId(), getRunnerId()) &&
-           !(processHandler != null && processHandler.isProcessTerminating());
+  @NotNull
+  protected ExecutionEnvironment getEnvironment(AnActionEvent event) {
+    return environment;
   }
 
   public void registerShortcut(JComponent component) {
index 712956bd670dc16183a8236d5d0779d18e576f27..06a24c2896488fc1421eebba53caef652669fda3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2014 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -18,10 +18,7 @@ package com.intellij.execution.runners;
 import com.intellij.diagnostic.logging.LogConsoleManagerBase;
 import com.intellij.diagnostic.logging.LogFilesManager;
 import com.intellij.diagnostic.logging.OutputFileUtil;
-import com.intellij.execution.DefaultExecutionResult;
-import com.intellij.execution.ExecutionManager;
-import com.intellij.execution.ExecutionResult;
-import com.intellij.execution.Executor;
+import com.intellij.execution.*;
 import com.intellij.execution.configurations.RunConfigurationBase;
 import com.intellij.execution.configurations.RunProfile;
 import com.intellij.execution.configurations.SearchScopeProvider;
@@ -60,7 +57,6 @@ public class RunContentBuilder extends LogConsoleManagerBase {
   private final LogFilesManager myManager;
 
   private RunnerLayoutUi myUi;
-  private final Executor myExecutor;
 
   /**
    * @deprecated use {@link #RunContentBuilder(ProgramRunner, com.intellij.execution.ExecutionResult, ExecutionEnvironment)}
@@ -88,7 +84,6 @@ public class RunContentBuilder extends LogConsoleManagerBase {
   public RunContentBuilder(ExecutionResult executionResult, @NotNull ExecutionEnvironment environment) {
     super(environment.getProject(), SearchScopeProvider.createSearchScope(environment.getProject(), environment.getRunProfile()));
 
-    myExecutor = environment.getExecutor();
     myManager = new LogFilesManager(environment.getProject(), this, this);
     myExecutionResult = executionResult;
     setEnvironment(environment);
@@ -142,7 +137,7 @@ public class RunContentBuilder extends LogConsoleManagerBase {
         runnerType = JAVA_RUNNER + "." + id;
       }
     }
-    myUi = RunnerLayoutUi.Factory.getInstance(getProject()).create(runnerType, myExecutor.getId(), profile.getName(), this);
+    myUi = RunnerLayoutUi.Factory.getInstance(getProject()).create(runnerType, getEnvironment().getExecutor().getId(), profile.getName(), this);
     myUi.getOptions().setMoveToGridActionEnabled(false).setMinimizeActionEnabled(false);
 
     if (ApplicationManager.getApplication().isUnitTestMode()) {
@@ -168,7 +163,7 @@ public class RunContentBuilder extends LogConsoleManagerBase {
       if (console instanceof ObservableConsoleView && !ApplicationManager.getApplication().isUnitTestMode()) {
         ((ObservableConsoleView)console).addChangeListener(new ConsoleToFrontListener((RunConfigurationBase)profile,
                                                                                       getProject(),
-                                                                                      myExecutor,
+                                                                                      getEnvironment().getExecutor(),
                                                                                       contentDescriptor,
                                                                                       myUi),
                                                            this);
@@ -192,8 +187,8 @@ public class RunContentBuilder extends LogConsoleManagerBase {
     final DefaultActionGroup consoleActions = new DefaultActionGroup();
     if (console instanceof ConsoleView) {
       AnAction[] actions = ((ConsoleView)console).createConsoleActions();
-      for (AnAction goaction: actions) {
-        consoleActions.add(goaction);
+      for (AnAction action: actions) {
+        consoleActions.add(action);
       }
     }
 
@@ -203,9 +198,15 @@ public class RunContentBuilder extends LogConsoleManagerBase {
   private ActionGroup createActionToolbar(final RunContentDescriptor contentDescriptor, final JComponent component) {
     final DefaultActionGroup actionGroup = new DefaultActionGroup();
 
-    final RestartAction restartAction = new RestartAction(myExecutor, contentDescriptor, getEnvironment());
+    final RestartAction restartAction = new RestartAction(contentDescriptor, getEnvironment());
     restartAction.registerShortcut(component);
     actionGroup.add(restartAction);
+    contentDescriptor.setRestarter(new Runnable() {
+      @Override
+      public void run() {
+        ExecutionUtil.restart(getEnvironment(), contentDescriptor);
+      }
+    });
 
     if (myExecutionResult instanceof DefaultExecutionResult) {
       final AnAction[] actions = ((DefaultExecutionResult)myExecutionResult).getRestartActions();
@@ -238,9 +239,9 @@ public class RunContentBuilder extends LogConsoleManagerBase {
     actionGroup.add(myUi.getOptions().getLayoutActions());
     actionGroup.addSeparator();
     actionGroup.add(PinToolwindowTabAction.getPinAction());
-    actionGroup.add(new CloseAction(myExecutor, contentDescriptor, getProject()));
+    actionGroup.add(new CloseAction(getEnvironment().getExecutor(), contentDescriptor, getProject()));
     final String helpId = contentDescriptor.getHelpId();
-    actionGroup.add(new ContextHelpAction(helpId != null ? helpId : myExecutor.getHelpId()));
+    actionGroup.add(new ContextHelpAction(helpId != null ? helpId : getEnvironment().getExecutor().getHelpId()));
     return actionGroup;
   }
 
index 65fa309fe3b9b891abb1371db3a3557aaa2d14c4..e57e0cf0f70ee491c633187f7f088401e42f90c0 100644 (file)
     </group>
 
     <group id="XDebugger.ToolWindow.LeftToolbar">
+      <reference ref="Rerun"/>
       <reference ref="Resume"/>
       <reference ref="Pause"/>
       <reference ref="Stop"/>
index 9405cfe35cf11898bd9fa0e4dedd710e3e2233f0..6734edd3e8385e7c58cc11a1f859f3135eede03a 100644 (file)
@@ -20,7 +20,6 @@ import com.intellij.execution.Executor;
 import com.intellij.execution.configurations.RunProfile;
 import com.intellij.execution.executors.DefaultDebugExecutor;
 import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.execution.runners.RestartAction;
 import com.intellij.execution.runners.RunContentBuilder;
 import com.intellij.execution.ui.ExecutionConsole;
 import com.intellij.execution.ui.RunContentDescriptor;
@@ -153,6 +152,9 @@ public class XDebugSessionTab extends DebuggerSessionTabBase implements DataProv
       ExecutionEnvironment environment = getEnvironment();
       return environment == null ? null : environment.getRunProfile();
     }
+    else if (LangDataKeys.EXECUTION_ENVIRONMENT.is(dataId)) {
+      return getEnvironment();
+    }
 
     if (session != null) {
       if (SESSION_KEY.is(dataId)) {
@@ -241,18 +243,14 @@ public class XDebugSessionTab extends DebuggerSessionTabBase implements DataProv
     DefaultActionGroup leftToolbar = new DefaultActionGroup();
     final Executor debugExecutor = DefaultDebugExecutor.getDebugExecutorInstance();
     ExecutionEnvironment environment = getEnvironment();
-    final Executor executor = environment != null ? environment.getExecutor() : debugExecutor;
     if (environment != null) {
-      RestartAction restartAction = new RestartAction(executor, myRunContentDescriptor, environment);
-      leftToolbar.add(restartAction);
-      restartAction.registerShortcut(myUi.getComponent());
-
       List<AnAction> additionalRestartActions = session.getRestartActions();
-      leftToolbar.addAll(additionalRestartActions);
-      if (!additionalRestartActions.isEmpty()) leftToolbar.addSeparator();
+      if (!additionalRestartActions.isEmpty()) {
+        leftToolbar.addAll(additionalRestartActions);
+        leftToolbar.addSeparator();
+      }
       leftToolbar.addAll(session.getExtraActions());
     }
-
     leftToolbar.addAll(getCustomizedActionGroup(XDebuggerActions.TOOL_WINDOW_LEFT_TOOLBAR_GROUP));
 
     for (AnAction action : session.getExtraStopActions()) {
@@ -294,7 +292,7 @@ public class XDebugSessionTab extends DebuggerSessionTabBase implements DataProv
     leftToolbar.addSeparator();
 
     leftToolbar.add(PinToolwindowTabAction.getPinAction());
-    leftToolbar.add(new CloseAction(executor, myRunContentDescriptor, getProject()));
+    leftToolbar.add(new CloseAction(environment != null ? environment.getExecutor() : debugExecutor, myRunContentDescriptor, getProject()));
     leftToolbar.add(new ContextHelpAction(debugExecutor.getHelpId()));
 
     DefaultActionGroup topToolbar = new DefaultActionGroup();