merge LanguageConsole & LanguageConsoleView: part 1

This commit is contained in:
Gregory.Shrago
2015-02-19 23:02:43 +03:00
parent b4bbf2e0de
commit b4821406a5
23 changed files with 235 additions and 524 deletions
@@ -335,7 +335,7 @@ public class LexerEditorHighlighter implements EditorHighlighter, PrioritizedDoc
return new TokenProcessor();
}
protected SyntaxHighlighter getSyntaxHighlighter() {
public SyntaxHighlighter getSyntaxHighlighter() {
return myHighlighter;
}
@@ -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() {
@@ -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<LanguageConsole> myEnabledCondition;
@@ -48,46 +46,22 @@ public class ConsoleExecuteAction extends DumbAwareAction {
this(console, executeActionHandler, CONSOLE_EXECUTE_ACTION_ID, Conditions.<LanguageConsole>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<LanguageConsole> enabledCondition) {
this(console, null, executeActionHandler, CONSOLE_EXECUTE_ACTION_ID, enabledCondition);
ConsoleExecuteAction(@NotNull LanguageConsoleView console, final @NotNull ConsoleExecuteActionHandler executeActionHandler, @Nullable Condition<LanguageConsole> enabledCondition) {
this(console, executeActionHandler, CONSOLE_EXECUTE_ACTION_ID, enabledCondition);
}
public ConsoleExecuteAction(@NotNull LanguageConsoleView console,
@NotNull BaseConsoleExecuteActionHandler executeActionHandler,
@Nullable Condition<LanguageConsole> 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<LanguageConsole> 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<LanguageConsole> enabledCondition) {
super(null, null, AllIcons.Actions.Execute);
myConsole = console;
myConsoleView = consoleView;
myExecuteActionHandler = executeActionHandler;
myEnabledCondition = enabledCondition == null ? Conditions.<LanguageConsole>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);
}
}
@@ -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();
@@ -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<AnAction, ConsoleHistoryController> registerExecuteAction(@NotNull LanguageConsole console,
public static Pair<AnAction, ConsoleHistoryController> registerExecuteAction(@NotNull LanguageConsoleView console,
@NotNull final Consumer<String> executeActionHandler,
@NotNull String historyType,
@Nullable String historyPersistenceId,
@Nullable Condition<LanguageConsole> 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<AnAction, ConsoleHistoryController>(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<VirtualFile, Project, PsiFile> 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;
@@ -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<VirtualFile, Project, PsiFile> 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);
@@ -24,8 +24,8 @@ import org.jetbrains.annotations.NotNull;
*/
public interface LanguageConsoleView extends ConsoleView {
@NotNull
LanguageConsole getConsole();
Project getProject();
@NotNull
Project getProject();
LanguageConsole getConsole();
}
@@ -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();
}
}
@@ -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);
}
@@ -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<EditorEx>() {
@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);
}
@@ -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<T extends LanguageConsole
private void initConsoleUI(Process process) {
// Init console view
myConsoleView = createConsoleView();
if (myConsoleView instanceof LanguageConsoleViewImpl) {
((LanguageConsoleViewImpl)myConsoleView).setBorder(new SideBorder(UIUtil.getBorderColor(), SideBorder.LEFT));
if (myConsoleView instanceof JComponent) {
((JComponent)myConsoleView).setBorder(new SideBorder(UIUtil.getBorderColor(), SideBorder.LEFT));
}
myProcessHandler = createProcessHandler(process);
@@ -233,8 +236,8 @@ public abstract class AbstractConsoleRunnerWithHistory<T extends LanguageConsole
return ActionManager.getInstance().getAction(IdeActions.ACTION_STOP_PROGRAM);
}
public LanguageConsoleImpl getLanguageConsole() {
return (LanguageConsoleImpl)myConsoleView.getConsole();
public LanguageConsole getLanguageConsole() {
return myConsoleView.getConsole();
}
@SuppressWarnings("UnusedDeclaration")
@@ -195,14 +195,18 @@ public class ConsoleViewUtil {
IElementType tokenType;
while ((tokenType = lexer.getTokenType()) != null) {
TextAttributesKey[] keys = highlighter.getTokenHighlights(tokenType);
ConsoleViewContentType type = keys.length == 0 ? ConsoleViewContentType.NORMAL_OUTPUT :
ConsoleViewContentType.getConsoleViewType(ColorCache.keys.get(Arrays.asList(keys)));
console.print(lexer.getTokenText(), type);
console.print(lexer.getTokenText(), getContentTypeForToken(tokenType, highlighter));
lexer.advance();
}
}
@NotNull
public static ConsoleViewContentType getContentTypeForToken(@NotNull IElementType tokenType, @NotNull SyntaxHighlighter highlighter) {
TextAttributesKey[] keys = highlighter.getTokenHighlights(tokenType);
return keys.length == 0 ? ConsoleViewContentType.NORMAL_OUTPUT :
ConsoleViewContentType.getConsoleViewType(ColorCache.keys.get(Arrays.asList(keys)));
}
public static void printAsFileType(@NotNull ConsoleView console, @NotNull String text, @NotNull FileType fileType) {
SyntaxHighlighter highlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(fileType, null, null);
if (highlighter != null) {
@@ -16,6 +16,7 @@
package org.jetbrains.plugins.groovy.console;
import com.intellij.execution.console.LanguageConsoleImpl;
import com.intellij.execution.console.LanguageConsoleView;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
@@ -40,7 +41,7 @@ public class GroovyConsoleAction extends GroovyShellActionBase implements DumbAw
}
@Override
protected LanguageConsoleImpl createConsole(Project project, String title) {
protected LanguageConsoleView createConsole(Project project, String title) {
return new LanguageConsoleImpl(project, title, GroovyLanguage.INSTANCE) {
@NotNull
@Override
@@ -18,7 +18,9 @@ package org.jetbrains.plugins.groovy.console;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.Executor;
import com.intellij.execution.configurations.JavaParameters;
import com.intellij.execution.console.*;
import com.intellij.execution.console.ConsoleHistoryController;
import com.intellij.execution.console.LanguageConsoleView;
import com.intellij.execution.console.ProcessBackedConsoleExecuteActionHandler;
import com.intellij.execution.process.OSProcessHandler;
import com.intellij.execution.runners.AbstractConsoleRunnerWithHistory;
import com.intellij.execution.ui.RunContentDescriptor;
@@ -182,7 +184,7 @@ public abstract class GroovyShellActionBase extends AnAction {
public abstract String getTitle();
protected abstract LanguageConsoleImpl createConsole(Project project, String title);
protected abstract LanguageConsoleView createConsole(Project project, String title);
private class GroovyConsoleRunner extends AbstractConsoleRunnerWithHistory<LanguageConsoleView> {
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);
@@ -52,14 +52,6 @@ public class PyConsoleOptions implements PersistentStateComponent<PyConsoleOptio
myState.myShowDebugConsoleByDefault = showDebugConsoleByDefault;
}
public boolean isShowSeparatorLine() {
return myState.myShowSeparatorLine;
}
public void setShowSeparatorLine(boolean showSeparatorLine) {
myState.myShowSeparatorLine = showSeparatorLine;
}
public boolean isIpythonEnabled(){
return myState.myIpythonEnabled;
}
@@ -80,7 +72,6 @@ public class PyConsoleOptions implements PersistentStateComponent<PyConsoleOptio
@Override
public void loadState(State state) {
myState.myShowDebugConsoleByDefault = state.myShowDebugConsoleByDefault;
myState.myShowSeparatorLine = state.myShowSeparatorLine;
myState.myPythonConsoleState = state.myPythonConsoleState;
myState.myIpythonEnabled = state.myIpythonEnabled;
}
@@ -89,7 +80,6 @@ public class PyConsoleOptions implements PersistentStateComponent<PyConsoleOptio
public PyConsoleSettings myPythonConsoleState = new PyConsoleSettings();
public boolean myShowDebugConsoleByDefault = false;
public boolean myShowSeparatorLine = true;
public boolean myIpythonEnabled = true;
}
@@ -13,7 +13,7 @@
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<grid id="b4377" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="b4377" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -26,7 +26,7 @@
<children>
<component id="d33dd" class="com.intellij.ui.components.JBCheckBox" binding="myShowDebugConsoleByDefault" default-binding="true">
<constraints>
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Always show debug console"/>
@@ -34,25 +34,17 @@
</component>
<vspacer id="c732">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="cccd6" class="com.intellij.ui.components.JBCheckBox" binding="myIpythonEnabledCheckbox">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Use IPython if available"/>
</properties>
</component>
<component id="cc309" class="com.intellij.ui.components.JBCheckBox" binding="myShowSeparatorLine">
<constraints>
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Show separator line"/>
</properties>
</component>
</children>
</grid>
<hspacer id="4135">
@@ -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();
}
@@ -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();
}
}
@@ -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<String, ConsoleViewContentType> next() {
myLexerState = myLexer.getState();
Pair<String, ConsoleViewContentType> res = Pair.create(myLexer.getTokenText(),
new ConsoleViewContentType("", convertAttributes(
myPyHighlighter.getTokenHighlights(
myLexer.getTokenType()))));
IElementType tokenType = myLexer.getTokenType();
Pair<String, ConsoleViewContentType> res = Pair.create(
myLexer.getTokenText(),
tokenType == null ? ConsoleViewContentType.NORMAL_OUTPUT : ConsoleViewUtil.getContentTypeForToken(tokenType, myPyHighlighter));
myLexer.advance();
return res;
@@ -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)) {
@@ -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);
}
@@ -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();
}
@@ -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<ConsoleVie
if (!primary && !isPrimaryConsoleEnabled()) {
PythonConsoleView pydevConsoleView = getPydevConsoleView();
LanguageConsoleImpl languageConsole = pydevConsoleView.getConsole();
LanguageConsole languageConsole = pydevConsoleView.getConsole();
IdeFocusManager.findInstance().requestFocus(languageConsole.getConsoleEditor().getContentComponent(), true);
pydevConsoleView.updateUI();
languageConsole.getHistoryViewer().getComponent().updateUI();
}
}
}