mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
WEB-11324 Live Console vs. stdin
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 210 B |
Binary file not shown.
|
After Width: | Height: | Size: 534 B |
@@ -18,6 +18,7 @@ package com.intellij.execution.console;
|
||||
import com.intellij.codeInsight.lookup.Lookup;
|
||||
import com.intellij.codeInsight.lookup.LookupManager;
|
||||
import com.intellij.execution.process.ConsoleHistoryModel;
|
||||
import com.intellij.execution.ui.ConsoleViewContentType;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.EmptyAction;
|
||||
@@ -39,7 +40,7 @@ public class ConsoleExecuteAction extends DumbAwareAction {
|
||||
|
||||
private final LanguageConsoleView myConsoleView;
|
||||
private final LanguageConsoleImpl myConsole;
|
||||
private final ConsoleExecuteActionHandler myExecuteActionHandler;
|
||||
final ConsoleExecuteActionHandler myExecuteActionHandler;
|
||||
private final Condition<LanguageConsoleImpl> myEnabledCondition;
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
@@ -139,6 +140,8 @@ public class ConsoleExecuteAction extends DumbAwareAction {
|
||||
private boolean myAddToHistory = true;
|
||||
final boolean myPreserveMarkup;
|
||||
|
||||
boolean useProcessStdIn;
|
||||
|
||||
public ConsoleExecuteActionHandler(boolean preserveMarkup) {
|
||||
myCommandHistoryModel = new ConsoleHistoryModel();
|
||||
myPreserveMarkup = preserveMarkup;
|
||||
@@ -160,11 +163,21 @@ public class ConsoleExecuteAction extends DumbAwareAction {
|
||||
}
|
||||
|
||||
protected void runExecuteAction(@NotNull LanguageConsoleImpl console, @Nullable LanguageConsoleView consoleView) {
|
||||
beforeExecution(console);
|
||||
if (!useProcessStdIn) {
|
||||
beforeExecution(console);
|
||||
}
|
||||
|
||||
String text = console.prepareExecuteAction(myAddToHistory, myPreserveMarkup, true);
|
||||
String text = console.prepareExecuteAction(myAddToHistory && !useProcessStdIn, myPreserveMarkup, true);
|
||||
((UndoManagerImpl)UndoManager.getInstance(console.getProject())).invalidateActionsFor(DocumentReferenceManager.getInstance().create(console.getCurrentEditor().getDocument()));
|
||||
addToCommandHistoryAndExecute(console, consoleView, text);
|
||||
|
||||
if (useProcessStdIn) {
|
||||
assert consoleView != null;
|
||||
consoleView.print(text, ConsoleViewContentType.USER_INPUT);
|
||||
consoleView.print("\n", ConsoleViewContentType.USER_INPUT);
|
||||
}
|
||||
else {
|
||||
addToCommandHistoryAndExecute(console, consoleView, text);
|
||||
}
|
||||
}
|
||||
|
||||
private void addToCommandHistoryAndExecute(@NotNull LanguageConsoleImpl console, @Nullable LanguageConsoleView consoleView, @NotNull String text) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.intellij.execution.console;
|
||||
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
import com.intellij.execution.process.ProcessHandler;
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
@@ -60,6 +62,8 @@ public final class LanguageConsoleBuilder {
|
||||
|
||||
private boolean oneLineInput;
|
||||
|
||||
private String processInputStateKey;
|
||||
|
||||
// todo to be removed
|
||||
public LanguageConsoleBuilder(@SuppressWarnings("NullableProblems") @NotNull LanguageConsoleView consoleView) {
|
||||
this.consoleView = consoleView;
|
||||
@@ -87,6 +91,7 @@ public final class LanguageConsoleBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public LanguageConsoleBuilder initActions(@NotNull BaseConsoleExecuteActionHandler executeActionHandler, @NotNull String historyType) {
|
||||
if (consoleView == null) {
|
||||
this.executeActionHandler = executeActionHandler;
|
||||
@@ -150,6 +155,13 @@ public final class LanguageConsoleBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public LanguageConsoleBuilder processInputStateKey(@Nullable String value) {
|
||||
processInputStateKey = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public LanguageConsoleView build(@NotNull Project project, @NotNull Language language) {
|
||||
GutteredLanguageConsole console = new GutteredLanguageConsole(language.getDisplayName() + " Console", project, language, gutterContentProvider, psiFileFactory);
|
||||
if (oneLineInput) {
|
||||
@@ -160,6 +172,17 @@ public final class LanguageConsoleBuilder {
|
||||
assert historyType != null;
|
||||
doInitAction(consoleView, executeActionHandler, historyType);
|
||||
}
|
||||
|
||||
if (processInputStateKey != null) {
|
||||
assert executeActionHandler != null;
|
||||
if (PropertiesComponent.getInstance().getBoolean(processInputStateKey, false)) {
|
||||
executeActionHandler.useProcessStdIn = true;
|
||||
DaemonCodeAnalyzer daemonCodeAnalyzer = DaemonCodeAnalyzer.getInstance(consoleView.getProject());
|
||||
daemonCodeAnalyzer.setHighlightingEnabled(consoleView.getConsole().getFile(), false);
|
||||
}
|
||||
consoleView.addCustomConsoleAction(new UseConsoleInputAction(processInputStateKey));
|
||||
}
|
||||
|
||||
console.initComponents();
|
||||
return consoleView;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.intellij.execution.console;
|
||||
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.LangDataKeys;
|
||||
import com.intellij.openapi.actionSystem.ToggleAction;
|
||||
import com.intellij.openapi.actionSystem.ex.ActionUtil;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
final class UseConsoleInputAction extends ToggleAction implements DumbAware {
|
||||
private final String processInputStateKey;
|
||||
private boolean useProcessStdIn;
|
||||
|
||||
public UseConsoleInputAction(@NotNull String processInputStateKey) {
|
||||
super("Use Console Input", null, AllIcons.Debugger.CommandLine);
|
||||
|
||||
this.processInputStateKey = processInputStateKey;
|
||||
useProcessStdIn = PropertiesComponent.getInstance().getBoolean(processInputStateKey, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelected(@Nullable AnActionEvent event) {
|
||||
return !useProcessStdIn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(AnActionEvent event, boolean state) {
|
||||
useProcessStdIn = !state;
|
||||
|
||||
LanguageConsoleView consoleView = (LanguageConsoleView)event.getData(LangDataKeys.CONSOLE_VIEW);
|
||||
assert consoleView != null;
|
||||
DaemonCodeAnalyzer daemonCodeAnalyzer = DaemonCodeAnalyzer.getInstance(consoleView.getProject());
|
||||
PsiFile file = consoleView.getConsole().getFile();
|
||||
daemonCodeAnalyzer.setHighlightingEnabled(file, state);
|
||||
daemonCodeAnalyzer.restart(file);
|
||||
if (state) {
|
||||
PropertiesComponent.getInstance().unsetValue(processInputStateKey);
|
||||
}
|
||||
else {
|
||||
PropertiesComponent.getInstance().setValue(processInputStateKey, "true");
|
||||
}
|
||||
|
||||
List<AnAction> actions = ActionUtil.getActions(consoleView.getConsole().getConsoleEditor().getComponent());
|
||||
ConsoleExecuteAction action = ContainerUtil.findInstance(actions, ConsoleExecuteAction.class);
|
||||
action.myExecuteActionHandler.useProcessStdIn = !state;
|
||||
}
|
||||
}
|
||||
@@ -204,6 +204,7 @@ public class AllIcons {
|
||||
public static final Icon AutoVariablesMode = IconLoader.getIcon("/debugger/autoVariablesMode.png"); // 16x16
|
||||
public static final Icon BreakpointAlert = IconLoader.getIcon("/debugger/breakpointAlert.png"); // 16x16
|
||||
public static final Icon Class_filter = IconLoader.getIcon("/debugger/class_filter.png"); // 16x16
|
||||
public static final Icon CommandLine = IconLoader.getIcon("/debugger/commandLine.png"); // 16x16
|
||||
public static final Icon Console = IconLoader.getIcon("/debugger/console.png"); // 16x16
|
||||
public static final Icon Db_array = IconLoader.getIcon("/debugger/db_array.png"); // 16x16
|
||||
public static final Icon Db_db_object = IconLoader.getIcon("/debugger/db_db_object.png"); // 16x16
|
||||
|
||||
Reference in New Issue
Block a user