IDEA-204807 "Add to Watches" action shouldn't create duplicates

This commit is contained in:
Egor Ushakov
2018-12-28 15:37:20 +03:00
parent 9e8790658f
commit f9c707fb7a
2 changed files with 19 additions and 3 deletions
@@ -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);
}
});
});
@@ -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);
}