CR-IC-4638 EvaluateInConsoleFromTreeAction

This commit is contained in:
Vladimir Krivosheev
2014-03-05 14:12:07 +01:00
parent aa9d7298c1
commit 3181d9a5e2
8 changed files with 73 additions and 17 deletions
@@ -24,6 +24,7 @@ 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;
@@ -115,8 +116,19 @@ public class ConsoleExecuteAction extends DumbAwareAction {
return myEnabledCondition.value(myConsole);
}
public void execute(@NotNull TextRange range, @NotNull String text, @NotNull EditorEx editor) {
myConsole.addTextRangeToHistory(range, editor, myExecuteActionHandler.myPreserveMarkup);
public void execute(@Nullable TextRange range, @NotNull String text, @Nullable EditorEx editor) {
if (range == null) {
myConsole.doAddPromptToHistory();
DocumentEx document = myConsole.getHistoryViewer().getDocument();
document.insertString(document.getTextLength(), text);
if (!text.endsWith("\n")) {
document.insertString(document.getTextLength(), "\n");
}
}
else {
assert editor != null;
myConsole.addTextRangeToHistory(range, editor, myExecuteActionHandler.myPreserveMarkup);
}
myExecuteActionHandler.addToCommandHistoryAndExecute(myConsole, myConsoleView, text);
}
@@ -911,8 +911,10 @@ action.XDebugger.JumpToSource.description=Open source of the selected item
action.XDebugger.JumpToTypeSource.text=Jump To Type Source
action.XDebugger.JumpToTypeSource.description=Open source of the selected value's type
action.XDebugger.Inspect.text=Inspect...
action.XDebugger.AddToWatches.text=Add to Watches
action.XDebugger.EvaluateInConsole.text=Evaluate In Console
action.Debugger.Tree.AddToWatches.text=Add to Watches
action.Debugger.Tree.EvaluateInConsole.text=Evaluate In Console
action.XDebugger.RemoveWatch.text=Remove Watch
action.XDebugger.RemoveAllWatches.text=Remove All Watches
action.XDebugger.NewWatch.text=New Watch...
@@ -951,6 +953,7 @@ action.Debugger.MarkObject.text=Mark Object...
action.Debugger.MarkObject.unmark.text=Unmark Object
action.Debugger.MarkObject.description=Mark/unmark the object so that it can be visually distinguished in in debugger views
action.Debugger.AddToWatch.text=Add to Watches
action.Debugger.EvaluateInConsole.text=Evaluate in Console
action.Debugger.AutoRenderer.text=Auto
group.EditorPopupMenu.text=Editor Popup Menu
group.EditorPopupMenu.description=Editor Popup Menu
@@ -645,6 +645,7 @@
</group>
<action id="Debugger.AddToWatch" class="com.intellij.xdebugger.impl.actions.AddToWatchesAction" icon="AllIcons.Debugger.AddToWatch"/>
<action id="Debugger.EvaluateInConsole" class="com.intellij.xdebugger.impl.actions.EvaluateInConsoleAction"/>
<group id="EditorPopupMenuDebug">
<separator/>
@@ -652,6 +653,7 @@
<reference ref="RunToCursor"/>
<reference ref="ForceRunToCursor"/>
<reference ref="Debugger.AddToWatch"/>
<reference ref="Debugger.EvaluateInConsole"/>
<separator/>
<add-to-group group-id="EditorLangPopupMenu" relative-to-action="EditorPopupMenu.Run" anchor="before"/>
@@ -667,8 +669,8 @@
<action id="XDebugger.JumpToSource" class="com.intellij.xdebugger.impl.ui.tree.actions.XJumpToSourceAction"/>
<action id="XDebugger.JumpToTypeSource" class="com.intellij.xdebugger.impl.ui.tree.actions.XJumpToTypeSourceAction"/>
<action id="XDebugger.AddToWatches" class="com.intellij.xdebugger.impl.ui.tree.actions.XAddToWatchesAction" icon="AllIcons.Debugger.AddToWatch"/>
<action id="XDebugger.EvaluateInConsole" class="com.intellij.xdebugger.impl.actions.EvaluateInConsoleAction"/>
<action id="Debugger.Tree.AddToWatches" class="com.intellij.xdebugger.impl.ui.tree.actions.XAddToWatchesAction" icon="AllIcons.Debugger.AddToWatch"/>
<action id="Debugger.Tree.EvaluateInConsole" class="com.intellij.xdebugger.impl.ui.tree.actions.EvaluateInConsoleFromTreeAction"/>
<action id="XDebugger.NewWatch" class="com.intellij.xdebugger.impl.frame.actions.XNewWatchAction" icon="AllIcons.Debugger.NewWatch"/>
<action id="XDebugger.EditWatch" class="com.intellij.xdebugger.impl.frame.actions.XEditWatchAction"/>
@@ -719,8 +721,8 @@
<reference ref="XDebugger.ValueGroup"/>
<reference ref="XDebugger.JumpToSource"/>
<reference ref="XDebugger.JumpToTypeSource"/>
<reference ref="XDebugger.AddToWatches"/>
<reference ref="XDebugger.EvaluateInConsole"/>
<reference ref="Debugger.Tree.AddToWatches"/>
<reference ref="Debugger.Tree.EvaluateInConsole"/>
</group>
<group id="XDebugger.Variables.Tree.Toolbar">
@@ -741,8 +743,8 @@
<group id="XDebugger.Inspect.Tree.Popup">
<reference ref="XDebugger.ValueGroup"/>
<reference ref="XDebugger.AddToWatches"/>
<reference ref="XDebugger.EvaluateInConsole"/>
<reference ref="Debugger.Tree.AddToWatches"/>
<reference ref="Debugger.Tree.EvaluateInConsole"/>
</group>
<group id="XDebugger.Settings" icon="AllIcons.General.SecondaryGroup" popup="true">
@@ -18,9 +18,6 @@ package com.intellij.xdebugger.impl.actions;
import com.intellij.xdebugger.impl.DebuggerSupport;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
final class AddToWatchesAction extends XDebuggerActionBase {
public AddToWatchesAction() {
super(true);
@@ -2,6 +2,7 @@ package com.intellij.xdebugger.impl.actions.handlers;
import com.intellij.execution.console.ConsoleExecuteAction;
import com.intellij.execution.console.LanguageConsoleView;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
@@ -27,10 +28,16 @@ public class XEvaluateInConsoleFromEditorActionHandler extends XAddToWatchesFrom
@Nullable
private static ConsoleExecuteAction getConsoleExecuteAction(@NotNull XDebugSession session) {
if (!(session.getConsoleView() instanceof LanguageConsoleView)) {
return getConsoleExecuteAction(session.getConsoleView());
}
@Nullable
public static ConsoleExecuteAction getConsoleExecuteAction(@Nullable ConsoleView consoleView) {
if (!(consoleView instanceof LanguageConsoleView)) {
return null;
}
List<AnAction> actions = ActionUtil.getActions(((LanguageConsoleView)session.getConsoleView()).getConsole().getConsoleEditor().getComponent());
List<AnAction> actions = ActionUtil.getActions(((LanguageConsoleView)consoleView).getConsole().getConsoleEditor().getComponent());
ConsoleExecuteAction action = ContainerUtil.findInstance(actions, ConsoleExecuteAction.class);
return action == null || !action.isEnabled() ? null : action;
}
@@ -144,6 +144,9 @@ public class XDebugSessionTab extends DebuggerSessionTabBase {
if (XWatchesView.DATA_KEY.is(dataId)) {
return myWatchesView;
}
if (LangDataKeys.CONSOLE_VIEW.is(dataId)) {
return session.getConsoleView();
}
return null;
}
});
@@ -0,0 +1,32 @@
package com.intellij.xdebugger.impl.ui.tree.actions;
import com.intellij.execution.console.ConsoleExecuteAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.xdebugger.impl.actions.handlers.XEvaluateInConsoleFromEditorActionHandler;
import com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
class EvaluateInConsoleFromTreeAction extends XAddToWatchesAction {
@Override
protected boolean isEnabled(@NotNull XValueNodeImpl node, @NotNull AnActionEvent e) {
return super.isEnabled(node, e) && getConsoleExecuteAction(e) != null;
}
@Nullable
private static ConsoleExecuteAction getConsoleExecuteAction(@NotNull AnActionEvent e) {
return XEvaluateInConsoleFromEditorActionHandler.getConsoleExecuteAction(e.getData(LangDataKeys.CONSOLE_VIEW));
}
@Override
protected void perform(XValueNodeImpl node, @NotNull String nodeName, AnActionEvent e) {
ConsoleExecuteAction action = getConsoleExecuteAction(e);
if (action != null) {
String expression = node.getValueContainer().getEvaluationExpression();
if (expression != null) {
action.execute(null, expression, null);
}
}
}
}
@@ -21,9 +21,9 @@ import com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
* This action works only in the variables view, it is not generic action like {@see com.intellij.xdebugger.impl.actions.AddToWatchesAction}
*/
public class XAddToWatchesAction extends XDebuggerTreeActionBase {
class XAddToWatchesAction extends XDebuggerTreeActionBase {
@Override
protected boolean isEnabled(@NotNull final XValueNodeImpl node, @NotNull AnActionEvent e) {
return super.isEnabled(node, e) && node.getValueContainer().getEvaluationExpression() != null && e.getData(XWatchesView.DATA_KEY) != null;