From ea4b4f205c78c579b5c288c81a2ea24705940a1d Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Mon, 9 Sep 2013 12:45:29 +0200 Subject: [PATCH] continue WEB-1171 javascript live console: execution enabled condition --- .../AbstractConsoleRunnerWithHistory.java | 3 +- .../runners/ConsoleExecuteAction.java | 12 +++++--- .../runners/LanguageConsoleBuilder.java | 30 +++++++++++++++---- .../ProcessBackedConsoleExecuteAction.java | 21 ------------- 4 files changed, 34 insertions(+), 32 deletions(-) delete mode 100644 platform/lang-impl/src/com/intellij/execution/runners/ProcessBackedConsoleExecuteAction.java diff --git a/platform/lang-impl/src/com/intellij/execution/runners/AbstractConsoleRunnerWithHistory.java b/platform/lang-impl/src/com/intellij/execution/runners/AbstractConsoleRunnerWithHistory.java index a0c840d5d338..55d8c3940017 100644 --- a/platform/lang-impl/src/com/intellij/execution/runners/AbstractConsoleRunnerWithHistory.java +++ b/platform/lang-impl/src/com/intellij/execution/runners/AbstractConsoleRunnerWithHistory.java @@ -246,7 +246,8 @@ public abstract class AbstractConsoleRunnerWithHistory myEnabledCondition; public ConsoleExecuteAction(@NotNull LanguageConsoleImpl console, @NotNull BaseConsoleExecuteActionHandler executeActionHandler) { - this(console, executeActionHandler, CONSOLE_EXECUTE_ACTION_ID); + this(console, executeActionHandler, CONSOLE_EXECUTE_ACTION_ID, Conditions.alwaysTrue()); } public ConsoleExecuteAction(@NotNull LanguageConsoleImpl console, @NotNull BaseConsoleExecuteActionHandler executeActionHandler, - @NotNull String emptyExecuteActionId) { + @NotNull String emptyExecuteActionId, @NotNull Condition enabledCondition) { super(null, null, AllIcons.Actions.Execute); myConsole = console; myExecuteActionHandler = executeActionHandler; + myEnabledCondition = enabledCondition; EmptyAction.setupAction(this, emptyExecuteActionId, null); } @@ -59,6 +63,6 @@ public class ConsoleExecuteAction extends DumbAwareAction { } protected boolean isEnabled() { - return true; + return myEnabledCondition.value(myConsole); } } \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/execution/runners/LanguageConsoleBuilder.java b/platform/lang-impl/src/com/intellij/execution/runners/LanguageConsoleBuilder.java index a64af30d8e25..e893386e802a 100644 --- a/platform/lang-impl/src/com/intellij/execution/runners/LanguageConsoleBuilder.java +++ b/platform/lang-impl/src/com/intellij/execution/runners/LanguageConsoleBuilder.java @@ -4,29 +4,47 @@ import com.intellij.execution.console.ConsoleHistoryController; import com.intellij.execution.console.LanguageConsoleImpl; import com.intellij.execution.console.LanguageConsoleView; import com.intellij.execution.process.ProcessHandler; +import com.intellij.openapi.util.Condition; +import com.intellij.openapi.util.Conditions; import org.jetbrains.annotations.NotNull; public class LanguageConsoleBuilder { private LanguageConsoleImpl myConsole; - private ProcessHandler myProcessHandler; + private Condition myExecutionEnabled = Conditions.alwaysTrue(); public LanguageConsoleBuilder console(@NotNull LanguageConsoleView console) { myConsole = console.getConsole(); return this; } - public LanguageConsoleBuilder processHandler(ProcessHandler processHandler) { - myProcessHandler = processHandler; + public LanguageConsoleBuilder processHandler(@NotNull ProcessHandler processHandler) { + myExecutionEnabled = new ProcessBackedExecutionEnabledCondition(processHandler); + return this; + } + + public LanguageConsoleBuilder executionEnabled(@NotNull Condition condition) { + myExecutionEnabled = condition; return this; } public LanguageConsoleBuilder initActions(@NotNull BaseConsoleExecuteActionHandler executeActionHandler, @NotNull String historyType) { - ConsoleExecuteAction action = myProcessHandler == null - ? new ConsoleExecuteAction(myConsole, executeActionHandler) - : new ProcessBackedConsoleExecuteAction(myConsole, myProcessHandler, executeActionHandler); + ConsoleExecuteAction action = new ConsoleExecuteAction(myConsole, executeActionHandler, ConsoleExecuteAction.CONSOLE_EXECUTE_ACTION_ID, myExecutionEnabled); action.registerCustomShortcutSet(action.getShortcutSet(), myConsole.getConsoleEditor().getComponent()); new ConsoleHistoryController(historyType, "", myConsole, executeActionHandler.getConsoleHistoryModel()).install(); return this; } + + static class ProcessBackedExecutionEnabledCondition implements Condition { + private ProcessHandler myProcessHandler; + + public ProcessBackedExecutionEnabledCondition(ProcessHandler myProcessHandler) { + this.myProcessHandler = myProcessHandler; + } + + @Override + public boolean value(LanguageConsoleImpl console) { + return !myProcessHandler.isProcessTerminated(); + } + } } \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/execution/runners/ProcessBackedConsoleExecuteAction.java b/platform/lang-impl/src/com/intellij/execution/runners/ProcessBackedConsoleExecuteAction.java deleted file mode 100644 index 7132a2ef99ee..000000000000 --- a/platform/lang-impl/src/com/intellij/execution/runners/ProcessBackedConsoleExecuteAction.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.intellij.execution.runners; - -import com.intellij.execution.console.LanguageConsoleImpl; -import com.intellij.execution.process.ProcessHandler; - -class ProcessBackedConsoleExecuteAction extends ConsoleExecuteAction { - private final ProcessHandler myProcessHandler; - - public ProcessBackedConsoleExecuteAction(LanguageConsoleImpl languageConsole, - ProcessHandler processHandler, - BaseConsoleExecuteActionHandler consoleExecuteActionHandler) { - super(languageConsole, consoleExecuteActionHandler); - - myProcessHandler = processHandler; - } - - @Override - protected boolean isEnabled() { - return !myProcessHandler.isProcessTerminated(); - } -} \ No newline at end of file