Search in sources :

Example 1 with ConsoleExecuteAction

use of com.intellij.execution.console.ConsoleExecuteAction in project intellij-community by JetBrains.

the class XEvaluateInConsoleFromEditorActionHandler method perform.

@Override
protected void perform(@NotNull XDebugSession session, DataContext dataContext) {
    Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
    if (editor == null || !(editor instanceof EditorEx)) {
        return;
    }
    int selectionStart = editor.getSelectionModel().getSelectionStart();
    int selectionEnd = editor.getSelectionModel().getSelectionEnd();
    Promise<Pair<TextRange, String>> rangeAndText = null;
    if (selectionStart != selectionEnd) {
        TextRange textRange = new TextRange(selectionStart, selectionEnd);
        rangeAndText = Promise.resolve(Pair.create(textRange, editor.getDocument().getText(textRange)));
    } else {
        XDebuggerEvaluator evaluator = session.getDebugProcess().getEvaluator();
        if (evaluator != null) {
            Promise<ExpressionInfo> expressionInfoPromise = evaluator.getExpressionInfoAtOffsetAsync(session.getProject(), editor.getDocument(), selectionStart, true);
            rangeAndText = expressionInfoPromise.then(expressionInfo -> {
                if (expressionInfo == null) {
                    return null;
                }
                return Pair.create(expressionInfo.getTextRange(), XDebuggerEvaluateActionHandler.getExpressionText(expressionInfo, editor.getDocument()));
            });
        } else {
            return;
        }
    }
    rangeAndText.done(textRangeStringPair -> {
        ApplicationManager.getApplication().invokeLater(() -> {
            TextRange range = textRangeStringPair.getFirst();
            String text = textRangeStringPair.getSecond();
            if (text == null)
                return;
            ConsoleExecuteAction action = getConsoleExecuteAction(session);
            if (action != null) {
                action.execute(range, text, (EditorEx) editor);
            }
        });
    });
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) ActionUtil(com.intellij.openapi.actionSystem.ex.ActionUtil) AnAction(com.intellij.openapi.actionSystem.AnAction) TextRange(com.intellij.openapi.util.TextRange) ContainerUtil(com.intellij.util.containers.ContainerUtil) Editor(com.intellij.openapi.editor.Editor) ExpressionInfo(com.intellij.xdebugger.evaluation.ExpressionInfo) Nullable(org.jetbrains.annotations.Nullable) Promise(org.jetbrains.concurrency.Promise) List(java.util.List) ConsoleView(com.intellij.execution.ui.ConsoleView) Pair(com.intellij.openapi.util.Pair) ApplicationManager(com.intellij.openapi.application.ApplicationManager) EditorEx(com.intellij.openapi.editor.ex.EditorEx) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) ConsoleExecuteAction(com.intellij.execution.console.ConsoleExecuteAction) LanguageConsoleView(com.intellij.execution.console.LanguageConsoleView) NotNull(org.jetbrains.annotations.NotNull) XDebugSession(com.intellij.xdebugger.XDebugSession) XDebuggerEvaluator(com.intellij.xdebugger.evaluation.XDebuggerEvaluator) EditorEx(com.intellij.openapi.editor.ex.EditorEx) XDebuggerEvaluator(com.intellij.xdebugger.evaluation.XDebuggerEvaluator) TextRange(com.intellij.openapi.util.TextRange) Editor(com.intellij.openapi.editor.Editor) ExpressionInfo(com.intellij.xdebugger.evaluation.ExpressionInfo) ConsoleExecuteAction(com.intellij.execution.console.ConsoleExecuteAction) Pair(com.intellij.openapi.util.Pair)

Example 2 with ConsoleExecuteAction

use of com.intellij.execution.console.ConsoleExecuteAction in project intellij-community by JetBrains.

the class XEvaluateInConsoleFromEditorActionHandler method getConsoleExecuteAction.

@Nullable
public static ConsoleExecuteAction getConsoleExecuteAction(@Nullable ConsoleView consoleView) {
    if (!(consoleView instanceof LanguageConsoleView)) {
        return null;
    }
    List<AnAction> actions = ActionUtil.getActions(((LanguageConsoleView) consoleView).getConsoleEditor().getComponent());
    ConsoleExecuteAction action = ContainerUtil.findInstance(actions, ConsoleExecuteAction.class);
    return action == null || !action.isEnabled() ? null : action;
}
Also used : LanguageConsoleView(com.intellij.execution.console.LanguageConsoleView) AnAction(com.intellij.openapi.actionSystem.AnAction) ConsoleExecuteAction(com.intellij.execution.console.ConsoleExecuteAction) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with ConsoleExecuteAction

use of com.intellij.execution.console.ConsoleExecuteAction in project intellij-community by JetBrains.

the class PydevConsoleRunnerImpl method fillToolBarActions.

private List<AnAction> fillToolBarActions(final DefaultActionGroup toolbarActions, final RunContentDescriptor contentDescriptor) {
    //toolbarActions.add(backspaceHandlingAction);
    toolbarActions.add(createRerunAction());
    List<AnAction> actions = ContainerUtil.newArrayList();
    //stop
    actions.add(createStopAction());
    //close
    actions.add(createCloseAction(contentDescriptor));
    // run action
    actions.add(new ConsoleExecuteAction(myConsoleView, myConsoleExecuteActionHandler, myConsoleExecuteActionHandler.getEmptyExecuteAction(), myConsoleExecuteActionHandler));
    // Help
    actions.add(CommonActionsManager.getInstance().createHelpAction("interactive_console"));
    toolbarActions.addAll(actions);
    actions.add(0, createRerunAction());
    actions.add(createInterruptAction());
    actions.add(PyConsoleUtil.createTabCompletionAction(myConsoleView));
    actions.add(createSplitLineAction());
    toolbarActions.add(new ShowVarsAction(myConsoleView, myPydevConsoleCommunication));
    toolbarActions.add(ConsoleHistoryController.getController(myConsoleView).getBrowseHistory());
    toolbarActions.add(new ConnectDebuggerAction());
    toolbarActions.add(new NewConsoleAction());
    return actions;
}
Also used : ShowVarsAction(com.jetbrains.python.console.actions.ShowVarsAction) ConsoleExecuteAction(com.intellij.execution.console.ConsoleExecuteAction)

Aggregations

ConsoleExecuteAction (com.intellij.execution.console.ConsoleExecuteAction)3 LanguageConsoleView (com.intellij.execution.console.LanguageConsoleView)2 AnAction (com.intellij.openapi.actionSystem.AnAction)2 Nullable (org.jetbrains.annotations.Nullable)2 ConsoleView (com.intellij.execution.ui.ConsoleView)1 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 ActionUtil (com.intellij.openapi.actionSystem.ex.ActionUtil)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 Editor (com.intellij.openapi.editor.Editor)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1 Pair (com.intellij.openapi.util.Pair)1 TextRange (com.intellij.openapi.util.TextRange)1 ContainerUtil (com.intellij.util.containers.ContainerUtil)1 XDebugSession (com.intellij.xdebugger.XDebugSession)1 ExpressionInfo (com.intellij.xdebugger.evaluation.ExpressionInfo)1 XDebuggerEvaluator (com.intellij.xdebugger.evaluation.XDebuggerEvaluator)1 ShowVarsAction (com.jetbrains.python.console.actions.ShowVarsAction)1 List (java.util.List)1 NotNull (org.jetbrains.annotations.NotNull)1