actions for edit/delete filter

This commit is contained in:
Egor.Ushakov
2017-05-25 17:25:11 +03:00
parent efcba2c727
commit d0180fe97b
5 changed files with 101 additions and 20 deletions
@@ -196,7 +196,8 @@ public abstract class ArrayAction extends DebuggerAction {
ArrayRenderer original,
@NotNull DebuggerContextImpl debuggerContext,
String title) {
return ArrayFilterInplaceEditor.edit(node, original);
ArrayFilterInplaceEditor.edit(node);
return Promises.rejectedPromise();
}
}
}
@@ -0,0 +1,82 @@
/*
* Copyright 2000-2017 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.debugger.actions;
import com.intellij.debugger.DebuggerManagerEx;
import com.intellij.debugger.settings.NodeRendererSettings;
import com.intellij.debugger.ui.tree.render.ArrayFilterInplaceEditor;
import com.intellij.debugger.ui.tree.render.ArrayRenderer;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.util.ArrayUtil;
import com.intellij.xdebugger.impl.ui.tree.XDebuggerTree;
import com.intellij.xdebugger.impl.ui.tree.nodes.MessageTreeNode;
import com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl;
import org.jetbrains.annotations.Nullable;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
/**
* @author egor
*/
public abstract class ArrayFilterAction extends AnAction {
@Override
public void update(AnActionEvent e) {
e.getPresentation().setEnabledAndVisible(getFilterNode(e) != null);
}
public static boolean isArrayFilter(TreeNode node) {
return node instanceof MessageTreeNode && ((MessageTreeNode)node).getLink() == ArrayRenderer.Filtered.FILTER_HYPERLINK;
}
@Nullable
private static MessageTreeNode getFilterNode(AnActionEvent e) {
XDebuggerTree tree = XDebuggerTree.getTree(e.getDataContext());
if (tree != null) {
TreePath[] paths = tree.getSelectionPaths();
if (!ArrayUtil.isEmpty(paths) && paths.length == 1) {
Object node = paths[0].getLastPathComponent();
if (isArrayFilter((TreeNode)node)) {
return (MessageTreeNode)node;
}
}
}
return null;
}
public static class Edit extends ArrayFilterAction {
@Override
public void actionPerformed(AnActionEvent e) {
MessageTreeNode node = getFilterNode(e);
if (node != null) {
ArrayFilterInplaceEditor.edit((XValueNodeImpl)node.getParent());
}
}
}
public static class Delete extends ArrayFilterAction {
@Override
public void actionPerformed(AnActionEvent e) {
MessageTreeNode node = getFilterNode(e);
if (node != null) {
ArrayAction.setArrayRenderer(NodeRendererSettings.getInstance().getArrayRenderer(),
(XValueNodeImpl)node.getParent(),
DebuggerManagerEx.getInstanceEx(e.getProject()).getContext());
}
}
}
}
@@ -16,6 +16,9 @@
package com.intellij.debugger.ui.tree.render
import com.intellij.debugger.DebuggerBundle
import com.intellij.debugger.DebuggerManagerEx
import com.intellij.debugger.actions.ArrayAction
import com.intellij.debugger.actions.ArrayFilterAction
import com.intellij.debugger.settings.NodeRendererSettings
import com.intellij.icons.AllIcons
import com.intellij.ui.SimpleColoredComponent
@@ -23,28 +26,26 @@ import com.intellij.ui.SimpleTextAttributes
import com.intellij.xdebugger.impl.XDebuggerUtilImpl
import com.intellij.xdebugger.impl.ui.DebuggerUIUtil
import com.intellij.xdebugger.impl.ui.tree.XDebuggerTreeInplaceEditor
import com.intellij.xdebugger.impl.ui.tree.nodes.MessageTreeNode
import com.intellij.xdebugger.impl.ui.tree.nodes.XDebuggerTreeNode
import com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl
import org.jetbrains.concurrency.AsyncPromise
import org.jetbrains.concurrency.Promise
import java.awt.Rectangle
/**
* @author egor
*/
class ArrayFilterInplaceEditor(node: XDebuggerTreeNode, val myTemp : Boolean, val res: AsyncPromise<ArrayRenderer>) : XDebuggerTreeInplaceEditor(node, "arrayFilter") {
class ArrayFilterInplaceEditor(node: XDebuggerTreeNode, val myTemp : Boolean) : XDebuggerTreeInplaceEditor(node, "arrayFilter") {
override fun cancelEditing() {
super.cancelEditing()
if (myTemp) (myNode.parent as XValueNodeImpl).removeTemporaryEditorNode(myNode)
res.setError("Cancelled")
}
override fun doOKAction() {
res.setResult(if (XDebuggerUtilImpl.isEmptyExpression(expression))
NodeRendererSettings.getInstance().arrayRenderer
else
ArrayRenderer.Filtered(expression))
ArrayAction.setArrayRenderer(if (XDebuggerUtilImpl.isEmptyExpression(expression))
NodeRendererSettings.getInstance().arrayRenderer
else
ArrayRenderer.Filtered(expression),
myNode.parent as XValueNodeImpl,
DebuggerManagerEx.getInstanceEx(project).context)
super.doOKAction()
}
@@ -65,20 +66,14 @@ class ArrayFilterInplaceEditor(node: XDebuggerTreeNode, val myTemp : Boolean, va
companion object {
@JvmStatic
fun edit(parentNode: XValueNodeImpl,
original: ArrayRenderer): Promise<ArrayRenderer> {
val res = AsyncPromise<ArrayRenderer>()
fun edit(parentNode: XValueNodeImpl) {
var temp = false
val node: XDebuggerTreeNode
if (original is ArrayRenderer.Filtered) {
node = parentNode.children.find { it is MessageTreeNode && it.link === ArrayRenderer.Filtered.FILTER_HYPERLINK } as XDebuggerTreeNode
}
else {
var node = parentNode.children.find { ArrayFilterAction.isArrayFilter(it) }
if (node == null) {
node = parentNode.addTemporaryEditorNode(AllIcons.General.Filter, DebuggerBundle.message("message.node.filtered"))
temp = true
}
DebuggerUIUtil.invokeLater({ArrayFilterInplaceEditor(node, temp, res).show()})
return res
DebuggerUIUtil.invokeLater({ArrayFilterInplaceEditor(node as XDebuggerTreeNode, temp).show()})
}
}
}
@@ -1068,6 +1068,8 @@ action.Debugger.ViewText.description=View text value of selected node in a separ
action.Debugger.EditCustomField.text=Edit...
action.Debugger.NewCustomField.text=New Class Level Watch...
action.Debugger.RemoveCustomField.text=Remove Watch
action.Debugger.EditArrayFilter.text=Edit...
action.Debugger.RemoveArrayFilter.text=Remove Filter
action.Debugger.ShowReferring.text=Show Referring Objects...
action.Debugger.CompareValueWithClipboard.text=Compare Value with Clipboard
action.Debugger.CompareValueWithClipboard.description=Compare value of selected node with clipboard text
@@ -210,6 +210,7 @@ public abstract class XValueContainerNode<ValueContainer extends XValueContainer
fireNodesInserted(messages);
}
@NotNull
public XDebuggerTreeNode addTemporaryEditorNode(@Nullable Icon icon, @Nullable String text) {
if (isLeaf()) {
setLeaf(false);