mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
continue WEB-1171 javascript live console: execution enabled condition
This commit is contained in:
+2
-1
@@ -246,7 +246,8 @@ public abstract class AbstractConsoleRunnerWithHistory<T extends LanguageConsole
|
||||
public static AnAction createConsoleExecAction(final LanguageConsoleImpl languageConsole,
|
||||
final ProcessHandler processHandler,
|
||||
final ConsoleExecuteActionHandler consoleExecuteActionHandler) {
|
||||
return new ProcessBackedConsoleExecuteAction(languageConsole, processHandler, consoleExecuteActionHandler);
|
||||
return new ConsoleExecuteAction(languageConsole, consoleExecuteActionHandler, ConsoleExecuteAction.CONSOLE_EXECUTE_ACTION_ID,
|
||||
new LanguageConsoleBuilder.ProcessBackedExecutionEnabledCondition(processHandler));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -23,24 +23,28 @@ import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.EmptyAction;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Conditions;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ConsoleExecuteAction extends DumbAwareAction {
|
||||
public static final String CONSOLE_EXECUTE_ACTION_ID = "Console.Execute";
|
||||
static final String CONSOLE_EXECUTE_ACTION_ID = "Console.Execute";
|
||||
|
||||
private final LanguageConsoleImpl myConsole;
|
||||
private final BaseConsoleExecuteActionHandler myExecuteActionHandler;
|
||||
private final Condition<LanguageConsoleImpl> myEnabledCondition;
|
||||
|
||||
public ConsoleExecuteAction(@NotNull LanguageConsoleImpl console, @NotNull BaseConsoleExecuteActionHandler executeActionHandler) {
|
||||
this(console, executeActionHandler, CONSOLE_EXECUTE_ACTION_ID);
|
||||
this(console, executeActionHandler, CONSOLE_EXECUTE_ACTION_ID, Conditions.<LanguageConsoleImpl>alwaysTrue());
|
||||
}
|
||||
|
||||
public ConsoleExecuteAction(@NotNull LanguageConsoleImpl console, @NotNull BaseConsoleExecuteActionHandler executeActionHandler,
|
||||
@NotNull String emptyExecuteActionId) {
|
||||
@NotNull String emptyExecuteActionId, @NotNull Condition<LanguageConsoleImpl> 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);
|
||||
}
|
||||
}
|
||||
@@ -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<LanguageConsoleImpl> 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<LanguageConsoleImpl> 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<LanguageConsoleImpl> {
|
||||
private ProcessHandler myProcessHandler;
|
||||
|
||||
public ProcessBackedExecutionEnabledCondition(ProcessHandler myProcessHandler) {
|
||||
this.myProcessHandler = myProcessHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean value(LanguageConsoleImpl console) {
|
||||
return !myProcessHandler.isProcessTerminated();
|
||||
}
|
||||
}
|
||||
}
|
||||
-21
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user