From 860f3889a29886b29ce7c1d5769061fa901cd369 Mon Sep 17 00:00:00 2001 From: Evgeny Terekhin <> Date: Mon, 16 Nov 2020 14:50:23 +0000 Subject: [PATCH] added immediate window shortcut GitOrigin-RevId: 89c8a916953769551b4cb10e89a39f226ed1d4b2 --- .../XDebuggerEvaluateActionHandler.java | 32 +++++++++------- .../impl/frame/XWatchesViewImpl.java | 30 ++++----------- .../xdebugger/impl/frame/XWatchesViewImpl2.kt | 37 ++----------------- .../impl/ui/XDebugSessionTabCustomizer.java | 11 ------ 4 files changed, 31 insertions(+), 79 deletions(-) diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XDebuggerEvaluateActionHandler.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XDebuggerEvaluateActionHandler.java index 484e1af5a8d9..d9471ba079fb 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XDebuggerEvaluateActionHandler.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XDebuggerEvaluateActionHandler.java @@ -8,6 +8,7 @@ import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.AppUIUtil; import com.intellij.xdebugger.XDebugSession; @@ -37,6 +38,23 @@ public class XDebuggerEvaluateActionHandler extends XDebuggerActionHandler { return; } + final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(dataContext); + XValue value = XDebuggerTreeActionBase.getSelectedValue(dataContext); + getSelectedTextAsync(evaluator, dataContext) + .onSuccess(pair -> { + var evalExpression = pair.first; + var evalMode = pair.second; + if (evalExpression == null && value != null) { + value.calculateEvaluationExpression().onSuccess( + expression -> AppUIUtil.invokeOnEdt(() -> showDialog(session, file, editorsProvider, stackFrame, evaluator, expression))); + } else { + AppUIUtil.invokeOnEdt(() -> showDialog(session, file, editorsProvider, stackFrame, evaluator, + XExpressionImpl.fromText(evalExpression, evalMode))); + } + }); + } + + public static Promise> getSelectedTextAsync(@NotNull XDebuggerEvaluator evaluator, @NotNull DataContext dataContext) { Editor editor = CommonDataKeys.EDITOR.getData(dataContext); EvaluationMode mode = EvaluationMode.EXPRESSION; @@ -56,20 +74,8 @@ public class XDebuggerEvaluateActionHandler extends XDebuggerActionHandler { expressionTextPromise = evaluator.getWhenDataIsReady(editor, selectedText); } - final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(dataContext); - EvaluationMode finalMode = mode; - XValue value = XDebuggerTreeActionBase.getSelectedValue(dataContext); - expressionTextPromise.onSuccess(expressionText -> { - if (expressionText == null && value != null) { - value.calculateEvaluationExpression().onSuccess( - expression -> AppUIUtil.invokeOnEdt(() -> showDialog(session, file, editorsProvider, stackFrame, evaluator, expression))); - } - else { - AppUIUtil.invokeOnEdt(() -> showDialog(session, file, editorsProvider, stackFrame, evaluator, - XExpressionImpl.fromText(expressionText, finalMode))); - } - }); + return expressionTextPromise.then(expression -> Pair.create(expression, finalMode)); } private static void showDialog(@NotNull XDebugSession session, diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XWatchesViewImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XWatchesViewImpl.java index 4ce257ed158d..17ec395b8027 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XWatchesViewImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XWatchesViewImpl.java @@ -69,17 +69,15 @@ public class XWatchesViewImpl extends XVariablesView implements DnDNativeTarget, private final CompositeDisposable myDisposables = new CompositeDisposable(); private final boolean myWatchesInVariables; - private final boolean myVertical; private final boolean inlineWatchesEnabled; public XWatchesViewImpl(@NotNull XDebugSessionImpl session, boolean watchesInVariables) { - this(session, watchesInVariables, watchesInVariables, true); + this(session, watchesInVariables, watchesInVariables); } - protected XWatchesViewImpl(@NotNull XDebugSessionImpl session, boolean watchesInVariables, boolean vertical, boolean createToolbar) { + protected XWatchesViewImpl(@NotNull XDebugSessionImpl session, boolean watchesInVariables, boolean vertical) { super(session); myWatchesInVariables = watchesInVariables; - myVertical = vertical; inlineWatchesEnabled = Registry.is("debugger.watches.inline.enabled"); XDebuggerTree tree = getTree(); @@ -109,31 +107,19 @@ public class XWatchesViewImpl extends XVariablesView implements DnDNativeTarget, } }.registerCustomShortcutSet(CommonShortcuts.getPaste(), tree, myDisposables); - if(createToolbar) - createToolbar(AnAction.EMPTY_ARRAY); - } - - protected void createToolbar(AnAction[] extraActions){ - final DefaultActionGroup actionGroup = new DefaultActionGroup(); - actionGroup.add(ActionManager.getInstance().getAction(XDebuggerActions.WATCHES_TREE_TOOLBAR_GROUP)); - - for (var action : extraActions) { - actionGroup.add(action); - } - ActionToolbarImpl toolbar = (ActionToolbarImpl)ActionManager.getInstance().createActionToolbar( ActionPlaces.DEBUGGER_TOOLBAR, - actionGroup, - !myVertical); + DebuggerSessionTabBase.getCustomizedActionGroup(XDebuggerActions.WATCHES_TREE_TOOLBAR_GROUP), + !vertical); toolbar.setBorder(new CustomLineBorder(CaptionPanel.CNT_ACTIVE_BORDER_COLOR, 0, 0, - myVertical ? 0 : 1, - myVertical ? 1 : 0)); - toolbar.setTargetComponent(getTree()); + vertical ? 0 : 1, + vertical ? 1 : 0)); + toolbar.setTargetComponent(tree); if (!myWatchesInVariables) { getTree().getEmptyText().setText(XDebuggerBundle.message("debugger.no.watches")); } - getPanel().add(toolbar.getComponent(), myVertical ? BorderLayout.WEST : BorderLayout.NORTH); + getPanel().add(toolbar.getComponent(), vertical ? BorderLayout.WEST : BorderLayout.NORTH); installEditListeners(); } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XWatchesViewImpl2.kt b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XWatchesViewImpl2.kt index 07abfa0ccfff..0c109f7b58fe 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XWatchesViewImpl2.kt +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XWatchesViewImpl2.kt @@ -4,11 +4,8 @@ import com.intellij.ide.DataManager import com.intellij.ide.dnd.DnDNativeTarget import com.intellij.ide.util.PropertiesComponent import com.intellij.openapi.Disposable -import com.intellij.openapi.actionSystem.AnAction -import com.intellij.openapi.actionSystem.AnActionEvent -import com.intellij.openapi.actionSystem.ToggleAction +import com.intellij.openapi.actionSystem.* import com.intellij.openapi.actionSystem.impl.ActionToolbarImpl -import com.intellij.openapi.ui.Splitter import com.intellij.ui.OnePixelSplitter import com.intellij.util.ui.UIUtil import com.intellij.util.ui.components.BorderLayoutPanel @@ -23,13 +20,12 @@ class XWatchesViewImpl2( isVertical: Boolean, val layoutDisposable: Disposable ) : - XWatchesViewImpl(session, watchesInVariables, isVertical, false), DnDNativeTarget, XWatchesView { + XWatchesViewImpl(session, watchesInVariables, isVertical), DnDNativeTarget, XWatchesView { init { val bottomLocalsComponentProvider = (session.debugProcess as? XDebugSessionTabCustomizer)?.bottomLocalsComponentProvider - if (bottomLocalsComponentProvider == null) - super.createToolbar(AnAction.EMPTY_ARRAY) - else { + if (bottomLocalsComponentProvider != null) + { // it's hacky, we change default watches component to splitter, this way allows not to change base components DataManager.removeDataProvider(myComponent) val splitter = OnePixelSplitter(true, "debugger.immediate.window.in.watches.proportion.key", 0.5f) @@ -37,7 +33,6 @@ class XWatchesViewImpl2( dividerWidth = 1 divider.background = UIUtil.CONTRAST_BORDER_COLOR } - super.createToolbar(arrayOf(createExtraAction(splitter, bottomLocalsComponentProvider))) val toolbar = myComponent.getComponent(1) as ActionToolbarImpl val locals = myComponent.getComponent(0) as JPanel splitter.firstComponent = locals @@ -51,28 +46,4 @@ class XWatchesViewImpl2( DataManager.registerDataProvider(myComponent, this) } } - - fun createExtraAction( - splitter: Splitter, - sessionTabComponentProvider: XDebugSessionTabCustomizer.SessionTabComponentProvider - ): AnAction { - return object : ToggleAction(sessionTabComponentProvider.componentIconPopupText, null, sessionTabComponentProvider.componentIcon) { - private var bottomComponentIsVisible: Boolean = - PropertiesComponent.getInstance().getBoolean("debugger.immediate.window.in.watches", true) - override fun isSelected(e: AnActionEvent): Boolean = bottomComponentIsVisible - override fun setSelected(e: AnActionEvent, state: Boolean) { - bottomComponentIsVisible = !bottomComponentIsVisible - splitter.apply { - if (bottomComponentIsVisible) - secondComponent = sessionTabComponentProvider.createBottomLocalsComponent(layoutDisposable) - else - secondComponent = null - revalidate() - repaint() - } - sessionTabComponentProvider.visibilityChanged(bottomComponentIsVisible) - PropertiesComponent.getInstance().setValue("debugger.immediate.window.in.watches", bottomComponentIsVisible, true) - } - } - } } \ No newline at end of file diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionTabCustomizer.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionTabCustomizer.java index bf0bf81f76fd..6650ba62cd54 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionTabCustomizer.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionTabCustomizer.java @@ -11,17 +11,6 @@ import javax.swing.*; public interface XDebugSessionTabCustomizer { @Nullable SessionTabComponentProvider getBottomLocalsComponentProvider(); interface SessionTabComponentProvider { - default void visibilityChanged(boolean isVisible) { - } - - default @Nullable Icon getComponentIcon(){ - return null; - } - - default @Nullable String getComponentIconPopupText(){ - return null; - } - JComponent createBottomLocalsComponent(@NotNull Disposable layoutDisposable); } }