Execute code fragment in console action(PY-2633).
authorDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Tue, 1 Mar 2011 13:02:02 +0000 (16:02 +0300)
committerDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Tue, 1 Mar 2011 13:03:59 +0000 (16:03 +0300)
platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java
platform/lang-impl/src/com/intellij/execution/runners/AbstractConsoleRunnerWithHistory.java
platform/lang-impl/src/com/intellij/execution/runners/ConsoleExecuteActionHandler.java

index bc703320ecca7e1e520fdc0a31f1be0dc5a5a413..d649cb12e87528438475f5e139b462c50ffe15d5 100644 (file)
@@ -365,7 +365,7 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider {
     myHistoryViewer.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
   }
 
-  private String addTextRangeToHistory(TextRange textRange, final EditorEx consoleEditor, boolean preserveMarkup) {
+  protected String addTextRangeToHistory(TextRange textRange, final EditorEx consoleEditor, boolean preserveMarkup) {
     final DocumentImpl history = (DocumentImpl)myHistoryViewer.getDocument();
     final MarkupModel markupModel = history.getMarkupModel(myProject);
     appendToHistoryDocument(history, myPrompt);
index 14ca394d105f5a326f10bbf8fe7ab31a5dff2a26..4fa5ab1871b0783b7a3aa5e8f5e1af443215e764 100644 (file)
@@ -242,10 +242,8 @@ public abstract class AbstractConsoleRunnerWithHistory {
   public static ConsoleExecutionActions createConsoleExecActions(final LanguageConsoleImpl languageConsole,
                                                                  final ProcessHandler processHandler,
                                                                  final ConsoleExecuteActionHandler consoleExecuteActionHandler) {
-    final ConsoleHistoryModel myHistory = new ConsoleHistoryModel();
-
     final AnAction runAction = new ConsoleExecuteAction(languageConsole,
-                                                        myHistory, processHandler, consoleExecuteActionHandler);
+                                                        processHandler, consoleExecuteActionHandler);
 
     final PairProcessor<AnActionEvent, String> historyProcessor = new PairProcessor<AnActionEvent, String>() {
       public boolean process(final AnActionEvent e, final String s) {
@@ -260,10 +258,10 @@ public abstract class AbstractConsoleRunnerWithHistory {
 
     final EditorEx consoleEditor = languageConsole.getConsoleEditor();
     final AnAction upAction = ConsoleHistoryModel.createConsoleHistoryUpAction(createCanMoveUpComputable(consoleEditor),
-                                                                               myHistory,
+                                                                               consoleExecuteActionHandler.getConsoleHistoryModel(),
                                                                                historyProcessor);
     final AnAction downAction = ConsoleHistoryModel.createConsoleHistoryDownAction(createCanMoveDownComputable(consoleEditor),
-                                                                                   myHistory,
+                                                                                   consoleExecuteActionHandler.getConsoleHistoryModel(),
                                                                                    historyProcessor);
 
     return new ConsoleExecutionActions(runAction, downAction, upAction);
@@ -331,26 +329,23 @@ public abstract class AbstractConsoleRunnerWithHistory {
     public static final String CONSOLE_EXECUTE = "Console.Execute";
 
     private final LanguageConsoleImpl myLanguageConsole;
-    private final ConsoleHistoryModel myHistory;
     private final ProcessHandler myProcessHandler;
 
     private final ConsoleExecuteActionHandler myConsoleExecuteActionHandler;
 
 
     public ConsoleExecuteAction(LanguageConsoleImpl languageConsole,
-                                ConsoleHistoryModel history,
                                 ProcessHandler processHandler,
                                 ConsoleExecuteActionHandler consoleExecuteActionHandler) {
       super(null, null, IconLoader.getIcon(ACTIONS_EXECUTE_ICON));
       myLanguageConsole = languageConsole;
-      myHistory = history;
       myProcessHandler = processHandler;
       myConsoleExecuteActionHandler = consoleExecuteActionHandler;
       EmptyAction.setupAction(this, CONSOLE_EXECUTE, null);
     }
 
     public void actionPerformed(final AnActionEvent e) {
-      myConsoleExecuteActionHandler.runExecuteAction(myLanguageConsole, myHistory);
+      myConsoleExecuteActionHandler.runExecuteAction(myLanguageConsole);
     }
 
     public void update(final AnActionEvent e) {
index e9ada53cb4b0eda0ff3d78817ed74674bd1f41f4..5bd6b971f8d49e882206e797d1e37a4ee49eb125 100644 (file)
@@ -26,21 +26,29 @@ import java.io.IOException;
 import java.io.OutputStream;
 
 /**
-* @author traff
-*/
+ * @author traff
+ */
 public class ConsoleExecuteActionHandler {
   private final ProcessHandler myProcessHandler;
   private final boolean myPreserveMarkup;
   private boolean myAddCurrentToHistory = true;
+  private ConsoleHistoryModel myConsoleHistoryModel;
 
   public ConsoleExecuteActionHandler(ProcessHandler processHandler, boolean preserveMarkup) {
     myProcessHandler = processHandler;
+    myConsoleHistoryModel = new ConsoleHistoryModel();
     myPreserveMarkup = preserveMarkup;
   }
 
+  public void setConsoleHistoryModel(ConsoleHistoryModel consoleHistoryModel) {
+    myConsoleHistoryModel = consoleHistoryModel;
+  }
 
-  public void runExecuteAction(LanguageConsoleImpl languageConsole,
-                                  ConsoleHistoryModel consoleHistoryModel) {
+  public ConsoleHistoryModel getConsoleHistoryModel() {
+    return myConsoleHistoryModel;
+  }
+
+  public void runExecuteAction(LanguageConsoleImpl languageConsole) {
 
     // Process input and add to history
     final Document document = languageConsole.getCurrentEditor().getDocument();
@@ -53,9 +61,10 @@ public class ConsoleExecuteActionHandler {
     }
     languageConsole.setInputText("");
     if (!StringUtil.isEmptyOrSpaces(text)) {
-      consoleHistoryModel.addToHistory(text);
+      myConsoleHistoryModel.addToHistory(text);
     }
     // Send to interpreter / server
+
     processLine(text);
   }