From d75838ad201abb98562ef7a31d978124ace272f6 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 6 Sep 2013 16:35:43 +0200 Subject: [PATCH] =?UTF-8?q?continue=20WEB-1171=20javascript=20live=20conso?= =?UTF-8?q?le=20=E2=80=94=20works=20now,=20but=20UI=20is=20ugly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../console/LanguageConsoleImpl.java | 51 ++++++++++--------- .../console/LanguageConsoleViewImpl.java | 8 ++- .../openapi/util/text/StringUtilRt.java | 15 +++++- 3 files changed, 48 insertions(+), 26 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java index 53caeb97b999..680f936eed25 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java @@ -55,6 +55,7 @@ import com.intellij.openapi.fileTypes.FileTypes; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.*; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.util.text.StringUtilRt; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; @@ -380,10 +381,6 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider { this.myTitle = title; } - public void addToHistory(final String text, final TextAttributes attributes) { - printToHistory(text, attributes); - } - public void printToHistory(@NotNull final List> attributedText) { ApplicationManager.getApplication().assertIsDispatchThread(); if (LOG.isDebugEnabled()) { @@ -400,7 +397,7 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider { } final DocumentEx history = myHistoryViewer.getDocument(); final int oldHistoryLength = history.getTextLength(); - appendToHistoryDocument(history, sb.toString()); + appendToHistoryDocument(history, sb); assert oldHistoryLength + offsets[i] >= history.getTextLength() : "unexpected history length " + oldHistoryLength + " " + offsets[i] + " " + history.getTextLength(); @@ -435,9 +432,9 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider { LOG.debug("printToHistory(): completed"); } - public void printToHistory(String text, final TextAttributes attributes) { + public void printToHistory(@NotNull CharSequence text, @NotNull TextAttributes attributes) { ApplicationManager.getApplication().assertIsDispatchThread(); - text = StringUtil.convertLineSeparators(text); + text = StringUtilRt.unifyLineSeparators(text); final boolean scrollToEnd = shouldScrollHistoryToEnd(); addTextToHistory(text, attributes); if (scrollToEnd) { @@ -446,8 +443,11 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider { queueUiUpdate(scrollToEnd); } - protected void addTextToHistory(@Nullable String text, @Nullable TextAttributes attributes) { - if (text == null || text.length() == 0) return; + protected void addTextToHistory(@Nullable CharSequence text, @Nullable TextAttributes attributes) { + if (StringUtil.isEmpty(text)) { + return; + } + Document history = myHistoryViewer.getDocument(); MarkupModel markupModel = DocumentMarkupModel.forDocument(history, myProject, true); int offset = history.getTextLength(); @@ -557,7 +557,7 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider { addTextToHistory(myPrompt, ConsoleViewContentType.USER_INPUT.getAttributes()); } - protected void appendToHistoryDocument(@NotNull Document history, @NotNull String text) { + protected void appendToHistoryDocument(@NotNull Document history, @NotNull CharSequence text) { ApplicationManager.getApplication().assertIsDispatchThread(); history.insertString(history.getTextLength(), text); } @@ -619,7 +619,6 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider { public void calcData(DataKey key, DataSink sink) { if (OpenFileDescriptor.NAVIGATE_IN_EDITOR == key) { sink.put(OpenFileDescriptor.NAVIGATE_IN_EDITOR, myConsoleEditor); - return; } else if (getProject().isInitialized()) { FileEditorManager editorManager = FileEditorManager.getInstance(getProject()); @@ -729,8 +728,23 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider { } } + public void printToHistoryOnEdt(@NotNull final CharSequence text, @NotNull final TextAttributes attributes) { + Application application = ApplicationManager.getApplication(); + if (application.isDispatchThread()) { + printToHistory(text, attributes); + } + else { + application.invokeLater(new Runnable() { + @Override + public void run() { + printToHistory(text, attributes); + } + }, ModalityState.stateForComponent(getComponent())); + } + } + public static void printToConsole(@NotNull final LanguageConsoleImpl console, - @NotNull final String string, + @NotNull final CharSequence string, @NotNull final ConsoleViewContentType mainType, @Nullable ConsoleViewContentType additionalType) { final TextAttributes mainAttributes = mainType.getAttributes(); @@ -743,18 +757,7 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider { attributes.setBackgroundColor(mainAttributes.getBackgroundColor()); } - Application application = ApplicationManager.getApplication(); - if (application.isDispatchThread()) { - console.printToHistory(string, attributes); - } - else { - application.invokeLater(new Runnable() { - @Override - public void run() { - console.printToHistory(string, attributes); - } - }, ModalityState.stateForComponent(console.getComponent())); - } + console.printToHistoryOnEdt(string, attributes); } private class MyLayout extends AbstractLayoutManager { diff --git a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleViewImpl.java b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleViewImpl.java index 530d8394f68a..89f6da48b9f7 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleViewImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleViewImpl.java @@ -20,6 +20,7 @@ import com.intellij.lang.Language; import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; +import com.intellij.psi.search.GlobalSearchScope; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -36,7 +37,12 @@ public class LanguageConsoleViewImpl extends ConsoleViewImpl implements Language } public LanguageConsoleViewImpl(@NotNull LanguageConsoleImpl console) { - super(console.getProject(), true); + this(console, true); + } + + public LanguageConsoleViewImpl(@NotNull LanguageConsoleImpl console, boolean usePredefinedMessageFilter) { + super(console.getProject(), GlobalSearchScope.allScope(console.getProject()), true, null, usePredefinedMessageFilter); + myConsole = console; Disposer.register(this, myConsole); } diff --git a/platform/util-rt/src/com/intellij/openapi/util/text/StringUtilRt.java b/platform/util-rt/src/com/intellij/openapi/util/text/StringUtilRt.java index 7130d22e1d38..1cffb307d76d 100644 --- a/platform/util-rt/src/com/intellij/openapi/util/text/StringUtilRt.java +++ b/platform/util-rt/src/com/intellij/openapi/util/text/StringUtilRt.java @@ -101,6 +101,19 @@ public class StringUtilRt { @NotNull String newSeparator, @Nullable int[] offsetsToKeep, boolean keepCarriageReturn) { + return unifyLineSeparators(text, newSeparator, offsetsToKeep, keepCarriageReturn).toString(); + } + + @NotNull + public static CharSequence unifyLineSeparators(@NotNull CharSequence text) { + return unifyLineSeparators(text, "\n", null, false); + } + + @NotNull + public static CharSequence unifyLineSeparators(@NotNull CharSequence text, + @NotNull String newSeparator, + @Nullable int[] offsetsToKeep, + boolean keepCarriageReturn) { StringBuilder buffer = null; int intactLength = 0; final boolean newSeparatorIsSlashN = "\n".equals(newSeparator); @@ -156,7 +169,7 @@ public class StringUtilRt { } } } - return buffer == null ? text : buffer.toString(); + return buffer == null ? text : buffer; } private static void shiftOffsets(int[] offsets, int changeOffset, int oldLength, int newLength) {