protected override bool CanDrop(ItemContainer[] dragItems, ItemContainer dropTarget) { if (!base.CanDrop(dragItems, dropTarget)) { return(false); } TreeViewItem tvDropTarget = (TreeViewItem)dropTarget; if (tvDropTarget == null) { return(true); } foreach (ItemContainer dragItem in dragItems) { TreeViewItem tvDragItem = (TreeViewItem)dragItem; if (tvDropTarget.IsDescendantOf(tvDragItem)) { return(false); } } return(true); }
private void MoveSubtree(TreeViewItem parent, TreeViewItem child) { int parentSiblingIndex = parent.transform.GetSiblingIndex(); int siblingIndex = child.transform.GetSiblingIndex(); bool incrementSiblingIndex = false; if (parentSiblingIndex < siblingIndex) { incrementSiblingIndex = true; } TreeViewItem prev = parent; while (child != null && child.IsDescendantOf(parent)) { if (prev == child) { break; } DropItemAfter(prev, child); prev = child; if (incrementSiblingIndex) { siblingIndex++; } child = (TreeViewItem)GetItemContainer(siblingIndex); } }
/// <summary> /// Get Next Child Of TreeViewItem /// </summary> /// <param name="currentChild"></param> /// <returns>next treeview item after current child</returns> public TreeViewItem NextChild(TreeViewItem currentChild) { if (currentChild == null) { throw new ArgumentNullException("currentChild"); } int siblingIndex = currentChild.transform.GetSiblingIndex(); siblingIndex++; TreeViewItem nextChild = (TreeViewItem)m_treeView.GetItemContainer(siblingIndex); while (nextChild != null && nextChild.IsDescendantOf(this)) { if (nextChild.Parent == this) { return(nextChild); } siblingIndex++; nextChild = (TreeViewItem)m_treeView.GetItemContainer(siblingIndex); } return(null); }
/// <summary> /// Get Last Child of TreeViewItem /// </summary> /// <returns>Last Child</returns> public TreeViewItem LastChild() { if (!HasChildren) { return(null); } int siblingIndex = transform.GetSiblingIndex(); TreeViewItem lastChild = null; while (true) { siblingIndex++; TreeViewItem child = (TreeViewItem)TreeView.GetItemContainer(siblingIndex); if (child == null || !child.IsDescendantOf(this)) { return(lastChild); } if (child.Parent == this) { lastChild = child; } } }
protected override bool CanDrop(ItemContainer[] dragItems, ItemContainer dropTarget) { if (!base.CanDrop(dragItems, dropTarget)) { return(false); } TreeViewItem treeViewItem = (TreeViewItem)dropTarget; if (Object.op_Equality((Object)treeViewItem, (Object)null)) { return(true); } foreach (TreeViewItem dragItem in dragItems) { if (treeViewItem.IsDescendantOf(dragItem)) { return(false); } } return(true); }
public TreeViewItem LastDescendant() { if (!this.HasChildren) { return((TreeViewItem)null); } int siblingIndex = ((Component)this).get_transform().GetSiblingIndex(); TreeViewItem treeViewItem = (TreeViewItem)null; while (true) { ++siblingIndex; TreeViewItem itemContainer = (TreeViewItem)this.TreeView.GetItemContainer(siblingIndex); if (!Object.op_Equality((Object)itemContainer, (Object)null) && itemContainer.IsDescendantOf(this)) { treeViewItem = itemContainer; } else { break; } } return(treeViewItem); }
private void OnTreeViewItemParentChanged(object sender, ParentChangedEventArgs e) { TreeViewItem tvItem = (TreeViewItem)sender; if (!CanHandleEvent(tvItem)) { return; } TreeViewItem oldParent = e.OldParent; if (DropMarker.Action != ItemDropAction.SetLastChild && DropMarker.Action != ItemDropAction.None) { if (oldParent != null && !oldParent.HasChildren) { oldParent.CanExpand = false; } return; } TreeViewItem tvDropTarget = e.NewParent; if (tvDropTarget != null) { if (tvDropTarget.CanExpand) { tvDropTarget.IsExpanded = true; } else { tvDropTarget.CanExpand = true; try { m_expandSilently = true; tvDropTarget.IsExpanded = true; } finally { m_expandSilently = false; } } } TreeViewItem dragItemChild = tvItem.FirstChild(); TreeViewItem lastChild = null; if (tvDropTarget != null) { lastChild = tvDropTarget.LastChild(); if (lastChild == null) { lastChild = tvDropTarget; } } else { lastChild = (TreeViewItem)LastItemContainer(); } if (lastChild != tvItem) { TreeViewItem lastDescendant = lastChild.LastDescendant(); if (lastDescendant != null) { lastChild = lastDescendant; } if (!lastChild.IsDescendantOf(tvItem)) { base.SetNextSibling(lastChild, tvItem); } } if (dragItemChild != null) { MoveSubtree(tvItem, dragItemChild); } if (oldParent != null && !oldParent.HasChildren) { oldParent.CanExpand = false; } }
public TreeViewItem NextChild(TreeViewItem currentChild) { if (Object.op_Equality((Object)currentChild, (Object)null)) { throw new ArgumentNullException(nameof(currentChild)); } int siblingIndex = ((Component)currentChild).get_transform().GetSiblingIndex() + 1; for (TreeViewItem itemContainer = (TreeViewItem)this.TreeView.GetItemContainer(siblingIndex); Object.op_Inequality((Object)itemContainer, (Object)null) && itemContainer.IsDescendantOf(this); itemContainer = (TreeViewItem)this.TreeView.GetItemContainer(siblingIndex)) { if (Object.op_Equality((Object)itemContainer.Parent, (Object)this)) { return(itemContainer); } ++siblingIndex; } return((TreeViewItem)null); }
private void MoveSubtree(TreeViewItem parent, TreeViewItem child) { int siblingIndex1 = ((Component)parent).get_transform().GetSiblingIndex(); int siblingIndex2 = ((Component)child).get_transform().GetSiblingIndex(); bool flag = false; if (siblingIndex1 < siblingIndex2) { flag = true; } for (TreeViewItem treeViewItem = parent; Object.op_Inequality((Object)child, (Object)null) && child.IsDescendantOf(parent) && !Object.op_Equality((Object)treeViewItem, (Object)child); child = (TreeViewItem)this.GetItemContainer(siblingIndex2)) { base.SetNextSibling((ItemContainer)treeViewItem, (ItemContainer)child); treeViewItem = child; if (flag) { ++siblingIndex2; } } }