From b4821406a578dfef039dac610343d04f1ff514b2 Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Thu, 19 Feb 2015 18:34:23 +0300 Subject: [PATCH] merge LanguageConsole & LanguageConsoleView: part 1 --- .../ex/util/LexerEditorHighlighter.java | 2 +- .../BaseConsoleExecuteActionHandler.java | 34 +- .../console/ConsoleExecuteAction.java | 72 ++-- .../execution/console/LanguageConsole.java | 13 +- .../console/LanguageConsoleBuilder.java | 19 +- .../console/LanguageConsoleImpl.java | 353 +++++------------- .../console/LanguageConsoleView.java | 4 +- .../console/LanguageConsoleViewImpl.java | 74 ---- ...cessBackedConsoleExecuteActionHandler.java | 7 +- .../execution/impl/ConsoleViewImpl.java | 56 +-- .../AbstractConsoleRunnerWithHistory.java | 13 +- .../execution/impl/ConsoleViewUtil.java | 12 +- .../groovy/console/GroovyConsoleAction.java | 3 +- .../groovy/console/GroovyShellActionBase.java | 8 +- .../python/console/PyConsoleOptions.java | 10 - .../console/PyConsoleOptionsConfigurable.form | 16 +- .../console/PyConsoleOptionsConfigurable.java | 4 - .../console/PyConsoleProcessHandler.java | 4 +- .../console/PyConsoleSourceHighlighter.java | 11 +- .../python/console/PyConsoleUtil.java | 4 +- .../PydevConsoleExecuteActionHandler.java | 11 +- .../python/console/PythonConsoleView.java | 23 +- .../PythonDebugLanguageConsoleView.java | 6 +- 23 files changed, 235 insertions(+), 524 deletions(-) delete mode 100644 platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleViewImpl.java diff --git a/platform/editor-ui-ex/src/com/intellij/openapi/editor/ex/util/LexerEditorHighlighter.java b/platform/editor-ui-ex/src/com/intellij/openapi/editor/ex/util/LexerEditorHighlighter.java index 20d71d48a816..e51f2f81c7ea 100644 --- a/platform/editor-ui-ex/src/com/intellij/openapi/editor/ex/util/LexerEditorHighlighter.java +++ b/platform/editor-ui-ex/src/com/intellij/openapi/editor/ex/util/LexerEditorHighlighter.java @@ -335,7 +335,7 @@ public class LexerEditorHighlighter implements EditorHighlighter, PrioritizedDoc return new TokenProcessor(); } - protected SyntaxHighlighter getSyntaxHighlighter() { + public SyntaxHighlighter getSyntaxHighlighter() { return myHighlighter; } diff --git a/platform/lang-impl/src/com/intellij/execution/console/BaseConsoleExecuteActionHandler.java b/platform/lang-impl/src/com/intellij/execution/console/BaseConsoleExecuteActionHandler.java index 7ed208258dbf..0e438a7098c2 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/BaseConsoleExecuteActionHandler.java +++ b/platform/lang-impl/src/com/intellij/execution/console/BaseConsoleExecuteActionHandler.java @@ -16,48 +16,18 @@ package com.intellij.execution.console; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public abstract class BaseConsoleExecuteActionHandler extends ConsoleExecuteAction.ConsoleExecuteActionHandler { public BaseConsoleExecuteActionHandler(boolean preserveMarkup) { super(preserveMarkup); } - public void runExecuteAction(@NotNull LanguageConsoleView consoleView) { - runExecuteAction(consoleView.getConsole(), consoleView); - } - @Override - final void doExecute(@NotNull String text, @NotNull LanguageConsole console, @Nullable LanguageConsoleView consoleView) { - if (consoleView == null) { - //noinspection deprecation - execute(text); - } - else { - execute(text, consoleView); - } + final void doExecute(@NotNull String text, @NotNull LanguageConsoleView consoleView) { + execute(text, consoleView); } protected void execute(@NotNull String text, @NotNull LanguageConsoleView console) { - //noinspection deprecation - execute(text); - } - - @SuppressWarnings("UnusedDeclaration") - @Deprecated - /** - * @deprecated to remove in IDEA 15 - */ - public void runExecuteAction(@NotNull LanguageConsoleImpl languageConsole) { - runExecuteAction(languageConsole, null); - } - - @Deprecated - /** - * @deprecated to remove in IDEA 15 - */ - protected void execute(@NotNull String text) { - throw new AbstractMethodError(); } public String getEmptyExecuteAction() { diff --git a/platform/lang-impl/src/com/intellij/execution/console/ConsoleExecuteAction.java b/platform/lang-impl/src/com/intellij/execution/console/ConsoleExecuteAction.java index bcb5f024a45f..96e420c98cd2 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/ConsoleExecuteAction.java +++ b/platform/lang-impl/src/com/intellij/execution/console/ConsoleExecuteAction.java @@ -25,7 +25,6 @@ import com.intellij.openapi.actionSystem.EmptyAction; import com.intellij.openapi.command.impl.UndoManagerImpl; import com.intellij.openapi.command.undo.DocumentReferenceManager; import com.intellij.openapi.command.undo.UndoManager; -import com.intellij.openapi.editor.ex.DocumentEx; import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.util.Condition; @@ -39,7 +38,6 @@ public class ConsoleExecuteAction extends DumbAwareAction { static final String CONSOLE_EXECUTE_ACTION_ID = "Console.Execute"; private final LanguageConsoleView myConsoleView; - private final LanguageConsole myConsole; final ConsoleExecuteActionHandler myExecuteActionHandler; private final Condition myEnabledCondition; @@ -48,46 +46,22 @@ public class ConsoleExecuteAction extends DumbAwareAction { this(console, executeActionHandler, CONSOLE_EXECUTE_ACTION_ID, Conditions.alwaysTrue()); } - /** - * Only internal usage, to keep backward compatibility - * to remove in IDEA 14 - */ - public static ConsoleExecuteAction createAction(@NotNull final LanguageConsole languageConsole, - @NotNull ProcessBackedConsoleExecuteActionHandler consoleExecuteActionHandler) { - final ConsoleExecuteActionHandler handler = consoleExecuteActionHandler; - return new ConsoleExecuteAction(languageConsole, new ConsoleExecuteActionHandler(handler.myPreserveMarkup) { - @Override - void doExecute(@NotNull String text, @NotNull LanguageConsole console, @Nullable LanguageConsoleView consoleView) { - handler.doExecute(text, languageConsole, null); - } - }, consoleExecuteActionHandler); - } - - ConsoleExecuteAction(@NotNull LanguageConsole console, final @NotNull ConsoleExecuteActionHandler executeActionHandler, @Nullable Condition enabledCondition) { - this(console, null, executeActionHandler, CONSOLE_EXECUTE_ACTION_ID, enabledCondition); + ConsoleExecuteAction(@NotNull LanguageConsoleView console, final @NotNull ConsoleExecuteActionHandler executeActionHandler, @Nullable Condition enabledCondition) { + this(console, executeActionHandler, CONSOLE_EXECUTE_ACTION_ID, enabledCondition); } public ConsoleExecuteAction(@NotNull LanguageConsoleView console, @NotNull BaseConsoleExecuteActionHandler executeActionHandler, @Nullable Condition enabledCondition) { - this(console.getConsole(), console, executeActionHandler, CONSOLE_EXECUTE_ACTION_ID, enabledCondition); + this(console, executeActionHandler, CONSOLE_EXECUTE_ACTION_ID, enabledCondition); } - public ConsoleExecuteAction(@NotNull LanguageConsoleView console, - @NotNull BaseConsoleExecuteActionHandler executeActionHandler, - @NotNull String emptyExecuteActionId, - @NotNull Condition enabledCondition) { - this(console.getConsole(), console, executeActionHandler, emptyExecuteActionId, enabledCondition); - } - - private ConsoleExecuteAction(@NotNull LanguageConsole console, - @Nullable LanguageConsoleView consoleView, + public ConsoleExecuteAction(@NotNull LanguageConsoleView consoleView, @NotNull ConsoleExecuteActionHandler executeActionHandler, @NotNull String emptyExecuteActionId, @Nullable Condition enabledCondition) { super(null, null, AllIcons.Actions.Execute); - myConsole = console; myConsoleView = consoleView; myExecuteActionHandler = executeActionHandler; myEnabledCondition = enabledCondition == null ? Conditions.alwaysTrue() : enabledCondition; @@ -97,7 +71,7 @@ public class ConsoleExecuteAction extends DumbAwareAction { @Override public final void update(@NotNull AnActionEvent e) { - EditorEx editor = myConsole.getConsoleEditor(); + EditorEx editor = myConsoleView.getConsole().getConsoleEditor(); boolean enabled = !editor.isRendererMode() && isEnabled() && (myExecuteActionHandler.isEmptyCommandExecutionAllowed() || !StringUtil.isEmptyOrSpaces(editor.getDocument().getCharsSequence())); if (enabled) { @@ -111,27 +85,26 @@ public class ConsoleExecuteAction extends DumbAwareAction { @Override public final void actionPerformed(@NotNull AnActionEvent e) { - myExecuteActionHandler.runExecuteAction(myConsole, myConsoleView); + myExecuteActionHandler.runExecuteAction(myConsoleView); } public boolean isEnabled() { - return myEnabledCondition.value(myConsole); + return myEnabledCondition.value(myConsoleView.getConsole()); } public void execute(@Nullable TextRange range, @NotNull String text, @Nullable EditorEx editor) { if (range == null) { - ((LanguageConsoleImpl)myConsole).doAddPromptToHistory(); - DocumentEx document = myConsole.getHistoryViewer().getDocument(); - document.insertString(document.getTextLength(), text); + ((LanguageConsoleImpl)myConsoleView.getConsole()).doAddPromptToHistory(); + myConsoleView.print(text, ConsoleViewContentType.USER_INPUT); if (!text.endsWith("\n")) { - document.insertString(document.getTextLength(), "\n"); + myConsoleView.print("\n", ConsoleViewContentType.USER_INPUT); } } else { assert editor != null; - ((LanguageConsoleImpl)myConsole).addTextRangeToHistory(range, editor, myExecuteActionHandler.myPreserveMarkup); + ((LanguageConsoleImpl)myConsoleView.getConsole()).addTextRangeToHistory(range, editor, myExecuteActionHandler.myPreserveMarkup); } - myExecuteActionHandler.addToCommandHistoryAndExecute(myConsole, myConsoleView, text); + myExecuteActionHandler.addToCommandHistoryAndExecute(myConsoleView, text); } public static abstract class ConsoleExecuteActionHandler { @@ -159,32 +132,33 @@ public class ConsoleExecuteAction extends DumbAwareAction { myAddToHistory = addCurrentToHistory; } - protected void beforeExecution(@NotNull LanguageConsole console) { + protected void beforeExecution(@NotNull LanguageConsoleView consoleView) { } - protected void runExecuteAction(@NotNull LanguageConsole console, @Nullable LanguageConsoleView consoleView) { + public void runExecuteAction(@NotNull LanguageConsoleView consoleView) { if (!myUseProcessStdIn) { - beforeExecution(console); + beforeExecution(consoleView); } - String text = ((LanguageConsoleImpl)console).prepareExecuteAction(myAddToHistory && !myUseProcessStdIn, myPreserveMarkup, true); - ((UndoManagerImpl)UndoManager.getInstance(console.getProject())).invalidateActionsFor(DocumentReferenceManager.getInstance().create(console.getCurrentEditor().getDocument())); + String text = ((LanguageConsoleImpl)consoleView.getConsole()).prepareExecuteAction(myAddToHistory && !myUseProcessStdIn, + myPreserveMarkup, true); + ((UndoManagerImpl)UndoManager.getInstance(consoleView.getProject())).invalidateActionsFor(DocumentReferenceManager.getInstance().create( + consoleView.getConsole().getCurrentEditor().getDocument())); if (myUseProcessStdIn) { - assert consoleView != null; consoleView.print(text, ConsoleViewContentType.USER_INPUT); consoleView.print("\n", ConsoleViewContentType.USER_INPUT); } else { - addToCommandHistoryAndExecute(console, consoleView, text); + addToCommandHistoryAndExecute(consoleView, text); } } - private void addToCommandHistoryAndExecute(@NotNull LanguageConsole console, @Nullable LanguageConsoleView consoleView, @NotNull String text) { + private void addToCommandHistoryAndExecute(@NotNull LanguageConsoleView consoleView, @NotNull String text) { myCommandHistoryModel.addToHistory(text); - doExecute(text, console, consoleView); + doExecute(text, consoleView); } - abstract void doExecute(@NotNull String text, @NotNull LanguageConsole console, @Nullable LanguageConsoleView consoleView); + abstract void doExecute(@NotNull String text, @NotNull LanguageConsoleView consoleView); } } \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsole.java b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsole.java index 0dc989484730..222c270a9da4 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsole.java +++ b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsole.java @@ -15,18 +15,20 @@ */ package com.intellij.execution.console; +import com.intellij.execution.ui.ConsoleViewContentType; import com.intellij.lang.Language; import com.intellij.openapi.Disposable; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.ex.EditorEx; -import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import javax.swing.*; + /** * @author gregsh */ @@ -34,11 +36,14 @@ public interface LanguageConsole extends Disposable { @NotNull Project getProject(); - boolean isValid(); + @NotNull + JComponent getComponent(); @NotNull String getTitle(); + void setTitle(String title); + @NotNull PsiFile getFile(); @@ -67,7 +72,9 @@ public interface LanguageConsole extends Disposable { void setPrompt(@Nullable String prompt); - void setPromptAttributes(@NotNull TextAttributes attributes); + void setPromptAttributes(@NotNull ConsoleViewContentType textAttributes); + + void setInputText(@NotNull String inputText); boolean isEditable(); 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 4418031be1f1..bf0057a5c62b 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleBuilder.java +++ b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleBuilder.java @@ -117,22 +117,22 @@ public final class LanguageConsoleBuilder { /** * todo This API doesn't look good, but it is much better than force client to know low-level details */ - public static Pair registerExecuteAction(@NotNull LanguageConsole console, + public static Pair registerExecuteAction(@NotNull LanguageConsoleView console, @NotNull final Consumer executeActionHandler, @NotNull String historyType, @Nullable String historyPersistenceId, @Nullable Condition enabledCondition) { ConsoleExecuteAction.ConsoleExecuteActionHandler handler = new ConsoleExecuteAction.ConsoleExecuteActionHandler(true) { @Override - void doExecute(@NotNull String text, @NotNull LanguageConsole console, @Nullable LanguageConsoleView consoleView) { + void doExecute(@NotNull String text, @NotNull LanguageConsoleView consoleView) { executeActionHandler.consume(text); } }; ConsoleExecuteAction action = new ConsoleExecuteAction(console, handler, enabledCondition); - action.registerCustomShortcutSet(action.getShortcutSet(), console.getConsoleEditor().getComponent()); + action.registerCustomShortcutSet(action.getShortcutSet(), console.getConsole().getConsoleEditor().getComponent()); - ConsoleHistoryController historyController = new ConsoleHistoryController(historyType, historyPersistenceId, console, handler.getConsoleHistoryModel()); + ConsoleHistoryController historyController = new ConsoleHistoryController(historyType, historyPersistenceId, console.getConsole(), handler.getConsoleHistoryModel()); historyController.install(); return new Pair(action, historyController); } @@ -167,11 +167,10 @@ public final class LanguageConsoleBuilder { @NotNull public LanguageConsoleView build(@NotNull Project project, @NotNull Language language) { - GutteredLanguageConsole console = new GutteredLanguageConsole(language.getDisplayName() + " Console", project, language, gutterContentProvider, psiFileFactory); + GutteredLanguageConsole consoleView = new GutteredLanguageConsole(language.getDisplayName() + " Console", project, language, gutterContentProvider, psiFileFactory); if (oneLineInput) { - console.getConsoleEditor().setOneLineMode(true); + consoleView.getConsoleEditor().setOneLineMode(true); } - LanguageConsoleViewImpl consoleView = new LanguageConsoleViewImpl(console, true); if (executeActionHandler != null) { assert historyType != null; doInitAction(consoleView, executeActionHandler, historyType); @@ -187,7 +186,7 @@ public final class LanguageConsoleBuilder { consoleView.addCustomConsoleAction(new UseConsoleInputAction(processInputStateKey)); } - console.initComponents(); + consoleView.initComponents(); return consoleView; } @@ -201,9 +200,7 @@ public final class LanguageConsoleBuilder { @NotNull Language language, @Nullable GutterContentProvider gutterContentProvider, @Nullable PairFunction psiFileFactory) { - super(project, title, new LightVirtualFile(title, language, ""), false, psiFileFactory); - - setShowSeparatorLine(false); + super(project, title, new LightVirtualFile(title, language, ""), psiFileFactory); this.gutterContentProvider = gutterContentProvider == null ? new BasicGutterContentProvider() : gutterContentProvider; this.psiFileFactory = psiFileFactory; 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 69bcccdc3f3b..6972d4d08712 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java @@ -15,51 +15,46 @@ */ package com.intellij.execution.console; -import com.intellij.codeInsight.daemon.impl.HighlightInfo; +import com.intellij.execution.impl.ConsoleViewImpl; import com.intellij.execution.impl.ConsoleViewUtil; import com.intellij.execution.ui.ConsoleViewContentType; import com.intellij.ide.DataManager; import com.intellij.ide.highlighter.HighlighterFactory; import com.intellij.injected.editor.EditorWindow; import com.intellij.lang.Language; -import com.intellij.lang.annotation.HighlightSeverity; -import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.DataProvider; import com.intellij.openapi.actionSystem.EmptyAction; import com.intellij.openapi.actionSystem.IdeActions; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.*; import com.intellij.openapi.editor.actions.EditorActionUtil; -import com.intellij.openapi.editor.colors.EditorColors; import com.intellij.openapi.editor.colors.EditorColorsManager; -import com.intellij.openapi.editor.event.*; +import com.intellij.openapi.editor.event.VisibleAreaEvent; +import com.intellij.openapi.editor.event.VisibleAreaListener; import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.editor.ex.FocusChangeListener; -import com.intellij.openapi.editor.ex.RangeHighlighterEx; import com.intellij.openapi.editor.ex.util.EditorUtil; +import com.intellij.openapi.editor.ex.util.LexerEditorHighlighter; import com.intellij.openapi.editor.highlighter.EditorHighlighter; import com.intellij.openapi.editor.highlighter.EditorHighlighterFactory; -import com.intellij.openapi.editor.highlighter.HighlighterIterator; -import com.intellij.openapi.editor.impl.DocumentMarkupModel; import com.intellij.openapi.editor.impl.EditorFactoryImpl; -import com.intellij.openapi.editor.markup.*; import com.intellij.openapi.fileEditor.*; import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx; import com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl; -import com.intellij.openapi.fileTypes.FileTypes; +import com.intellij.openapi.fileTypes.SyntaxHighlighter; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.TextRange; -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; import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; +import com.intellij.psi.search.GlobalSearchScope; import com.intellij.testFramework.LightVirtualFile; -import com.intellij.ui.JBColor; -import com.intellij.ui.SideBorder; -import com.intellij.util.*; +import com.intellij.util.DocumentUtil; +import com.intellij.util.FileContentUtil; +import com.intellij.util.ObjectUtils; +import com.intellij.util.PairFunction; import com.intellij.util.ui.AbstractLayoutManager; import com.intellij.util.ui.JBUI; import com.intellij.util.ui.UIUtil; @@ -80,8 +75,7 @@ import java.util.concurrent.atomic.AtomicBoolean; * @author Gregory.Shrago * In case of REPL consider to use {@link LanguageConsoleBuilder} */ -public class LanguageConsoleImpl implements LanguageConsole, DataProvider { - private static final int SEPARATOR_THICKNESS = 1; +public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageConsole, LanguageConsoleView, DataProvider { private final Project myProject; private final EditorEx myConsoleEditor; @@ -95,16 +89,11 @@ public class LanguageConsoleImpl implements LanguageConsole, DataProvider { private String myTitle; @Nullable private String myPrompt = "> "; - private TextAttributes myPromptAttributes = ConsoleViewContentType.USER_INPUT.getAttributes(); + private ConsoleViewContentType myPromptAttributes = ConsoleViewContentType.USER_INPUT; - private final LightVirtualFile myHistoryFile; private Editor myCurrentEditor; private final AtomicBoolean myForceScrollToEnd = new AtomicBoolean(false); - private final SingleAlarm myUpdateQueue; - private Runnable myUiUpdateRunnable; - - private boolean myShowSeparatorLine = true; private final FocusChangeListener myFocusListener = new FocusChangeListener() { @Override @@ -118,27 +107,22 @@ public class LanguageConsoleImpl implements LanguageConsole, DataProvider { }; public LanguageConsoleImpl(@NotNull Project project, @NotNull String title, @NotNull Language language) { - this(project, title, language, true); + this(project, title, new LightVirtualFile(title, language, "")); } - public LanguageConsoleImpl(@NotNull Project project, @NotNull String title, @NotNull Language language, boolean initComponents) { - this(project, title, new LightVirtualFile(title, language, ""), initComponents); - } - - public LanguageConsoleImpl(@NotNull Project project, @NotNull String title, @NotNull VirtualFile virtualFile, boolean initComponents) { - this(project, title, virtualFile, initComponents, null); + public LanguageConsoleImpl(@NotNull Project project, @NotNull String title, @NotNull VirtualFile virtualFile) { + this(project, title, virtualFile, null); } LanguageConsoleImpl(@NotNull Project project, @NotNull String title, @NotNull VirtualFile lightFile, - boolean initComponents, @Nullable PairFunction psiFileFactory) { + super(project, GlobalSearchScope.allScope(project), true, true); myProject = project; myTitle = title; myVirtualFile = lightFile; EditorFactory editorFactory = EditorFactory.getInstance(); - myHistoryFile = new LightVirtualFile(getTitle() + ".history.txt", FileTypes.PLAIN_TEXT, ""); myEditorDocument = FileDocumentManager.getInstance().getDocument(lightFile); if (myEditorDocument == null) { throw new AssertionError("no document for: " + lightFile); @@ -148,18 +132,6 @@ public class LanguageConsoleImpl implements LanguageConsole, DataProvider { myConsoleEditor.addFocusListener(myFocusListener); myCurrentEditor = myConsoleEditor; myHistoryViewer = (EditorEx)editorFactory.createViewer(((EditorFactoryImpl)editorFactory).createDocument(true), myProject); - myUpdateQueue = new SingleAlarm(new Runnable() { - @Override - public void run() { - if (isConsoleEditorEnabled()) { - myPanel.revalidate(); - myPanel.repaint(); - } - if (myUiUpdateRunnable != null) { - myUiUpdateRunnable.run(); - } - } - }, 300, this); // action shortcuts are not yet registered ApplicationManager.getApplication().invokeLater(new Runnable() { @@ -168,10 +140,26 @@ public class LanguageConsoleImpl implements LanguageConsole, DataProvider { installEditorFactoryListener(); } }, myProject.getDisposed()); + } - if (initComponents) { - initComponents(); - } + @Override + protected EditorEx doCreateConsoleEditor() { + return myHistoryViewer; + } + + @Override + protected void disposeEditor() { + } + + @Override + protected JComponent createCenterComponent() { + initComponents(); + return myPanel; + } + + @Override + public JComponent getPreferredFocusableComponent() { + return getConsoleEditor().getContentComponent(); } public void initComponents() { @@ -186,7 +174,7 @@ public class LanguageConsoleImpl implements LanguageConsole, DataProvider { @Override public void componentResized(ComponentEvent e) { if (myForceScrollToEnd.compareAndSet(true, false)) { - scrollHistoryToEnd(); + scrollToEnd(); } } @@ -219,18 +207,10 @@ public class LanguageConsoleImpl implements LanguageConsole, DataProvider { } } - public void setShowSeparatorLine(boolean showSeparatorLine) { - myShowSeparatorLine = showSeparatorLine; - } - private void setupComponents() { setupEditorDefault(myConsoleEditor); setupEditorDefault(myHistoryViewer); - //noinspection ConstantConditions - if (SEPARATOR_THICKNESS > 0 && myShowSeparatorLine) { - myHistoryViewer.getComponent().setBorder(new SideBorder(JBColor.LIGHT_GRAY, SideBorder.BOTTOM)); - } myHistoryViewer.getComponent().setMinimumSize(JBUI.emptySize()); myHistoryViewer.getComponent().setPreferredSize(JBUI.emptySize()); myHistoryViewer.setCaretEnabled(false); @@ -256,15 +236,6 @@ public class LanguageConsoleImpl implements LanguageConsole, DataProvider { } } }); - final DocumentAdapter docListener = new DocumentAdapter() { - @Override - public void documentChanged(final DocumentEvent e) { - queueUiUpdate(false); - } - }; - myEditorDocument.addDocumentListener(docListener, this); - myHistoryViewer.getDocument().addDocumentListener(docListener, this); - myHistoryViewer.getContentComponent().addKeyListener(new KeyAdapter() { @Override public void keyTyped(KeyEvent event) { @@ -275,10 +246,6 @@ public class LanguageConsoleImpl implements LanguageConsole, DataProvider { } }); - //noinspection deprecation - for (AnAction action : createActions()) { - action.registerCustomShortcutSet(action.getShortcutSet(), myConsoleEditor.getComponent()); - } EmptyAction.registerActionShortcuts(myHistoryViewer.getComponent(), myConsoleEditor.getComponent()); } @@ -286,25 +253,6 @@ public class LanguageConsoleImpl implements LanguageConsole, DataProvider { return myPanel.getComponentCount() > 1; } - @NotNull - @Deprecated - /** - * @deprecated LanguageConsoleImpl is not intended to be extended - */ - protected AnAction[] createActions() { - return AnAction.EMPTY_ARRAY; - } - - @SuppressWarnings("UnusedDeclaration") - @Deprecated - /** - * @deprecated Use {@link #setInputText} - * to remove in IDEA 15 - */ - public void setTextToEditor(@NotNull String text) { - setInputText(text); - } - protected void setupEditorDefault(@NotNull EditorEx editor) { ConsoleViewUtil.setupConsoleEditor(editor, false, false); editor.getContentComponent().setFocusCycleRoot(false); @@ -319,28 +267,12 @@ public class LanguageConsoleImpl implements LanguageConsole, DataProvider { editorSettings.setAdditionalColumnsCount(1); } - public void setUiUpdateRunnable(Runnable uiUpdateRunnable) { - assert myUiUpdateRunnable == null : "can be set only once"; - myUiUpdateRunnable = uiUpdateRunnable; - } - - public void flushAllUiUpdates() { - myUpdateQueue.flush(); - } - - @SuppressWarnings("UnusedDeclaration") - @NotNull - @Deprecated - public LightVirtualFile getHistoryFile() { - return myHistoryFile; - } - @Nullable public String getPrompt() { return myPrompt; } - public void setPromptAttributes(@NotNull TextAttributes textAttributes) { + public void setPromptAttributes(@NotNull ConsoleViewContentType textAttributes) { myPromptAttributes = textAttributes; } @@ -351,15 +283,10 @@ public class LanguageConsoleImpl implements LanguageConsole, DataProvider { } private void setPromptInner(@Nullable final String prompt) { - myUpdateQueue.checkDisposed(); - UIUtil.invokeAndWaitIfNeeded(new Runnable() { @Override public void run() { - myConsoleEditor.setPrefixTextAndAttributes(prompt, myPromptAttributes); - if (myPanel.isVisible()) { - queueUiUpdate(false); - } + myConsoleEditor.setPrefixTextAndAttributes(prompt, myPromptAttributes.getAttributes()); } }); } @@ -403,6 +330,12 @@ public class LanguageConsoleImpl implements LanguageConsole, DataProvider { return myProject; } + @NotNull + @Override + public LanguageConsole getConsole() { + return this; + } + @NotNull public String getTitle() { return myTitle; @@ -412,48 +345,13 @@ public class LanguageConsoleImpl implements LanguageConsole, DataProvider { myTitle = title; } - public void printToHistory(@NotNull CharSequence text, @NotNull TextAttributes attributes) { - ApplicationManager.getApplication().assertIsDispatchThread(); - text = StringUtilRt.unifyLineSeparators(text); - final boolean scrollToEnd = shouldScrollHistoryToEnd(); - addTextToHistory(text, attributes); - if (scrollToEnd) { - scrollHistoryToEnd(); - } - queueUiUpdate(scrollToEnd); - } - - protected void addTextToHistory(@Nullable CharSequence text, @Nullable TextAttributes attributes) { - if (StringUtil.isEmpty(text) || attributes == null) { - return; - } - - Document history = myHistoryViewer.getDocument(); - int offset = appendToHistoryDocument(history, text); - DocumentMarkupModel.forDocument(history, myProject, true).addRangeHighlighter(offset, offset + text.length(), HighlighterLayer.SYNTAX, attributes, - HighlighterTargetArea.EXACT_RANGE); - } - - @SuppressWarnings("UnusedDeclaration") - @Deprecated - /** - * @deprecated Use {@link LanguageConsoleBuilder}, - * {@link LanguageConsoleBuilder#registerExecuteAction)} or - * {@link ConsoleExecuteAction#prepareRunExecuteAction)} - * - * to remove in IDEA 15 - */ - public String addCurrentToHistory(@NotNull TextRange textRange, boolean erase, boolean preserveMarkup) { - return addToHistoryInner(textRange, myConsoleEditor, erase, preserveMarkup); - } - public String addToHistory(@NotNull TextRange textRange, @NotNull EditorEx editor, boolean preserveMarkup) { return addToHistoryInner(textRange, editor, false, preserveMarkup); } @NotNull public String prepareExecuteAction(boolean addToHistory, boolean preserveMarkup, boolean clearInput) { - Editor editor = getCurrentEditor(); + EditorEx editor = (EditorEx)getCurrentEditor(); Document document = editor.getDocument(); String text = document.getText(); TextRange range = new TextRange(0, document.getTextLength()); @@ -462,7 +360,7 @@ public class LanguageConsoleImpl implements LanguageConsole, DataProvider { } if (addToHistory) { - addToHistoryInner(range, myConsoleEditor, clearInput, preserveMarkup); + addToHistoryInner(range, editor, clearInput, preserveMarkup); } else if (clearInput) { setInputText(""); @@ -484,8 +382,7 @@ public class LanguageConsoleImpl implements LanguageConsole, DataProvider { }); } // always scroll to end on user input - scrollHistoryToEnd(); - queueUiUpdate(true); + scrollToEnd(); return result; } @@ -495,117 +392,86 @@ public class LanguageConsoleImpl implements LanguageConsole, DataProvider { return contentSize.getHeight() - visibleArea.getMaxY() < (getMinHistoryLineCount() * myHistoryViewer.getLineHeight()); } - private void scrollHistoryToEnd() { - if (myHistoryViewer.getDocument().getTextLength() != 0) { - EditorUtil.scrollToTheEnd(myHistoryViewer); - } - } - - @NotNull - protected String addTextRangeToHistory(@NotNull TextRange textRange, @NotNull EditorEx inputEditor, boolean preserveMarkup) { - doAddPromptToHistory(); - - final Document history = myHistoryViewer.getDocument(); - final MarkupModel markupModel = DocumentMarkupModel.forDocument(history, myProject, true); - final int localStartOffset = textRange.getStartOffset(); + public static String printWithHighlighting(@NotNull LanguageConsoleView console, @NotNull Editor inputEditor, @NotNull TextRange textRange) { String text; EditorHighlighter highlighter; if (inputEditor instanceof EditorWindow) { PsiFile file = ((EditorWindow)inputEditor).getInjectedFile(); - highlighter = HighlighterFactory.createHighlighter(file.getVirtualFile(), EditorColorsManager.getInstance().getGlobalScheme(), getProject()); + highlighter = + HighlighterFactory.createHighlighter(file.getVirtualFile(), EditorColorsManager.getInstance().getGlobalScheme(), console.getProject()); String fullText = InjectedLanguageUtil.getUnescapedText(file, null, null); highlighter.setText(fullText); text = textRange.substring(fullText); } else { text = inputEditor.getDocument().getText(textRange); - highlighter = inputEditor.getHighlighter(); + highlighter = ((EditorEx)inputEditor).getHighlighter(); } - //offset can be changed after text trimming after insert due to buffer constraints - int offset = appendToHistoryDocument(history, text); - - final HighlighterIterator iterator = highlighter.createIterator(localStartOffset); - final int localEndOffset = textRange.getEndOffset(); - while (!iterator.atEnd()) { - final int itStart = iterator.getStart(); - if (itStart > localEndOffset) { - break; - } - final int itEnd = iterator.getEnd(); - if (itEnd >= localStartOffset) { - final int start = Math.max(itStart, localStartOffset) - localStartOffset + offset; - final int end = Math.min(itEnd, localEndOffset) - localStartOffset + offset; - markupModel.addRangeHighlighter(start, end, HighlighterLayer.SYNTAX, iterator.getTextAttributes(), - HighlighterTargetArea.EXACT_RANGE); - } - iterator.advance(); + SyntaxHighlighter syntax = + highlighter instanceof LexerEditorHighlighter ? ((LexerEditorHighlighter)highlighter).getSyntaxHighlighter() : null; + ((LanguageConsoleImpl)console).doAddPromptToHistory(); + if (syntax != null) { + ConsoleViewUtil.printWithHighlighting(console, text, syntax); } - if (preserveMarkup) { - duplicateHighlighters(markupModel, DocumentMarkupModel.forDocument(inputEditor.getDocument(), myProject, true), offset, textRange); - // don't copy editor markup model, i.e. brace matcher, spell checker, etc. - // duplicateHighlighters(markupModel, inputEditor.getMarkupModel(), offset, textRange); - } - if (!text.endsWith("\n")) { - appendToHistoryDocument(history, "\n"); + else { + console.print(text, ConsoleViewContentType.USER_INPUT); } + console.print("\n", ConsoleViewContentType.NORMAL_OUTPUT); return text; } - protected void doAddPromptToHistory() { - addTextToHistory(myPrompt, myPromptAttributes); - } - - // returns the real (cyclic-buffer-aware) start offset of the inserted text - protected int appendToHistoryDocument(@NotNull Document history, @NotNull CharSequence text) { - ApplicationManager.getApplication().assertIsDispatchThread(); - history.insertString(history.getTextLength(), text); - return history.getTextLength() - text.length(); - } - - private static void duplicateHighlighters(@NotNull MarkupModel to, @NotNull MarkupModel from, int offset, @NotNull TextRange textRange) { - for (RangeHighlighter rangeHighlighter : from.getAllHighlighters()) { - if (!rangeHighlighter.isValid()) { - continue; - } - Object tooltip = rangeHighlighter.getErrorStripeTooltip(); - HighlightInfo highlightInfo = tooltip instanceof HighlightInfo? (HighlightInfo)tooltip : null; - if (highlightInfo != null) { - if (highlightInfo.getSeverity() != HighlightSeverity.INFORMATION) { - continue; - } - if (highlightInfo.type.getAttributesKey() == EditorColors.IDENTIFIER_UNDER_CARET_ATTRIBUTES) { - continue; - } - } - final int localOffset = textRange.getStartOffset(); - final int start = Math.max(rangeHighlighter.getStartOffset(), localOffset) - localOffset; - final int end = Math.min(rangeHighlighter.getEndOffset(), textRange.getEndOffset()) - localOffset; - if (start > end) { - continue; - } - final RangeHighlighter h = to.addRangeHighlighter(start + offset, end + offset, rangeHighlighter.getLayer(), rangeHighlighter.getTextAttributes(), rangeHighlighter.getTargetArea()); - ((RangeHighlighterEx)h).setAfterEndOfLine(((RangeHighlighterEx)rangeHighlighter).isAfterEndOfLine()); - } - } - @NotNull - public JComponent getComponent() { - return myPanel; + protected String addTextRangeToHistory(@NotNull TextRange textRange, @NotNull EditorEx inputEditor, boolean preserveMarkup) { + return printWithHighlighting(this, inputEditor, textRange); + + + //if (preserveMarkup) { + // duplicateHighlighters(markupModel, DocumentMarkupModel.forDocument(inputEditor.getDocument(), myProject, true), offset, textRange); + // // don't copy editor markup model, i.e. brace matcher, spell checker, etc. + // // duplicateHighlighters(markupModel, inputEditor.getMarkupModel(), offset, textRange); + //} } - public void queueUiUpdate(boolean forceScrollToEnd) { - myForceScrollToEnd.compareAndSet(false, forceScrollToEnd); - if (myUpdateQueue.isDisposed()) { - return; + protected void doAddPromptToHistory() { + if (myPrompt != null) { + print(myPrompt, myPromptAttributes); } - myUpdateQueue.request(); } + + //private static void duplicateHighlighters(@NotNull MarkupModel to, @NotNull MarkupModel from, int offset, @NotNull TextRange textRange) { + // for (RangeHighlighter rangeHighlighter : from.getAllHighlighters()) { + // if (!rangeHighlighter.isValid()) { + // continue; + // } + // Object tooltip = rangeHighlighter.getErrorStripeTooltip(); + // HighlightInfo highlightInfo = tooltip instanceof HighlightInfo? (HighlightInfo)tooltip : null; + // if (highlightInfo != null) { + // if (highlightInfo.getSeverity() != HighlightSeverity.INFORMATION) { + // continue; + // } + // if (highlightInfo.type.getAttributesKey() == EditorColors.IDENTIFIER_UNDER_CARET_ATTRIBUTES) { + // continue; + // } + // } + // int localOffset = textRange.getStartOffset(); + // int start = Math.max(rangeHighlighter.getStartOffset(), localOffset) - localOffset; + // int end = Math.min(rangeHighlighter.getEndOffset(), textRange.getEndOffset()) - localOffset; + // if (start > end) { + // continue; + // } + // RangeHighlighter h = to.addRangeHighlighter(start + offset, end + offset, rangeHighlighter.getLayer(), + // rangeHighlighter.getTextAttributes(), rangeHighlighter.getTargetArea()); + // ((RangeHighlighterEx)h).setAfterEndOfLine(((RangeHighlighterEx)rangeHighlighter).isAfterEndOfLine()); + // } + //} + @Override public void dispose() { + super.dispose(); EditorFactory editorFactory = EditorFactory.getInstance(); editorFactory.releaseEditor(myConsoleEditor); - editorFactory.releaseEditor(myHistoryViewer); + //editorFactory.releaseEditor(myHistoryViewer); if (getProject().isOpen()) { FileEditorManager editorManager = FileEditorManager.getInstance(getProject()); @@ -648,14 +514,7 @@ public class LanguageConsoleImpl implements LanguageConsole, DataProvider { myCurrentEditor = editor; } EmptyAction.registerActionShortcuts(editor.getComponent(), myConsoleEditor.getComponent()); - editor.getCaretModel().addCaretListener(new CaretAdapter() { - @Override - public void caretPositionChanged(CaretEvent e) { - queueUiUpdate(false); - } - }); } - queueUiUpdate(false); } @Override @@ -663,12 +522,10 @@ public class LanguageConsoleImpl implements LanguageConsole, DataProvider { if (!Comparing.equal(file, myVirtualFile)) { return; } - if (myUiUpdateRunnable != null && !Boolean.TRUE.equals(file.getUserData(FileEditorManagerImpl.CLOSING_TO_REOPEN))) { + if (!Boolean.TRUE.equals(file.getUserData(FileEditorManagerImpl.CLOSING_TO_REOPEN))) { if (myCurrentEditor != null && myCurrentEditor.isDisposed()) { myCurrentEditor = null; } - if (!isValid()) return; - ApplicationManager.getApplication().runReadAction(myUiUpdateRunnable); } } }; @@ -689,10 +546,6 @@ public class LanguageConsoleImpl implements LanguageConsole, DataProvider { return myFile.getLanguage(); } - public boolean isValid() { - return myVirtualFile.isValid() && myProject.isOpen(); - } - public void setLanguage(@NotNull Language language) { if (!(myVirtualFile instanceof LightVirtualFile)) { throw new UnsupportedOperationException(); @@ -767,7 +620,7 @@ public class LanguageConsoleImpl implements LanguageConsole, DataProvider { historySize.height = 0; } - int minHistoryHeight = historySize.height > 0 ? (getMinHistoryLineCount() * history.getLineHeight() + (myShowSeparatorLine ? SEPARATOR_THICKNESS : 0)) : 0; + int minHistoryHeight = historySize.height > 0 ? getMinHistoryLineCount() * history.getLineHeight() : 0; int minInputHeight = input.isViewer() ? 0 : input.getLineHeight(); final int inputPreferredHeight = input.isViewer() ? 0 : Math.max(minInputHeight, inputSize.height); final int historyPreferredHeight = Math.max(minHistoryHeight, historySize.height); diff --git a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleView.java b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleView.java index cd07953068bb..008acab59486 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleView.java +++ b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleView.java @@ -24,8 +24,8 @@ import org.jetbrains.annotations.NotNull; */ public interface LanguageConsoleView extends ConsoleView { @NotNull - LanguageConsole getConsole(); + Project getProject(); @NotNull - Project getProject(); + LanguageConsole getConsole(); } diff --git a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleViewImpl.java b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleViewImpl.java deleted file mode 100644 index 8a4b1f85125a..000000000000 --- a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleViewImpl.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2000-2010 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.execution.console; - -import com.intellij.execution.impl.ConsoleViewImpl; -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.*; - -/** - * @author Gregory.Shrago - */ -public class LanguageConsoleViewImpl extends ConsoleViewImpl implements LanguageConsoleView { - @NotNull - protected final LanguageConsoleImpl myConsole; - - public LanguageConsoleViewImpl(Project project, String title, Language language) { - this(new LanguageConsoleImpl(project, title, language)); - } - - public LanguageConsoleViewImpl(@NotNull LanguageConsoleImpl console) { - this(console, true); - } - - public LanguageConsoleViewImpl(@NotNull LanguageConsoleImpl console, boolean usePredefinedMessageFilter) { - super(console.getProject(), GlobalSearchScope.allScope(console.getProject()), true, usePredefinedMessageFilter); - - myConsole = console; - Disposer.register(this, myConsole); - } - - @Override - @NotNull - public LanguageConsoleImpl getConsole() { - return myConsole; - } - - @Override - protected EditorEx createRealEditor() { - return myConsole.getHistoryViewer(); - } - - @Override - protected void disposeEditor() { - } - - @Override - protected JComponent createCenterComponent() { - return myConsole.getComponent(); - } - - @Override - public JComponent getPreferredFocusableComponent() { - return myConsole.getConsoleEditor().getContentComponent(); - } -} diff --git a/platform/lang-impl/src/com/intellij/execution/console/ProcessBackedConsoleExecuteActionHandler.java b/platform/lang-impl/src/com/intellij/execution/console/ProcessBackedConsoleExecuteActionHandler.java index 49e7f2fb4f42..8a7ac55e05f9 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/ProcessBackedConsoleExecuteActionHandler.java +++ b/platform/lang-impl/src/com/intellij/execution/console/ProcessBackedConsoleExecuteActionHandler.java @@ -40,13 +40,8 @@ public class ProcessBackedConsoleExecuteActionHandler extends BaseConsoleExecute myProcessHandler = processHandler; } - @SuppressWarnings("deprecation") @Override - @Deprecated - /** - * @deprecated to remove in IDEA 15 - */ - protected void execute(@NotNull String text) { + protected void execute(@NotNull String text, @NotNull LanguageConsoleView console) { processLine(text); } diff --git a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java index 76e5c4e0b5d4..abaaadc0e4fb 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java @@ -149,7 +149,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo public void scrollToEnd() { if (myEditor == null) return; - myEditor.getCaretModel().moveToOffset(myEditor.getDocument().getTextLength()); + EditorUtil.scrollToTheEnd(myEditor); } public void foldImmediately() { @@ -469,34 +469,38 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo } if (myEditor == null) { - myEditor = createEditor(); - registerConsoleEditorActions(); - myEditor.getScrollPane().setBorder(null); - myHyperlinks = new EditorHyperlinkSupport(myEditor, myProject); + initConsoleEditor(); requestFlushImmediately(); myMainPanel.add(createCenterComponent(), BorderLayout.CENTER); - myEditor.getScrollingModel().addVisibleAreaListener(new VisibleAreaListener() { - @Override - public void visibleAreaChanged(VisibleAreaEvent e) { - // There is a possible case that the console text is populated while the console is not shown (e.g. we're debugging and - // 'Debugger' tab is active while 'Console' is not). It's also possible that newly added text contains long lines that - // are soft wrapped. We want to update viewport position then when the console becomes visible. - final Rectangle oldRectangle = e.getOldRectangle(); - if (oldRectangle == null) { - return; - } - - Editor myEditor = e.getEditor(); - if (oldRectangle.height <= 0 && e.getNewRectangle().height > 0 && myEditor.getSoftWrapModel().isSoftWrappingEnabled() - && myEditor.getCaretModel().getOffset() == myEditor.getDocument().getTextLength()) { - EditorUtil.scrollToTheEnd(myEditor); - } - } - }); } return this; } + protected void initConsoleEditor() { + myEditor = createConsoleEditor(); + registerConsoleEditorActions(); + myEditor.getScrollPane().setBorder(null); + myHyperlinks = new EditorHyperlinkSupport(myEditor, myProject); + myEditor.getScrollingModel().addVisibleAreaListener(new VisibleAreaListener() { + @Override + public void visibleAreaChanged(VisibleAreaEvent e) { + // There is a possible case that the console text is populated while the console is not shown (e.g. we're debugging and + // 'Debugger' tab is active while 'Console' is not). It's also possible that newly added text contains long lines that + // are soft wrapped. We want to update viewport position then when the console becomes visible. + final Rectangle oldRectangle = e.getOldRectangle(); + if (oldRectangle == null) { + return; + } + + Editor myEditor = e.getEditor(); + if (oldRectangle.height <= 0 && e.getNewRectangle().height > 0 && myEditor.getSoftWrapModel().isSoftWrappingEnabled() + && myEditor.getCaretModel().getOffset() == myEditor.getDocument().getTextLength()) { + EditorUtil.scrollToTheEnd(myEditor); + } + } + }); + } + protected JComponent createCenterComponent() { return myEditor.getComponent(); } @@ -847,11 +851,11 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo printHyperlink(hyperlinkText, ConsoleViewContentType.NORMAL_OUTPUT, info); } - private EditorEx createEditor() { + private EditorEx createConsoleEditor() { return ApplicationManager.getApplication().runReadAction(new Computable() { @Override public EditorEx compute() { - EditorEx editor = createRealEditor(); + EditorEx editor = doCreateConsoleEditor(); editor.addEditorMouseListener(new EditorPopupHandler() { @Override public void invokePopup(final EditorMouseEvent event) { @@ -907,7 +911,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo } } - protected EditorEx createRealEditor() { + protected EditorEx doCreateConsoleEditor() { return ConsoleViewUtil.setupConsoleEditor(myProject, true, false); } diff --git a/platform/lang-impl/src/com/intellij/execution/runners/AbstractConsoleRunnerWithHistory.java b/platform/lang-impl/src/com/intellij/execution/runners/AbstractConsoleRunnerWithHistory.java index 7ac83c90a965..973529c47d0d 100644 --- a/platform/lang-impl/src/com/intellij/execution/runners/AbstractConsoleRunnerWithHistory.java +++ b/platform/lang-impl/src/com/intellij/execution/runners/AbstractConsoleRunnerWithHistory.java @@ -22,7 +22,10 @@ import com.intellij.execution.ExecutionException; import com.intellij.execution.ExecutionHelper; import com.intellij.execution.ExecutionManager; import com.intellij.execution.Executor; -import com.intellij.execution.console.*; +import com.intellij.execution.console.ConsoleExecuteAction; +import com.intellij.execution.console.LanguageConsole; +import com.intellij.execution.console.LanguageConsoleView; +import com.intellij.execution.console.ProcessBackedConsoleExecuteActionHandler; import com.intellij.execution.executors.DefaultRunExecutor; import com.intellij.execution.process.*; import com.intellij.execution.ui.RunContentDescriptor; @@ -85,8 +88,8 @@ public abstract class AbstractConsoleRunnerWithHistory { private final GroovyShellRunner myShellRunner; @@ -210,7 +212,7 @@ public abstract class GroovyShellActionBase extends AnAction { @Override protected LanguageConsoleView createConsoleView() { - LanguageConsoleViewImpl res = new LanguageConsoleViewImpl(createConsole(getProject(), getConsoleTitle())); + LanguageConsoleView res = createConsole(getProject(), getConsoleTitle()); GroovyFileImpl file = (GroovyFileImpl)res.getConsole().getFile(); assert file.getContext() == null; file.putUserData(GROOVY_SHELL_FILE, Boolean.TRUE); diff --git a/python/src/com/jetbrains/python/console/PyConsoleOptions.java b/python/src/com/jetbrains/python/console/PyConsoleOptions.java index 01166f301c2d..1bf857347dc0 100644 --- a/python/src/com/jetbrains/python/console/PyConsoleOptions.java +++ b/python/src/com/jetbrains/python/console/PyConsoleOptions.java @@ -52,14 +52,6 @@ public class PyConsoleOptions implements PersistentStateComponent - + @@ -26,7 +26,7 @@ - + @@ -34,25 +34,17 @@ - + - + - - - - - - - - diff --git a/python/src/com/jetbrains/python/console/PyConsoleOptionsConfigurable.java b/python/src/com/jetbrains/python/console/PyConsoleOptionsConfigurable.java index ec544f930acd..0d6a281a81fe 100644 --- a/python/src/com/jetbrains/python/console/PyConsoleOptionsConfigurable.java +++ b/python/src/com/jetbrains/python/console/PyConsoleOptionsConfigurable.java @@ -172,7 +172,6 @@ public class PyConsoleOptionsConfigurable extends SearchableConfigurable.Parent. private static class PyConsoleOptionsPanel { private JPanel myWholePanel; private JBCheckBox myShowDebugConsoleByDefault; - private JBCheckBox myShowSeparatorLine; private JBCheckBox myIpythonEnabledCheckbox; private PyConsoleOptions myOptionsProvider; @@ -184,19 +183,16 @@ public class PyConsoleOptionsConfigurable extends SearchableConfigurable.Parent. public void apply() { myOptionsProvider.setShowDebugConsoleByDefault(myShowDebugConsoleByDefault.isSelected()); - myOptionsProvider.setShowSeparatorLine(myShowSeparatorLine.isSelected()); myOptionsProvider.setIpythonEnabled(myIpythonEnabledCheckbox.isSelected()); } public void reset() { myShowDebugConsoleByDefault.setSelected(myOptionsProvider.isShowDebugConsoleByDefault()); - myShowSeparatorLine.setSelected(myOptionsProvider.isShowSeparatorLine()); myIpythonEnabledCheckbox.setSelected(myOptionsProvider.isIpythonEnabled()); } public boolean isModified() { return myShowDebugConsoleByDefault.isSelected() != myOptionsProvider.isShowDebugConsoleByDefault() || - myShowSeparatorLine.isSelected() != myOptionsProvider.isShowSeparatorLine() || myIpythonEnabledCheckbox.isSelected() != myOptionsProvider.isIpythonEnabled(); } diff --git a/python/src/com/jetbrains/python/console/PyConsoleProcessHandler.java b/python/src/com/jetbrains/python/console/PyConsoleProcessHandler.java index f5ddd1a99354..fc8e5b0e4bc3 100644 --- a/python/src/com/jetbrains/python/console/PyConsoleProcessHandler.java +++ b/python/src/com/jetbrains/python/console/PyConsoleProcessHandler.java @@ -15,7 +15,7 @@ */ package com.jetbrains.python.console; -import com.intellij.execution.console.LanguageConsoleImpl; +import com.intellij.execution.console.LanguageConsole; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.ui.UIUtil; @@ -84,7 +84,7 @@ public class PyConsoleProcessHandler extends PythonProcessHandler { } } - private LanguageConsoleImpl getConsole() { + private LanguageConsole getConsole() { return myConsoleView.getConsole(); } } diff --git a/python/src/com/jetbrains/python/console/PyConsoleSourceHighlighter.java b/python/src/com/jetbrains/python/console/PyConsoleSourceHighlighter.java index fd6688a90da2..7964f7f916b0 100644 --- a/python/src/com/jetbrains/python/console/PyConsoleSourceHighlighter.java +++ b/python/src/com/jetbrains/python/console/PyConsoleSourceHighlighter.java @@ -15,6 +15,7 @@ */ package com.jetbrains.python.console; +import com.intellij.execution.impl.ConsoleViewUtil; import com.intellij.execution.ui.ConsoleViewContentType; import com.intellij.lexer.Lexer; import com.intellij.openapi.editor.HighlighterColors; @@ -22,6 +23,7 @@ import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.util.Pair; +import com.intellij.psi.tree.IElementType; import com.jetbrains.python.highlighting.PyHighlighter; /** @@ -57,11 +59,10 @@ class PyConsoleSourceHighlighter { private Pair next() { myLexerState = myLexer.getState(); - - Pair res = Pair.create(myLexer.getTokenText(), - new ConsoleViewContentType("", convertAttributes( - myPyHighlighter.getTokenHighlights( - myLexer.getTokenType())))); + IElementType tokenType = myLexer.getTokenType(); + Pair res = Pair.create( + myLexer.getTokenText(), + tokenType == null ? ConsoleViewContentType.NORMAL_OUTPUT : ConsoleViewUtil.getContentTypeForToken(tokenType, myPyHighlighter)); myLexer.advance(); return res; diff --git a/python/src/com/jetbrains/python/console/PyConsoleUtil.java b/python/src/com/jetbrains/python/console/PyConsoleUtil.java index c630feb0bf06..4fa29d4d482c 100644 --- a/python/src/com/jetbrains/python/console/PyConsoleUtil.java +++ b/python/src/com/jetbrains/python/console/PyConsoleUtil.java @@ -15,7 +15,7 @@ */ package com.jetbrains.python.console; -import com.intellij.execution.console.LanguageConsoleImpl; +import com.intellij.execution.console.LanguageConsole; import com.intellij.execution.ui.ConsoleViewContentType; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Editor; @@ -56,7 +56,7 @@ public class PyConsoleUtil { return prompt != null && IPYTHON_PAGING_PROMPT.equals(prompt.trim()); } - static String processPrompts(final LanguageConsoleImpl languageConsole, String string) { + static String processPrompts(final LanguageConsole languageConsole, String string) { // Change prompt for (String prompt : PROMPTS) { if (string.startsWith(prompt)) { diff --git a/python/src/com/jetbrains/python/console/PydevConsoleExecuteActionHandler.java b/python/src/com/jetbrains/python/console/PydevConsoleExecuteActionHandler.java index eafc36f8436a..43948609dff7 100644 --- a/python/src/com/jetbrains/python/console/PydevConsoleExecuteActionHandler.java +++ b/python/src/com/jetbrains/python/console/PydevConsoleExecuteActionHandler.java @@ -286,9 +286,14 @@ public class PydevConsoleExecuteActionHandler extends ProcessBackedConsoleExecut } private void ipythonInPrompt(LanguageConsole console, Editor currentEditor){ - TextAttributes attributes = ConsoleViewContentType.USER_INPUT.getAttributes(); - attributes.setFontType(Font.PLAIN); - console.setPromptAttributes(attributes); + console.setPromptAttributes(new ConsoleViewContentType("", ConsoleViewContentType.USER_INPUT_KEY) { + @Override + public TextAttributes getAttributes() { + TextAttributes attrs = super.getAttributes(); + attrs.setFontType(Font.PLAIN); + return attrs; + } + }); console.setPrompt("In[" + myIpythonInputPromptCount + "]:"); PyConsoleUtil.scrollDown(currentEditor); } diff --git a/python/src/com/jetbrains/python/console/PythonConsoleView.java b/python/src/com/jetbrains/python/console/PythonConsoleView.java index 151ecc8c27f1..dd072430d4a8 100644 --- a/python/src/com/jetbrains/python/console/PythonConsoleView.java +++ b/python/src/com/jetbrains/python/console/PythonConsoleView.java @@ -16,9 +16,9 @@ package com.jetbrains.python.console; import com.intellij.codeInsight.hint.HintManager; +import com.intellij.execution.console.LanguageConsole; import com.intellij.execution.console.LanguageConsoleImpl; import com.intellij.execution.console.LanguageConsoleView; -import com.intellij.execution.console.LanguageConsoleViewImpl; import com.intellij.execution.filters.Filter; import com.intellij.execution.filters.HyperlinkInfo; import com.intellij.execution.filters.OpenFileHyperlinkInfo; @@ -81,23 +81,18 @@ public class PythonConsoleView extends JPanel implements LanguageConsoleView, Ob private final EditorColorsScheme myScheme; private boolean myHyperlink; - private final LanguageConsoleViewImpl myLanguageConsoleView; + private final LanguageConsoleImpl myLanguageConsoleView; private Disposable mySplitDisposable; public PythonConsoleView(final Project project, final String title, final Sdk sdk) { super(new BorderLayout()); - LanguageConsoleImpl languageConsole = new LanguageConsoleImpl(project, title, PythonLanguage.getInstance(), false); - if (languageConsole.getFile().getVirtualFile() != null) { - languageConsole.getFile().getVirtualFile().putUserData(LanguageLevel.KEY, PythonSdkType.getLanguageLevelForSdk(sdk)); - } + myLanguageConsoleView = new LanguageConsoleImpl(project, title, PythonLanguage.getInstance()); + myLanguageConsoleView.getVirtualFile().putUserData(LanguageLevel.KEY, PythonSdkType.getLanguageLevelForSdk(sdk)); // Mark editor as console one, to prevent autopopup completion - languageConsole.getConsoleEditor().putUserData(PythonConsoleAutopopupBlockingHandler.REPL_KEY, new Object()); - languageConsole.setShowSeparatorLine(PyConsoleOptions.getInstance(project).isShowSeparatorLine()); - languageConsole.initComponents(); + myLanguageConsoleView.getConsoleEditor().putUserData(PythonConsoleAutopopupBlockingHandler.REPL_KEY, new Object()); - myLanguageConsoleView = new LanguageConsoleViewImpl(languageConsole); Disposer.register(this, myLanguageConsoleView); add(myLanguageConsoleView.getComponent(), BorderLayout.CENTER); @@ -139,15 +134,13 @@ public class PythonConsoleView extends JPanel implements LanguageConsoleView, Ob @Override public void requestFocus() { IdeFocusManager.findInstance().requestFocus(getPythonLanguageConsole().getConsoleEditor().getContentComponent(), true); - myLanguageConsoleView.updateUI(); - getLanguageConsole().getHistoryViewer().getComponent().updateUI(); } - private LanguageConsoleImpl getPythonLanguageConsole() { + private LanguageConsole getPythonLanguageConsole() { return getLanguageConsole(); } - public LanguageConsoleImpl getLanguageConsole() { + public LanguageConsole getLanguageConsole() { return myLanguageConsoleView.getConsole(); } @@ -416,7 +409,7 @@ public class PythonConsoleView extends JPanel implements LanguageConsoleView, Ob @NotNull @Override - public LanguageConsoleImpl getConsole() { + public LanguageConsole getConsole() { return myLanguageConsoleView.getConsole(); } diff --git a/python/src/com/jetbrains/python/console/PythonDebugLanguageConsoleView.java b/python/src/com/jetbrains/python/console/PythonDebugLanguageConsoleView.java index 46dd1fa3452d..943c60319569 100644 --- a/python/src/com/jetbrains/python/console/PythonDebugLanguageConsoleView.java +++ b/python/src/com/jetbrains/python/console/PythonDebugLanguageConsoleView.java @@ -16,7 +16,7 @@ package com.jetbrains.python.console; import com.intellij.execution.console.DuplexConsoleView; -import com.intellij.execution.console.LanguageConsoleImpl; +import com.intellij.execution.console.LanguageConsole; import com.intellij.execution.filters.TextConsoleBuilderFactory; import com.intellij.execution.impl.ConsoleViewImpl; import com.intellij.execution.ui.ConsoleView; @@ -71,11 +71,9 @@ public class PythonDebugLanguageConsoleView extends DuplexConsoleView