From b4137e5711a288b8174d8d836e5b63a99861db3f Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 24 Apr 2015 14:29:45 +0200 Subject: [PATCH] =?UTF-8?q?RerunFailedTestsAction=20=E2=80=94=20prepare=20?= =?UTF-8?q?to=20fix=20IDEA-79203=20Re-run=20keyboard=20shortcut=20(Ctrl-F5?= =?UTF-8?q?)=20doesn't=20work?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../execution/ui/RunContentDescriptor.java | 32 +++++++++---- .../AbstractRerunFailedTestsAction.java | 4 ++ .../actions/RerunFailedTestsAction.java | 48 ++++++++++++++----- .../xdebugger/impl/ui/XDebugSessionTab.java | 15 +++++- 4 files changed, 75 insertions(+), 24 deletions(-) diff --git a/platform/lang-api/src/com/intellij/execution/ui/RunContentDescriptor.java b/platform/lang-api/src/com/intellij/execution/ui/RunContentDescriptor.java index 618b3c1dd15f..c65510baa272 100644 --- a/platform/lang-api/src/com/intellij/execution/ui/RunContentDescriptor.java +++ b/platform/lang-api/src/com/intellij/execution/ui/RunContentDescriptor.java @@ -47,7 +47,7 @@ public class RunContentDescriptor implements Disposable { private Content myContent; @NotNull - private AnAction[] myRestartActions = AnAction.EMPTY_ARRAY; + private final AnAction[] myRestartActions; @Nullable private final Runnable myActivationCallback; @@ -58,6 +58,16 @@ public class RunContentDescriptor implements Disposable { String displayName, @Nullable Icon icon, @Nullable Runnable activationCallback) { + this(executionConsole, processHandler, component, displayName, icon, activationCallback, null); + } + + public RunContentDescriptor(@Nullable ExecutionConsole executionConsole, + @Nullable ProcessHandler processHandler, + @NotNull JComponent component, + String displayName, + @Nullable Icon icon, + @Nullable Runnable activationCallback, + @Nullable AnAction[] restartActions) { myExecutionConsole = executionConsole; myProcessHandler = processHandler; myComponent = component; @@ -68,6 +78,8 @@ public class RunContentDescriptor implements Disposable { if (myExecutionConsole != null) { Disposer.register(this, myExecutionConsole); } + + myRestartActions = restartActions == null ? AnAction.EMPTY_ARRAY : restartActions; } public RunContentDescriptor(@Nullable ExecutionConsole executionConsole, @@ -75,23 +87,25 @@ public class RunContentDescriptor implements Disposable { @NotNull JComponent component, String displayName, @Nullable Icon icon) { - this(executionConsole, processHandler, component, displayName, icon, null); + this(executionConsole, processHandler, component, displayName, icon, null, null); } public RunContentDescriptor(@Nullable ExecutionConsole executionConsole, @Nullable ProcessHandler processHandler, @NotNull JComponent component, String displayName) { - this(executionConsole, processHandler, component, displayName, null); + this(executionConsole, processHandler, component, displayName, null, null, null); } public RunContentDescriptor(@NotNull RunProfile profile, @NotNull ExecutionResult executionResult, @NotNull RunnerLayoutUi ui) { - this(executionResult.getExecutionConsole(), executionResult.getProcessHandler(), ui.getComponent(), profile.getName(), - profile.getIcon()); + this(executionResult.getExecutionConsole(), + executionResult.getProcessHandler(), + ui.getComponent(), + profile.getName(), + profile.getIcon(), + null, + executionResult instanceof DefaultExecutionResult ? ((DefaultExecutionResult)executionResult).getRestartActions() : null); myRunnerLayoutUi = ui; - if (executionResult instanceof DefaultExecutionResult) { - myRestartActions = ((DefaultExecutionResult)executionResult).getRestartActions(); - } } public Runnable getActivationCallback() { @@ -103,7 +117,7 @@ public class RunContentDescriptor implements Disposable { */ @NotNull public AnAction[] getRestartActions() { - return myRestartActions.clone(); + return myRestartActions.length == 0 ? AnAction.EMPTY_ARRAY : myRestartActions.clone(); } public ExecutionConsole getExecutionConsole() { diff --git a/platform/testRunner/src/com/intellij/execution/testframework/actions/AbstractRerunFailedTestsAction.java b/platform/testRunner/src/com/intellij/execution/testframework/actions/AbstractRerunFailedTestsAction.java index d9f87a90cba6..50570075d36b 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/actions/AbstractRerunFailedTestsAction.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/actions/AbstractRerunFailedTestsAction.java @@ -137,6 +137,10 @@ public class AbstractRerunFailedTestsAction extends AnAction implements AnAction return; } + execute(e, environment); + } + + void execute(@NotNull AnActionEvent e, @NotNull ExecutionEnvironment environment) { MyRunProfile profile = getRunProfile(environment); if (profile == null) { return; diff --git a/platform/testRunner/src/com/intellij/execution/testframework/actions/RerunFailedTestsAction.java b/platform/testRunner/src/com/intellij/execution/testframework/actions/RerunFailedTestsAction.java index 655981fcdea6..3cc267b1424b 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/actions/RerunFailedTestsAction.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/actions/RerunFailedTestsAction.java @@ -16,40 +16,62 @@ package com.intellij.execution.testframework.actions; import com.intellij.execution.ExecutionManager; +import com.intellij.execution.runners.ExecutionEnvironment; import com.intellij.execution.ui.RunContentDescriptor; -import com.intellij.execution.ui.layout.ViewContext; import com.intellij.ide.DataManager; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.project.Project; import org.jetbrains.annotations.NotNull; import javax.swing.*; class RerunFailedTestsAction extends AnAction { + @Override + public void update(AnActionEvent e) { + e.getPresentation().setEnabled(getAction(e, false)); + } + @Override public void actionPerformed(@NotNull AnActionEvent e) { + getAction(e, true); + } + + private static boolean getAction(@NotNull AnActionEvent e, boolean execute) { Project project = e.getProject(); if (project == null) { - return; + return false; } - RunContentDescriptor content = ExecutionManager.getInstance(project).getContentManager().getSelectedContent(); - if (content == null) { - return; + RunContentDescriptor contentDescriptor = ExecutionManager.getInstance(project).getContentManager().getSelectedContent(); + if (contentDescriptor == null) { + return false; } - JComponent component = content.getComponent(); + JComponent component = contentDescriptor.getComponent(); if (component == null) { - return; + return false; } - @SuppressWarnings("ConstantConditions") - DataContext dataContext = DataManager.getInstance().getDataContext(component); - ViewContext viewContext = ViewContext.CONTEXT_KEY.getData(dataContext); - if (viewContext != null) { - + ExecutionEnvironment environment = LangDataKeys.EXECUTION_ENVIRONMENT.getData(DataManager.getInstance().getDataContext(component)); + if (environment == null) { + return false; } + + AnAction[] actions = contentDescriptor.getRestartActions(); + if (actions.length == 0) { + return false; + } + + for (AnAction action : actions) { + if (action instanceof AbstractRerunFailedTestsAction) { + if (execute) { + ((AbstractRerunFailedTestsAction)action).execute(e, environment); + } + return true; + } + } + return false; } } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionTab.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionTab.java index 3f9f6ca0f2df..349b64742446 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionTab.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionTab.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -39,6 +39,7 @@ import com.intellij.ui.content.ContentManagerAdapter; import com.intellij.ui.content.ContentManagerEvent; import com.intellij.ui.content.tabs.PinToolwindowTabAction; import com.intellij.util.SystemProperties; +import com.intellij.util.containers.ContainerUtil; import com.intellij.xdebugger.XDebugSession; import com.intellij.xdebugger.XDebuggerBundle; import com.intellij.xdebugger.impl.XDebugSessionImpl; @@ -137,8 +138,18 @@ public class XDebugSessionTab extends DebuggerSessionTabBase { mySession = session; mySessionData = session.getSessionData(); myConsole = session.getConsoleView(); + + AnAction[] restartActions; + List restartActionsList = session.getRestartActions(); + if (ContainerUtil.isEmpty(restartActionsList)) { + restartActions = AnAction.EMPTY_ARRAY; + } + else { + restartActions = restartActionsList.toArray(new AnAction[restartActionsList.size()]); + } + myRunContentDescriptor = new RunContentDescriptor(myConsole, session.getDebugProcess().getProcessHandler(), - myUi.getComponent(), session.getSessionName(), icon, myRebuildWatchesRunnable); + myUi.getComponent(), session.getSessionName(), icon, myRebuildWatchesRunnable, restartActions); Disposer.register(myRunContentDescriptor, this); Disposer.register(myProject, myRunContentDescriptor); }