public TreeViewItemContainerData LastDescendant(
            VirtualizingTreeView treeView)
        {
            if (!this.HasChildren(treeView))
            {
                return((TreeViewItemContainerData)null);
            }
            int siblingIndex = treeView.IndexOf(this.Item);
            TreeViewItemContainerData itemContainerData1 = (TreeViewItemContainerData)null;

            while (true)
            {
                ++siblingIndex;
                TreeViewItemContainerData itemContainerData2 = (TreeViewItemContainerData)treeView.GetItemContainerData(siblingIndex);
                if (itemContainerData2 != null && itemContainerData2.IsDescendantOf(this))
                {
                    itemContainerData1 = itemContainerData2;
                }
                else
                {
                    break;
                }
            }
            return(itemContainerData1);
        }
        /// <summary>
        /// Get Next Child Of TreeViewItem
        /// </summary>
        /// <param name="currentChild"></param>
        /// <returns>next treeview item after current child</returns>
        public TreeViewItemContainerData NextChild(VirtualizingTreeView treeView, TreeViewItemContainerData currentChild)
        {
            if (currentChild == null)
            {
                throw new ArgumentNullException("currentChild");
            }

            int siblingIndex = treeView.IndexOf(currentChild.Item);

            siblingIndex++;

            TreeViewItemContainerData nextChild = (TreeViewItemContainerData)treeView.GetItemContainerData(siblingIndex);

            while (nextChild != null && nextChild.IsDescendantOf(this))
            {
                if (nextChild.Parent == this)
                {
                    return(nextChild);
                }

                siblingIndex++;
                nextChild = (TreeViewItemContainerData)treeView.GetItemContainerData(siblingIndex);
            }

            return(null);
        }
        public TreeViewItemContainerData LastChild(
            VirtualizingTreeView treeView)
        {
            if (!this.HasChildren(treeView))
            {
                return((TreeViewItemContainerData)null);
            }
            int siblingIndex = treeView.IndexOf(this.Item);
            TreeViewItemContainerData itemContainerData1 = (TreeViewItemContainerData)null;

            while (true)
            {
                TreeViewItemContainerData itemContainerData2;
                do
                {
                    ++siblingIndex;
                    itemContainerData2 = (TreeViewItemContainerData)treeView.GetItemContainerData(siblingIndex);
                    if (itemContainerData2 == null || !itemContainerData2.IsDescendantOf(this))
                    {
                        return(itemContainerData1);
                    }
                }while (itemContainerData2.Parent != this);
                itemContainerData1 = itemContainerData2;
            }
        }
        /// <summary>
        /// Get Last Child of TreeViewItem
        /// </summary>
        /// <returns>Last Child</returns>
        public TreeViewItemContainerData LastChild(VirtualizingTreeView treeView)
        {
            if (!HasChildren(treeView))
            {
                return(null);
            }

            int siblingIndex = treeView.IndexOf(Item);

            TreeViewItemContainerData lastChild = null;

            while (true)
            {
                siblingIndex++;
                TreeViewItemContainerData child = (TreeViewItemContainerData)treeView.GetItemContainerData(siblingIndex);
                if (child == null || !child.IsDescendantOf(this))
                {
                    return(lastChild);
                }
                if (child.Parent == this)
                {
                    lastChild = child;
                }
            }
        }
 public static void ExpandAll <T>(
     this VirtualizingTreeView treeView,
     T item,
     Func <T, T> getParent,
     Func <T, IEnumerable> getChildren)
 {
     treeView.ExpandTo <T>(getParent(item), getParent);
     treeView.ExpandChildren <T>(item, getChildren);
 }
        public bool HasChildren(VirtualizingTreeView treeView)
        {
            if (Object.op_Equality((Object)treeView, (Object)null))
            {
                return(false);
            }
            int num = treeView.IndexOf(this.Item);
            TreeViewItemContainerData itemContainerData = (TreeViewItemContainerData)treeView.GetItemContainerData(num + 1);

            return(itemContainerData != null && itemContainerData.Parent == this);
        }
        public TreeViewItemContainerData FirstChild(
            VirtualizingTreeView treeView)
        {
            if (!this.HasChildren(treeView))
            {
                return((TreeViewItemContainerData)null);
            }
            int siblingIndex = treeView.IndexOf(this.Item) + 1;

            return((TreeViewItemContainerData)treeView.GetItemContainerData(siblingIndex));
        }
        /// <summary>
        /// Returns true if TreeViewItem has children. DO NOT USE THIS PROPERTY DURING DRAG&DROP OPERATION
        /// </summary>
        public bool HasChildren(VirtualizingTreeView treeView)
        {
            if (treeView == null)
            {
                return(false);
            }
            int index = treeView.IndexOf(Item);

            TreeViewItemContainerData nextItem = (TreeViewItemContainerData)treeView.GetItemContainerData(index + 1);

            return(nextItem != null && nextItem.Parent == this);
        }
        public static void ExpandChildren <T>(this VirtualizingTreeView treeView, T item, Func <T, IEnumerable> getChildren)
        {
            IEnumerable children = getChildren(item);

            if (children != null)
            {
                treeView.Expand(item);

                foreach (T child in children)
                {
                    treeView.ExpandChildren(child, getChildren);
                }
            }
        }
        public static void ExpandChildren <T>(
            this VirtualizingTreeView treeView,
            T item,
            Func <T, IEnumerable> getChildren)
        {
            IEnumerable enumerable = getChildren(item);

            if (enumerable == null)
            {
                return;
            }
            treeView.Expand((object)item);
            foreach (T obj in enumerable)
            {
                treeView.ExpandChildren <T>(obj, getChildren);
            }
        }
        /// <summary>
        /// Get First Child of TreeViewItem
        /// </summary>
        /// <returns>First Child</returns>
        public TreeViewItemContainerData FirstChild(VirtualizingTreeView treeView)
        {
            if (!HasChildren(treeView))
            {
                return(null);
            }

            int siblingIndex = treeView.IndexOf(Item);

            siblingIndex++;

            TreeViewItemContainerData child = (TreeViewItemContainerData)treeView.GetItemContainerData(siblingIndex);

            Debug.Assert(child != null && child.Parent == this);

            return(child);
        }
        public static void ExpandTo <T>(this VirtualizingTreeView treeView, T item, Func <T, T> getParent)
        {
            if (item == null)
            {
                return;
            }
            ItemContainerData containerData = treeView.GetItemContainerData(item);

            if (containerData == null)
            {
                treeView.ExpandTo(getParent(item), getParent);
                treeView.Expand(item);
            }
            else
            {
                treeView.Expand(item);
            }
        }
 public static void ExpandTo <T>(
     this VirtualizingTreeView treeView,
     T item,
     Func <T, T> getParent)
 {
     if ((object)item == null)
     {
         return;
     }
     if (treeView.GetItemContainerData((object)item) == null)
     {
         treeView.ExpandTo <T>(getParent(item), getParent);
         treeView.Expand((object)item);
     }
     else
     {
         treeView.Expand((object)item);
     }
 }
        protected override void AwakeOverride()
        {
            base.AwakeOverride();
            this.m_treeView = (VirtualizingTreeView)((Component)this).GetComponentInParent <VirtualizingTreeView>();
            this.m_siblingGraphicsRectTransform = (RectTransform)this.SiblingGraphics.GetComponent <RectTransform>();
            RectTransform          transform           = (RectTransform)((Component)this).get_transform();
            VirtualizingScrollRect componentInChildren = (VirtualizingScrollRect)((Component)this.m_treeView).GetComponentInChildren <VirtualizingScrollRect>();

            if (Object.op_Inequality((Object)componentInChildren, (Object)null) && componentInChildren.UseGrid)
            {
                this.m_useGrid = true;
                transform.set_anchorMin(Vector2.get_zero());
                transform.set_anchorMax(Vector2.get_zero());
            }
            else
            {
                transform.set_anchorMin(Vector2.get_zero());
                transform.set_anchorMax(new Vector2(1f, 0.0f));
            }
        }
        public TreeViewItemContainerData NextChild(
            VirtualizingTreeView treeView,
            TreeViewItemContainerData currentChild)
        {
            if (currentChild == null)
            {
                throw new ArgumentNullException(nameof(currentChild));
            }
            int siblingIndex = treeView.IndexOf(currentChild.Item) + 1;

            for (TreeViewItemContainerData itemContainerData = (TreeViewItemContainerData)treeView.GetItemContainerData(siblingIndex); itemContainerData != null && itemContainerData.IsDescendantOf(this); itemContainerData = (TreeViewItemContainerData)treeView.GetItemContainerData(siblingIndex))
            {
                if (itemContainerData.Parent == this)
                {
                    return(itemContainerData);
                }
                ++siblingIndex;
            }
            return((TreeViewItemContainerData)null);
        }
Ejemplo n.º 16
0
        protected override void AwakeOverride()
        {
            base.AwakeOverride();
            m_treeView = GetComponentInParent <VirtualizingTreeView>();
            m_siblingGraphicsRectTransform = SiblingGraphics.GetComponent <RectTransform>();

            RectTransform          rectTransform = (RectTransform)transform;
            VirtualizingScrollRect scrollRect    = m_treeView.GetComponentInChildren <VirtualizingScrollRect>();

            if (scrollRect != null && scrollRect.UseGrid)
            {
                m_useGrid = true;
                rectTransform.anchorMin = Vector2.zero;
                rectTransform.anchorMax = Vector2.zero;
            }
            else
            {
                rectTransform.anchorMin = Vector2.zero;
                rectTransform.anchorMax = new Vector2(1, 0);
            }
        }
        public static void ItemDropStdHandler <T>(
            this VirtualizingTreeView treeView,
            ItemDropArgs e,
            Func <T, T> getParent,
            Action <T, T> setParent,
            Func <T, T, int> indexOfChild,
            Action <T, T> removeChild,
            Action <T, T, int> insertChild)
            where T : class
        {
            T dropTarget = (T)e.DropTarget;

            if (e.Action == ItemDropAction.SetLastChild)
            {
                for (int index = 0; index < e.DragItems.Length; ++index)
                {
                    T dragItem = (T)e.DragItems[index];
                    removeChild(dragItem, getParent(dragItem));
                    setParent(dragItem, dropTarget);
                    insertChild(dragItem, getParent(dragItem), 0);
                }
            }
            else if (e.Action == ItemDropAction.SetNextSibling)
            {
                for (int index = e.DragItems.Length - 1; index >= 0; --index)
                {
                    T   dragItem = (T)e.DragItems[index];
                    int num1     = indexOfChild(dropTarget, getParent(dropTarget));
                    if ((object)getParent(dragItem) != (object)getParent(dropTarget))
                    {
                        removeChild(dragItem, getParent(dragItem));
                        setParent(dragItem, getParent(dropTarget));
                        insertChild(dragItem, getParent(dragItem), num1 + 1);
                    }
                    else
                    {
                        int num2 = indexOfChild(dragItem, getParent(dragItem));
                        if (num1 < num2)
                        {
                            removeChild(dragItem, getParent(dragItem));
                            insertChild(dragItem, getParent(dragItem), num1 + 1);
                        }
                        else
                        {
                            removeChild(dragItem, getParent(dragItem));
                            insertChild(dragItem, getParent(dragItem), num1);
                        }
                    }
                }
            }
            else
            {
                if (e.Action != ItemDropAction.SetPrevSibling)
                {
                    return;
                }
                for (int index = 0; index < e.DragItems.Length; ++index)
                {
                    T dragItem = (T)e.DragItems[index];
                    if ((object)getParent(dragItem) != (object)getParent(dropTarget))
                    {
                        removeChild(dragItem, getParent(dragItem));
                        setParent(dragItem, getParent(dropTarget));
                        insertChild(dragItem, getParent(dragItem), 0);
                    }
                    int num1 = indexOfChild(dropTarget, getParent(dropTarget));
                    int num2 = indexOfChild(dragItem, getParent(dragItem));
                    if (num1 > num2)
                    {
                        removeChild(dragItem, getParent(dragItem));
                        insertChild(dragItem, getParent(dragItem), num1 - 1);
                    }
                    else
                    {
                        removeChild(dragItem, getParent(dragItem));
                        insertChild(dragItem, getParent(dragItem), num1);
                    }
                }
            }
        }
 protected override void AwakeOverride()
 {
     base.AwakeOverride();
     m_treeView = GetComponentInParent <VirtualizingTreeView>();
     m_siblingGraphicsRectTransform = SiblingGraphics.GetComponent <RectTransform>();
 }
        public static void ItemDropStdHandler <T>(this VirtualizingTreeView treeView, ItemDropArgs e,
                                                  Func <T, T> getParent,
                                                  Action <T, T> setParent,
                                                  Func <T, T, int> indexOfChild,
                                                  Action <T, T> removeChild,
                                                  Action <T, T, int> insertChild,
                                                  Action <T, T> addChild = null) where T : class
        {
            T dropTarget = (T)e.DropTarget;

            //Set drag items as children of drop target
            if (e.Action == ItemDropAction.SetLastChild)
            {
                for (int i = 0; i < e.DragItems.Length; ++i)
                {
                    T dragItem = (T)e.DragItems[i];
                    removeChild(dragItem, getParent(dragItem));
                    setParent(dragItem, dropTarget);
                    if (addChild != null)
                    {
                        addChild(dragItem, getParent(dragItem));
                    }
                    else
                    {
                        insertChild(dragItem, getParent(dragItem), 0);
                    }
                }
            }

            //Put drag items next to drop target
            else if (e.Action == ItemDropAction.SetNextSibling)
            {
                for (int i = e.DragItems.Length - 1; i >= 0; --i)
                {
                    T   dragItem   = (T)e.DragItems[i];
                    int dropTIndex = indexOfChild(dropTarget, getParent(dropTarget));
                    if (getParent(dragItem) != getParent(dropTarget))
                    {
                        removeChild(dragItem, getParent(dragItem));
                        setParent(dragItem, getParent(dropTarget));
                        insertChild(dragItem, getParent(dragItem), dropTIndex + 1);
                    }
                    else
                    {
                        int dragTIndex = indexOfChild(dragItem, getParent(dragItem));
                        if (dropTIndex < dragTIndex)
                        {
                            removeChild(dragItem, getParent(dragItem));
                            insertChild(dragItem, getParent(dragItem), dropTIndex + 1);
                        }
                        else
                        {
                            removeChild(dragItem, getParent(dragItem));
                            insertChild(dragItem, getParent(dragItem), dropTIndex);
                        }
                    }
                }
            }

            //Put drag items before drop target
            else if (e.Action == ItemDropAction.SetPrevSibling)
            {
                for (int i = 0; i < e.DragItems.Length; ++i)
                {
                    T dragItem = (T)e.DragItems[i];
                    if (getParent(dragItem) != getParent(dropTarget))
                    {
                        removeChild(dragItem, getParent(dragItem));
                        setParent(dragItem, getParent(dropTarget));
                        insertChild(dragItem, getParent(dragItem), 0);
                    }

                    int dropTIndex = indexOfChild(dropTarget, getParent(dropTarget));
                    int dragTIndex = indexOfChild(dragItem, getParent(dragItem));
                    if (dropTIndex > dragTIndex)
                    {
                        removeChild(dragItem, getParent(dragItem));
                        insertChild(dragItem, getParent(dragItem), dropTIndex - 1);
                    }
                    else
                    {
                        removeChild(dragItem, getParent(dragItem));
                        insertChild(dragItem, getParent(dragItem), dropTIndex);
                    }
                }
            }
        }