From 59ab7ba494524da37b1eedca04f88a6f9048da34 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 12 Sep 2014 14:12:40 +0200 Subject: [PATCH] WEB-11324 Live Console vs. stdin --- platform/icons/src/debugger/commandLine.png | Bin 0 -> 210 bytes .../icons/src/debugger/commandLine@2x.png | Bin 0 -> 534 bytes .../console/ConsoleExecuteAction.java | 21 +++++-- .../console/LanguageConsoleBuilder.java | 23 +++++++ .../console/UseConsoleInputAction.java | 56 ++++++++++++++++++ .../util/src/com/intellij/icons/AllIcons.java | 1 + 6 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 platform/icons/src/debugger/commandLine.png create mode 100644 platform/icons/src/debugger/commandLine@2x.png create mode 100644 platform/lang-impl/src/com/intellij/execution/console/UseConsoleInputAction.java diff --git a/platform/icons/src/debugger/commandLine.png b/platform/icons/src/debugger/commandLine.png new file mode 100644 index 0000000000000000000000000000000000000000..3d2333b0e7e87f0ff8ce09315065e5b55986b373 GIT binary patch literal 210 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Gd*1#Ln>}1|M>sko>^7Gr^V;) z*ZDF&vCQY@*;coS^duhGS^QjYQj;Oii8=efOKZ;frN_WIZQ8WDTN{&)`)=Z$VVr*M z@s%rA=D&UWc74B`ZB=Uuv%`-gox;<*ySnVuRaE|{-E3gx7PC2X>eR2eprB8ce}8=~ z_b^+qVZ(>hx3*?Kl&Y?-j(2f$``4bhXpcjgPQa8Yn&*0_BrpiNzCR-;`+*(kNCr<= KKbLh*2~7Z?^;tXs literal 0 HcmV?d00001 diff --git a/platform/icons/src/debugger/commandLine@2x.png b/platform/icons/src/debugger/commandLine@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..a70992337f1ebefc4bed3a0a90e6210236ff79db GIT binary patch literal 534 zcmV+x0_pvUP)UI600z=j8PaKK;jG&XGx0hA1Ox>It7u{Q`}gnLM$-VnG_d#{ zLlqDECrMgZ_T?u-)!+|-SS5xwK|wy6B|`LEFnAN;%9Sg{A3uJ~K41=b`t&Ks>eZ_y zfLQF=vuA8{cYuY3#Rm=!j=#WA;9Rj{h2+|`YsFr^e91=hL`R#qQPO-(sHN=i!KtgWp-h>D8-rl|u!fR&Z?znPiYCnF=H&lfLV?pmyZ#+qb!C9s(eX?%uu235o_#S^$YL zGc*5JQ&anDVq)@%rVcoB<_s?|*m*yG{KyL8v$M1R)6voSY;0`&nTLnxFU=F-p+kp+ zKr}Be?;k@$!%zD9`d>h40$I)B!-oYRCou7S($v)a#>mKs zRgJB!?FSHz&k 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) { diff --git a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleBuilder.java b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleBuilder.java index 329b9f0e3f13..a20b8c706ff2 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleBuilder.java +++ b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleBuilder.java @@ -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; } diff --git a/platform/lang-impl/src/com/intellij/execution/console/UseConsoleInputAction.java b/platform/lang-impl/src/com/intellij/execution/console/UseConsoleInputAction.java new file mode 100644 index 000000000000..5b450e3bd154 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/execution/console/UseConsoleInputAction.java @@ -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 actions = ActionUtil.getActions(consoleView.getConsole().getConsoleEditor().getComponent()); + ConsoleExecuteAction action = ContainerUtil.findInstance(actions, ConsoleExecuteAction.class); + action.myExecuteActionHandler.useProcessStdIn = !state; + } +} \ No newline at end of file diff --git a/platform/util/src/com/intellij/icons/AllIcons.java b/platform/util/src/com/intellij/icons/AllIcons.java index a80ffccdd58e..f31f9b94b058 100644 --- a/platform/util/src/com/intellij/icons/AllIcons.java +++ b/platform/util/src/com/intellij/icons/AllIcons.java @@ -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