From 793ecbb121d342b9331609afacc185e700613b1b Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Wed, 2 May 2012 21:02:27 +0200 Subject: [PATCH] better place for stop_and_run button --- .../debugger/ui/DebuggerSessionTab.java | 12 +++-- .../execution/runners/RestartAction.java | 23 ++++---- .../execution/runners/StopAndRunAction.java | 54 +++++++++++++++++++ .../impl/ui/XDebuggerUIConstants.java | 1 + 4 files changed, 75 insertions(+), 15 deletions(-) create mode 100644 platform/lang-impl/src/com/intellij/execution/runners/StopAndRunAction.java diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/DebuggerSessionTab.java b/java/debugger/impl/src/com/intellij/debugger/ui/DebuggerSessionTab.java index fa8035a41846..4f066fe2aea0 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/DebuggerSessionTab.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/DebuggerSessionTab.java @@ -40,6 +40,7 @@ import com.intellij.execution.filters.TextConsoleBuilderFactory; import com.intellij.execution.runners.ExecutionEnvironment; import com.intellij.execution.runners.ProgramRunner; import com.intellij.execution.runners.RestartAction; +import com.intellij.execution.runners.StopAndRunAction; import com.intellij.execution.ui.ConsoleView; import com.intellij.execution.ui.ExecutionConsoleEx; import com.intellij.execution.ui.RunContentDescriptor; @@ -263,9 +264,9 @@ public class DebuggerSessionTab extends DebuggerSessionTabBase implements Dispos DefaultActionGroup group = new DefaultActionGroup(); final Executor executor = DefaultDebugExecutor.getDebugExecutorInstance(); - RestartAction restarAction = new RestartAction(executor, - myRunner, myRunContentDescriptor.getProcessHandler(), XDebuggerUIConstants.DEBUG_AGAIN_ICON, - myRunContentDescriptor, myEnvironment); + final RestartAction restarAction = new RestartAction( + executor, myRunner, myRunContentDescriptor.getProcessHandler(), XDebuggerUIConstants.DEBUG_AGAIN_ICON, myRunContentDescriptor, myEnvironment + ); group.add(restarAction); restarAction.registerShortcut(myUi.getComponent()); @@ -284,6 +285,11 @@ public class DebuggerSessionTab extends DebuggerSessionTabBase implements Dispos addActionToGroup(group, XDebuggerActions.RESUME); addActionToGroup(group, XDebuggerActions.PAUSE); addActionToGroup(group, IdeActions.ACTION_STOP_PROGRAM); + final StopAndRunAction stopAndRunAction = new StopAndRunAction( + executor, myRunner, myRunContentDescriptor.getProcessHandler(), XDebuggerUIConstants.STOP_AND_START_ICON, myRunContentDescriptor, myEnvironment + ); + group.add(stopAndRunAction); + stopAndRunAction.registerShortcut(myUi.getComponent()); if (executionResult instanceof DefaultExecutionResult) { group.addAll(((DefaultExecutionResult)executionResult).getAdditionalStopActions()); } diff --git a/platform/lang-impl/src/com/intellij/execution/runners/RestartAction.java b/platform/lang-impl/src/com/intellij/execution/runners/RestartAction.java index 9571d8ca97da..810efe5d03c0 100644 --- a/platform/lang-impl/src/com/intellij/execution/runners/RestartAction.java +++ b/platform/lang-impl/src/com/intellij/execution/runners/RestartAction.java @@ -24,7 +24,7 @@ import com.intellij.openapi.keymap.KeymapManager; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.util.IconLoader; +import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -32,14 +32,11 @@ import javax.swing.*; * @author dyoma */ public class RestartAction extends AnAction implements DumbAware { - private static final Icon STOP_AND_START_ICON = IconLoader.getIcon("/actions/restart.png"); - private ProcessHandler myProcessHandler; - private final ProgramRunner myRunner; private final RunContentDescriptor myDescriptor; - private final Executor myExecutor; - private final Icon myIcon; - private final ExecutionEnvironment myEnvironment; + protected final ProgramRunner myRunner; + protected final Executor myExecutor; + protected final ExecutionEnvironment myEnvironment; public RestartAction(final Executor executor, final ProgramRunner runner, @@ -48,7 +45,6 @@ public class RestartAction extends AnAction implements DumbAware { final RunContentDescriptor descritor, final ExecutionEnvironment env) { super(null, null, icon); - myIcon = icon; myEnvironment = env; getTemplatePresentation().setEnabled(false); myProcessHandler = processHandler; @@ -58,9 +54,13 @@ public class RestartAction extends AnAction implements DumbAware { // see IDEADEV-698 } + @Nullable + protected ProcessHandler getProcessHandler() { + return myProcessHandler; + } + public void actionPerformed(final AnActionEvent e) { final DataContext dataContext = e.getDataContext(); - ActionManager.getInstance().getAction(IdeActions.ACTION_STOP_PROGRAM).actionPerformed(e); doRestart(dataContext); } @@ -71,7 +71,7 @@ public class RestartAction extends AnAction implements DumbAware { private void doRestart(final DataContext dataContext) { final Project project = PlatformDataKeys.PROJECT.getData(dataContext); if (ExecutorRegistry.getInstance().isStarting(project, myExecutor.getId(), myRunner.getRunnerId())) { - return; + return; } try { final ExecutionEnvironment old = myEnvironment; @@ -92,9 +92,8 @@ public class RestartAction extends AnAction implements DumbAware { if (myProcessHandler != null && !isRunning) { myProcessHandler = null; // already terminated } - presentation.setIcon(isRunning ? STOP_AND_START_ICON : myIcon); - presentation.setEnabled(true); + presentation.setEnabled(!isRunning /*&& myRunner.canRun(, myProfile)*/ && !ExecutorRegistry.getInstance().isStarting(myEnvironment.getProject(), myExecutor.getId(), myRunner.getRunnerId())); } public void registerShortcut(final JComponent component) { diff --git a/platform/lang-impl/src/com/intellij/execution/runners/StopAndRunAction.java b/platform/lang-impl/src/com/intellij/execution/runners/StopAndRunAction.java new file mode 100644 index 000000000000..d282e101799b --- /dev/null +++ b/platform/lang-impl/src/com/intellij/execution/runners/StopAndRunAction.java @@ -0,0 +1,54 @@ +/* + * Copyright 2000-2012 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.execution.runners; + +import com.intellij.execution.Executor; +import com.intellij.execution.process.ProcessHandler; +import com.intellij.execution.ui.RunContentDescriptor; +import com.intellij.openapi.actionSystem.ActionManager; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.IdeActions; +import com.intellij.openapi.actionSystem.Presentation; + +import javax.swing.*; + +/** + * @author dyoma + */ +public class StopAndRunAction extends RestartAction{ + + public StopAndRunAction(Executor executor, + ProgramRunner runner, + ProcessHandler processHandler, + Icon icon, + RunContentDescriptor descritor, ExecutionEnvironment env) { + super(executor, runner, processHandler, icon, descritor, env); + } + + public void actionPerformed(final AnActionEvent e) { + ActionManager.getInstance().getAction(IdeActions.ACTION_STOP_PROGRAM).actionPerformed(e); + super.actionPerformed(e); + } + + + public void update(final AnActionEvent event) { + super.update(event); + final ProcessHandler handler = getProcessHandler(); + final boolean isRunning = handler != null && !handler.isProcessTerminated(); + final Presentation presentation = event.getPresentation(); + presentation.setEnabled(isRunning); + } +} diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebuggerUIConstants.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebuggerUIConstants.java index d467eac7bea4..48ad7b5f729a 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebuggerUIConstants.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebuggerUIConstants.java @@ -44,6 +44,7 @@ public class XDebuggerUIConstants { @NonNls public static final String EQ_TEXT = " = "; public static final Icon DEBUG_AGAIN_ICON = IconLoader.getIcon("/actions/startDebugger.png"); + public static final Icon STOP_AND_START_ICON = IconLoader.getIcon("/actions/restart.png"); public static final Icon FRAMES_TAB_ICON = IconLoader.getIcon("/debugger/frame.png"); public static final Icon THREADS_TAB_ICON = IconLoader.getIcon("/debugger/threads.png"); public static final Icon VARIABLES_TAB_ICON = IconLoader.getIcon("/debugger/value.png");