mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
continue LanguageConsoleBuilder.registerExecuteAction — don't force client to know low-level details, cleanup NewSshConsole
This commit is contained in:
@@ -41,12 +41,13 @@ public class ConsoleExecuteAction extends DumbAwareAction {
|
||||
private final ConsoleExecuteActionHandler myExecuteActionHandler;
|
||||
private final Condition<LanguageConsoleImpl> myEnabledCondition;
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public ConsoleExecuteAction(@NotNull LanguageConsoleView console, @NotNull BaseConsoleExecuteActionHandler executeActionHandler) {
|
||||
this(console, executeActionHandler, CONSOLE_EXECUTE_ACTION_ID, Conditions.<LanguageConsoleImpl>alwaysTrue());
|
||||
}
|
||||
|
||||
ConsoleExecuteAction(@NotNull LanguageConsoleImpl console, final @NotNull ConsoleExecuteActionHandler executeActionHandler) {
|
||||
this(console, null, executeActionHandler, CONSOLE_EXECUTE_ACTION_ID, null);
|
||||
ConsoleExecuteAction(@NotNull LanguageConsoleImpl console, final @NotNull ConsoleExecuteActionHandler executeActionHandler, @Nullable Condition<LanguageConsoleImpl> enabledCondition) {
|
||||
this(console, null, executeActionHandler, CONSOLE_EXECUTE_ACTION_ID, enabledCondition);
|
||||
}
|
||||
|
||||
public ConsoleExecuteAction(@NotNull LanguageConsoleView console,
|
||||
@@ -114,20 +115,9 @@ public class ConsoleExecuteAction extends DumbAwareAction {
|
||||
}
|
||||
|
||||
final void runExecuteAction(@NotNull LanguageConsoleImpl console, @Nullable LanguageConsoleView consoleView) {
|
||||
// process input and add to history
|
||||
Document document = console.getCurrentEditor().getDocument();
|
||||
String text = document.getText();
|
||||
TextRange range = new TextRange(0, document.getTextLength());
|
||||
String text = prepareRunExecuteAction(console, myPreserveMarkup, myAddCurrentToHistory, true);
|
||||
|
||||
console.getCurrentEditor().getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset());
|
||||
|
||||
if (myAddCurrentToHistory) {
|
||||
console.addCurrentToHistory(range, false, myPreserveMarkup);
|
||||
}
|
||||
|
||||
console.setInputText("");
|
||||
|
||||
((UndoManagerImpl)UndoManager.getInstance(console.getProject())).invalidateActionsFor(DocumentReferenceManager.getInstance().create(document));
|
||||
((UndoManagerImpl)UndoManager.getInstance(console.getProject())).invalidateActionsFor(DocumentReferenceManager.getInstance().create(console.getCurrentEditor().getDocument()));
|
||||
|
||||
myConsoleHistoryModel.addToHistory(text);
|
||||
doExecute(text, console, consoleView);
|
||||
@@ -135,4 +125,22 @@ public class ConsoleExecuteAction extends DumbAwareAction {
|
||||
|
||||
abstract void doExecute(@NotNull String text, @NotNull LanguageConsoleImpl console, @Nullable LanguageConsoleView consoleView);
|
||||
}
|
||||
|
||||
public static String prepareRunExecuteAction(@NotNull LanguageConsoleImpl console, boolean preserveMarkup, boolean addCurrentToHistory, boolean clear) {
|
||||
// process input and add to history
|
||||
Document document = console.getCurrentEditor().getDocument();
|
||||
String text = document.getText();
|
||||
TextRange range = new TextRange(0, document.getTextLength());
|
||||
|
||||
console.getCurrentEditor().getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset());
|
||||
|
||||
if (addCurrentToHistory) {
|
||||
console.addCurrentToHistory(range, false, preserveMarkup);
|
||||
}
|
||||
|
||||
if (clear) {
|
||||
console.setInputText("");
|
||||
}
|
||||
return text;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.intellij.execution.console;
|
||||
|
||||
import com.intellij.execution.process.ProcessHandler;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.colors.EditorColors;
|
||||
import com.intellij.openapi.editor.event.DocumentAdapter;
|
||||
@@ -13,6 +14,7 @@ import com.intellij.openapi.editor.impl.EditorImpl;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Conditions;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.Consumer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -58,7 +60,11 @@ public class LanguageConsoleBuilder {
|
||||
/**
|
||||
* todo This API doesn't look good, but it is much better than force client to know low-level details
|
||||
*/
|
||||
public static void registerExecuteAction(@NotNull LanguageConsoleImpl console, @NotNull final Consumer<String> executeActionHandler, @NotNull String historyType) {
|
||||
public static Pair<AnAction, ConsoleHistoryController> registerExecuteAction(@NotNull LanguageConsoleImpl console,
|
||||
@NotNull final Consumer<String> executeActionHandler,
|
||||
@NotNull String historyType,
|
||||
@Nullable String historyPersistenceId,
|
||||
@Nullable Condition<LanguageConsoleImpl> enabledCondition) {
|
||||
ConsoleExecuteAction.ConsoleExecuteActionHandler handler = new ConsoleExecuteAction.ConsoleExecuteActionHandler(true) {
|
||||
@Override
|
||||
void doExecute(@NotNull String text, @NotNull LanguageConsoleImpl console, @Nullable LanguageConsoleView consoleView) {
|
||||
@@ -66,10 +72,12 @@ public class LanguageConsoleBuilder {
|
||||
}
|
||||
};
|
||||
|
||||
ConsoleExecuteAction action = new ConsoleExecuteAction(console, handler);
|
||||
ConsoleExecuteAction action = new ConsoleExecuteAction(console, handler, enabledCondition);
|
||||
action.registerCustomShortcutSet(action.getShortcutSet(), console.getConsoleEditor().getComponent());
|
||||
|
||||
new ConsoleHistoryController(historyType, null, console, handler.getConsoleHistoryModel()).install();
|
||||
ConsoleHistoryController historyController = new ConsoleHistoryController(historyType, historyPersistenceId, console, handler.getConsoleHistoryModel());
|
||||
historyController.install();
|
||||
return new Pair<AnAction, ConsoleHistoryController>(action, historyController);
|
||||
}
|
||||
|
||||
public LanguageConsoleBuilder historyAnnotation(@Nullable GutterContentProvider provider) {
|
||||
|
||||
Reference in New Issue
Block a user