private void OnItemDrop(object sender, ItemDropArgs args)
 {
     if (args.DropTarget == null)
     {
         return;
     }
     this.TreeView.ItemDropStdHandler <DataItem>(args, (Func <DataItem, DataItem>)(item => item.Parent), (Action <DataItem, DataItem>)((item, parent) => item.Parent = parent), (Func <DataItem, DataItem, int>)((item, parent) => this.ChildrenOf(parent).IndexOf(item)), (Action <DataItem, DataItem>)((item, parent) => this.ChildrenOf(parent).Remove(item)), (Action <DataItem, DataItem, int>)((item, parent, i) => this.ChildrenOf(parent).Insert(i, item)));
 }
        private void OnItemDrop(object sender, ItemDropArgs args)
        {
            if (args.DropTarget == null)
            {
                return;
            }

            TreeView.ItemDropStdHandler <DataItem>(args,
                                                   (item) => item.Parent,
                                                   (item, parent) => item.Parent = parent,
                                                   (item, parent) => ChildrenOf(parent).IndexOf(item),
                                                   (item, parent) => ChildrenOf(parent).Remove(item),
                                                   (item, parent, i) => ChildrenOf(parent).Insert(i, item));
        }
        private void OnItemDrop(object sender, ItemDropArgs e)
        {
            Transform transform1 = ((GameObject)e.DropTarget).get_transform();

            if (e.Action == ItemDropAction.SetLastChild)
            {
                for (int index = 0; index < e.DragItems.Length; ++index)
                {
                    Transform transform2 = ((GameObject)e.DragItems[index]).get_transform();
                    transform2.SetParent(transform1, true);
                    transform2.SetAsLastSibling();
                }
            }
            else if (e.Action == ItemDropAction.SetNextSibling)
            {
                for (int index = 0; index < e.DragItems.Length; ++index)
                {
                    Transform transform2 = ((GameObject)e.DragItems[index]).get_transform();
                    if (Object.op_Inequality((Object)transform2.get_parent(), (Object)transform1.get_parent()))
                    {
                        transform2.SetParent(transform1.get_parent(), true);
                    }
                    int siblingIndex = transform1.GetSiblingIndex();
                    transform2.SetSiblingIndex(siblingIndex + 1);
                }
            }
            else
            {
                if (e.Action != ItemDropAction.SetPrevSibling)
                {
                    return;
                }
                for (int index = 0; index < e.DragItems.Length; ++index)
                {
                    Transform transform2 = ((GameObject)e.DragItems[index]).get_transform();
                    if (Object.op_Inequality((Object)transform2.get_parent(), (Object)transform1.get_parent()))
                    {
                        transform2.SetParent(transform1.get_parent(), true);
                    }
                    int siblingIndex = transform1.GetSiblingIndex();
                    transform2.SetSiblingIndex(siblingIndex);
                }
            }
        }
        private void OnItemDrop(object sender, ItemDropArgs e)
        {
            Transform dropT = ((GameObject)e.DropTarget).transform;

            if (e.Action == ItemDropAction.SetLastChild)
            {
                for (int i = 0; i < e.DragItems.Length; ++i)
                {
                    Transform dragT = ((GameObject)e.DragItems[i]).transform;
                    dragT.SetParent(dropT, true);
                    dragT.SetAsLastSibling();
                }
            }
            else if (e.Action == ItemDropAction.SetNextSibling)
            {
                for (int i = 0; i < e.DragItems.Length; ++i)
                {
                    Transform dragT = ((GameObject)e.DragItems[i]).transform;
                    if (dragT.parent != dropT.parent)
                    {
                        dragT.SetParent(dropT.parent, true);
                    }

                    int siblingIndex = dropT.GetSiblingIndex();
                    dragT.SetSiblingIndex(siblingIndex + 1);
                }
            }
            else if (e.Action == ItemDropAction.SetPrevSibling)
            {
                for (int i = 0; i < e.DragItems.Length; ++i)
                {
                    Transform dragT = ((GameObject)e.DragItems[i]).transform;
                    if (dragT.parent != dropT.parent)
                    {
                        dragT.SetParent(dropT.parent, true);
                    }

                    int siblingIndex = dropT.GetSiblingIndex();
                    dragT.SetSiblingIndex(siblingIndex);
                }
            }
        }
Beispiel #5
0
        private void OnItemDrop(object sender, ItemDropArgs e)
        {
            if (e.DropTarget == null)
            {
                return;
            }

            DataItem dropT = ((DataItem)e.DropTarget);

            //Set drag items as children of drop target
            if (e.Action == ItemDropAction.SetLastChild)
            {
                for (int i = 0; i < e.DragItems.Length; ++i)
                {
                    DataItem dragT = ((DataItem)e.DragItems[i]);
                    if (dragT.Parent != null)
                    {
                        dragT.Parent.Children.Remove(dragT);
                    }
                    else
                    {
                        m_dataItems.Remove(dragT);
                    }
                    dragT.Parent = dropT;
                    dragT.Parent.Children.Add(dragT);
                }
            }

            //Put drag items next to drop target
            else if (e.Action == ItemDropAction.SetNextSibling)
            {
                for (int i = e.DragItems.Length - 1; i >= 0; --i)
                {
                    DataItem dragT      = ((DataItem)e.DragItems[i]);
                    int      dropTIndex = dropT.Parent != null?dropT.Parent.Children.IndexOf(dropT) : m_dataItems.IndexOf(dropT);

                    if (dragT.Parent != dropT.Parent)
                    {
                        if (dragT.Parent != null)
                        {
                            dragT.Parent.Children.Remove(dragT);
                        }
                        else
                        {
                            m_dataItems.Remove(dragT);
                        }
                        dragT.Parent = dropT;
                        dragT.Parent.Children.Insert(dropTIndex + 1, dragT);
                    }
                    else
                    {
                        int dragTIndex = dragT.Parent != null?dragT.Parent.Children.IndexOf(dragT) : m_dataItems.IndexOf(dragT);

                        if (dropTIndex < dragTIndex)
                        {
                            if (dragT.Parent != null)
                            {
                                dragT.Parent.Children.Remove(dragT);
                                dragT.Parent.Children.Insert(dropTIndex + 1, dragT);
                            }
                            else
                            {
                                m_dataItems.Remove(dragT);
                                m_dataItems.Insert(dropTIndex + 1, dragT);
                            }
                        }
                        else
                        {
                            if (dragT.Parent != null)
                            {
                                dragT.Parent.Children.Remove(dragT);
                                dragT.Parent.Children.Insert(dropTIndex, dragT);
                            }
                            else
                            {
                                m_dataItems.Remove(dragT);
                                m_dataItems.Insert(dropTIndex, dragT);
                            }
                        }
                    }
                }
            }

            //Put drag items before drop target
            else if (e.Action == ItemDropAction.SetPrevSibling)
            {
                for (int i = 0; i < e.DragItems.Length; ++i)
                {
                    DataItem dragT = ((DataItem)e.DragItems[i]);
                    if (dragT.Parent != dropT.Parent)
                    {
                        if (dragT.Parent != null)
                        {
                            dragT.Parent.Children.Remove(dragT);
                        }
                        else
                        {
                            m_dataItems.Remove(dragT);
                        }
                        dragT.Parent = dropT.Parent;
                        dragT.Parent.Children.Add(dragT);
                    }

                    int dropTIndex = dropT.Parent != null?dropT.Parent.Children.IndexOf(dropT) : m_dataItems.IndexOf(dropT);

                    int dragTIndex = dragT.Parent != null?dragT.Parent.Children.IndexOf(dragT) : m_dataItems.IndexOf(dragT);

                    if (dropTIndex > dragTIndex)
                    {
                        if (dragT.Parent != null)
                        {
                            dragT.Parent.Children.Remove(dragT);
                            dragT.Parent.Children.Insert(dropTIndex - 1, dragT);
                        }
                        else
                        {
                            m_dataItems.Remove(dragT);
                            m_dataItems.Insert(dropTIndex - 1, dragT);
                        }
                    }
                    else
                    {
                        if (dragT.Parent != null)
                        {
                            dragT.Parent.Children.Remove(dragT);
                            dragT.Parent.Children.Insert(dropTIndex - 1, dragT);
                        }
                        else
                        {
                            m_dataItems.Remove(dragT);
                            m_dataItems.Insert(dropTIndex, dragT);
                        }
                    }
                }
            }
        }
        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);
                    }
                }
            }
        }
        private void OnItemDrop(object sender, ItemDropArgs e)
        {
            if (e.DropTarget == null)
            {
                return;
            }

            Transform dropT = ((GameObject)e.DropTarget).transform;

            //Set drag items as children of drop target
            if (e.Action == ItemDropAction.SetLastChild)
            {
                for (int i = 0; i < e.DragItems.Length; ++i)
                {
                    Transform dragT = ((GameObject)e.DragItems[i]).transform;
                    dragT.SetParent(dropT, true);
                    dragT.SetAsLastSibling();
                }
            }

            //Put drag items next to drop target
            else if (e.Action == ItemDropAction.SetNextSibling)
            {
                for (int i = e.DragItems.Length - 1; i >= 0; --i)
                {
                    Transform dragT      = ((GameObject)e.DragItems[i]).transform;
                    int       dropTIndex = dropT.GetSiblingIndex();
                    if (dragT.parent != dropT.parent)
                    {
                        dragT.SetParent(dropT.parent, true);
                        dragT.SetSiblingIndex(dropTIndex + 1);
                    }
                    else
                    {
                        int dragTIndex = dragT.GetSiblingIndex();
                        if (dropTIndex < dragTIndex)
                        {
                            dragT.SetSiblingIndex(dropTIndex + 1);
                        }
                        else
                        {
                            dragT.SetSiblingIndex(dropTIndex);
                        }
                    }
                }
            }

            //Put drag items before drop target
            else if (e.Action == ItemDropAction.SetPrevSibling)
            {
                for (int i = 0; i < e.DragItems.Length; ++i)
                {
                    Transform dragT = ((GameObject)e.DragItems[i]).transform;
                    if (dragT.parent != dropT.parent)
                    {
                        dragT.SetParent(dropT.parent, true);
                    }

                    int dropTIndex = dropT.GetSiblingIndex();
                    int dragTIndex = dragT.GetSiblingIndex();
                    if (dropTIndex > dragTIndex)
                    {
                        dragT.SetSiblingIndex(dropTIndex - 1);
                    }
                    else
                    {
                        dragT.SetSiblingIndex(dropTIndex);
                    }
                }
            }
        }
        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);
                    }
                }
            }
        }