mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
continue WEB-1171 javascript live console — works now, but UI is ugly
This commit is contained in:
@@ -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<Pair<String, TextAttributes>> 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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user