From f9c707fb7adae7bd58b76eec8d642343c06fbd88 Mon Sep 17 00:00:00 2001 From: Egor Ushakov Date: Fri, 28 Dec 2018 15:36:44 +0300 Subject: [PATCH] IDEA-204807 "Add to Watches" action shouldn't create duplicates --- .../XAddToWatchesFromEditorActionHandler.java | 3 ++- .../impl/frame/XWatchesViewImpl.java | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XAddToWatchesFromEditorActionHandler.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XAddToWatchesFromEditorActionHandler.java index 3934daf0030e..94cc9abd5b6d 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XAddToWatchesFromEditorActionHandler.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XAddToWatchesFromEditorActionHandler.java @@ -10,6 +10,7 @@ import com.intellij.xdebugger.XDebugSession; import com.intellij.xdebugger.evaluation.XDebuggerEvaluator; import com.intellij.xdebugger.impl.XDebugSessionImpl; import com.intellij.xdebugger.impl.breakpoints.XExpressionImpl; +import com.intellij.xdebugger.impl.frame.XWatchesViewImpl; import com.intellij.xdebugger.impl.ui.XDebugSessionTab; import org.jetbrains.annotations.NotNull; import org.jetbrains.concurrency.Promise; @@ -69,7 +70,7 @@ public class XAddToWatchesFromEditorActionHandler extends XDebuggerActionHandler UIUtil.invokeLaterIfNeeded(() -> { XDebugSessionTab tab = ((XDebugSessionImpl)session).getSessionTab(); if (tab != null) { - tab.getWatchesView().addWatchExpression(XExpressionImpl.fromText(text), -1, true); + ((XWatchesViewImpl)tab.getWatchesView()).addWatchExpression(XExpressionImpl.fromText(text), -1, true, true); } }); }); 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 bc5ab63c087a..2a027c5a799b 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 @@ -207,10 +207,25 @@ public class XWatchesViewImpl extends XVariablesView implements DnDNativeTarget, @Override public void addWatchExpression(@NotNull XExpression expression, int index, final boolean navigateToWatchNode) { + addWatchExpression(expression, index, navigateToWatchNode, false); + } + + public void addWatchExpression(@NotNull XExpression expression, int index, final boolean navigateToWatchNode, boolean noDuplicates) { ApplicationManager.getApplication().assertIsDispatchThread(); XDebugSession session = getSession(getTree()); - myRootNode.addWatchExpression(session != null ? session.getCurrentStackFrame() : null, expression, index, navigateToWatchNode); - updateSessionData(); + boolean found = false; + if (noDuplicates) { + for (WatchNode child : myRootNode.getWatchChildren()) { + if (child.getExpression().equals(expression)) { + TreeUtil.selectNode(getTree(), child); + found = true; + } + } + } + if (!found) { + myRootNode.addWatchExpression(session != null ? session.getCurrentStackFrame() : null, expression, index, navigateToWatchNode); + updateSessionData(); + } if (navigateToWatchNode && session != null) { XDebugSessionTab.showWatchesView((XDebugSessionImpl)session); }