From 28d3bc674d6dcb49f10e2747056b12ec9ccdb310 Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Tue, 6 Oct 2009 11:37:59 +0400 Subject: [PATCH] TreeUi: moved element keeps selection - tested --- .../ide/util/treeView/UpdaterTreeState.java | 46 ++++++++++++++++--- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/UpdaterTreeState.java b/platform/platform-api/src/com/intellij/ide/util/treeView/UpdaterTreeState.java index 3e9c891572be..dde9c30ac69c 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/UpdaterTreeState.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/UpdaterTreeState.java @@ -238,20 +238,19 @@ public class UpdaterTreeState { if (newSelection.length > 0) { myUi._select(newSelection, new Runnable() { public void run() { + final Set hangByParent = new HashSet (); processUnsuccessfulSelections(newSelection, new Function() { public Object fun(final Object o) { if (myUi.isInStructure(o) && !adjusted.get(o).value(o)) { - Object parent = myUi.getTreeStructure().getParentElement(o); - if (parent != null) { - addSelection(parent); - } - return null; + hangByParent.add(o); + } else { + addAdjustedSelection(o, adjusted.get(o)); } - addAdjustedSelection(o, adjusted.get(o)); return null; } }, originallySelected); - result.setDone(); + + processHangByParent(hangByParent).notify(result); } }, true, true, true); } else { @@ -261,6 +260,39 @@ public class UpdaterTreeState { return result; } + private ActionCallback processHangByParent(Set elements) { + if (elements.size() == 0) return new ActionCallback.Done(); + + ActionCallback result = new ActionCallback(elements.size()); + for (Iterator iterator = elements.iterator(); iterator.hasNext();) { + processHangByParent(iterator.next()).notify(result); + } + return result; + } + + private ActionCallback processHangByParent(Object each) { + ActionCallback result = new ActionCallback(); + processNextHang(each, result); + return result; + } + + private void processNextHang(Object element, final ActionCallback callback) { + if (element == null || myUi.getSelectedElements().contains(element)) { + callback.setDone(); + } else { + final Object nextElement = myUi.getTreeStructure().getParentElement(element); + if (nextElement == null) { + callback.setDone(); + } else { + myUi.select(nextElement, new Runnable() { + public void run() { + processNextHang(nextElement, callback); + } + }, true); + } + } + } + private boolean isParentOrSame(Object parent, Object child) { Object eachParent = child; while (eachParent != null) {