Console init moved out of the event dispatch thread.
authorDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Mon, 21 Feb 2011 17:01:32 +0000 (20:01 +0300)
committerDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Tue, 22 Feb 2011 08:19:44 +0000 (11:19 +0300)
platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java
platform/lang-impl/src/com/intellij/execution/runners/AbstractConsoleRunnerWithHistory.java

index af25959298ce37198d2dd7f92e4a04971c6efbe1..bc703320ecca7e1e520fdc0a31f1be0dc5a5a413 100644 (file)
@@ -21,6 +21,7 @@ import com.intellij.ide.impl.TypeSafeDataProviderAdapter;
 import com.intellij.lang.Language;
 import com.intellij.openapi.Disposable;
 import com.intellij.openapi.actionSystem.*;
+import com.intellij.openapi.application.Application;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.application.ModalityState;
 import com.intellij.openapi.editor.*;
@@ -373,7 +374,7 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider {
                                     HighlighterTargetArea.EXACT_RANGE);
 
     final String text = consoleEditor.getDocument().getText(textRange);
-     //offset can be changed after text trimming after insert due to buffer constraints
+    //offset can be changed after text trimming after insert due to buffer constraints
     appendToHistoryDocument(history, text);
     int offset = history.getTextLength() - text.length();
     final int localStartOffset = textRange.getStartOffset();
@@ -617,10 +618,17 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider {
       attributes = additionalType.getAttributes().clone();
       attributes.setBackgroundColor(mainAttributes.getBackgroundColor());
     }
-    ApplicationManager.getApplication().invokeLater(new Runnable() {
-      public void run() {
-        console.printToHistory(string, attributes);
-      }
-    }, ModalityState.stateForComponent(console.getComponent()));
+
+    Application application = ApplicationManager.getApplication();
+    if (application.isDispatchThread()) {
+      console.printToHistory(string, attributes);
+    }
+    else {
+      application.invokeLater(new Runnable() {
+        public void run() {
+          console.printToHistory(string, attributes);
+        }
+      }, ModalityState.stateForComponent(console.getComponent()));
+    }
   }
 }
index ef936fc4706bb9c00bb4f20e8839d5e6fd203d77..f1f6b203f471ce77e13146b8d27ed422ce93502e 100644 (file)
@@ -30,18 +30,14 @@ import com.intellij.execution.ui.RunContentDescriptor;
 import com.intellij.execution.ui.actions.CloseAction;
 import com.intellij.ide.CommonActionsManager;
 import com.intellij.openapi.actionSystem.*;
+import com.intellij.openapi.application.Application;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.application.Result;
 import com.intellij.openapi.command.WriteCommandAction;
 import com.intellij.openapi.editor.CaretModel;
 import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.editor.Editor;
-import com.intellij.openapi.editor.actions.ScrollToTheEndToolbarAction;
-import com.intellij.openapi.editor.actions.ToggleUseSoftWrapsToolbarAction;
 import com.intellij.openapi.editor.ex.EditorEx;
-import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
-import com.intellij.openapi.editor.ex.util.EditorUtil;
-import com.intellij.openapi.editor.impl.softwrap.SoftWrapAppliancePlaces;
 import com.intellij.openapi.project.DumbAwareAction;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.Computable;
@@ -60,8 +56,8 @@ import java.util.List;
 
 /**
  * @author oleg
- * This class provides basic functionality for running consoles.
- * It launches external process and handles line input with history
+ *         This class provides basic functionality for running consoles.
+ *         It launches external process and handles line input with history
  */
 public abstract class AbstractConsoleRunnerWithHistory {
   private final Project myProject;
@@ -96,6 +92,23 @@ public abstract class AbstractConsoleRunnerWithHistory {
     // Create Server process
     final Process process = createProcess(myProvider);
 
+    Application application = ApplicationManager.getApplication();
+
+    if (application.isDispatchThread()) {
+      initConsoleUI(process);
+    }
+    else {
+      application.invokeLater(new Runnable() {
+        @Override
+        public void run() {
+          initConsoleUI(process);
+        }
+      });
+    }
+  }
+
+
+  private void initConsoleUI(Process process) {
     // Init console view
     myConsoleView = createConsoleView();
 
@@ -257,7 +270,7 @@ public abstract class AbstractConsoleRunnerWithHistory {
         // Check if we have active lookup or if we can move in editor
         return LookupManager.getActiveLookup(consoleEditor) != null ||
                document.getLineNumber(caretModel.getOffset()) < document.getLineCount() - 1 &&
-                                !StringUtil.isEmptyOrSpaces(document.getText().substring(caretModel.getOffset()));
+               !StringUtil.isEmptyOrSpaces(document.getText().substring(caretModel.getOffset()));
       }
     };
   }