예제 #1
0
        public void MoveElements(TreeElement parentElement, int insertionIndex, List <TreeElement> elements)
        {
            if (insertionIndex < 0)
            {
                throw new ArgumentException("Invalid input: insertionIndex is -1, client needs to decide what index elements should be reparented at");
            }

            // Invalid reparenting input
            if (parentElement == null)
            {
                return;
            }

            // We are moving items so we adjust the insertion index to accomodate that any items above the insertion index is removed before inserting
            if (insertionIndex > 0)
            {
                insertionIndex -= parentElement.children.GetRange(0, insertionIndex).Count(elements.Contains);
            }

            // Remove draggedItems from their parents
            foreach (var draggedItem in elements)
            {
                draggedItem.parent.children.Remove(draggedItem);                        // remove from old parent
                draggedItem.parent = parentElement;                                     // set new parent
            }

            if (parentElement.children == null)
            {
                parentElement.children = new List <TreeElement>();
            }

            // Insert dragged items under new parent
            parentElement.children.InsertRange(insertionIndex, elements);

            TreeElementUtility.UpdateDepthValues(root);
            TreeElementUtility.TreeToList(m_Root, m_Data);

            Changed();
        }
예제 #2
0
        IList <int> GetParentsBelowStackBased(TreeElement searchFromThis)
        {
            Stack <TreeElement> stack = new Stack <TreeElement>();

            stack.Push(searchFromThis);

            var parentsBelow = new List <int>();

            while (stack.Count > 0)
            {
                TreeElement current = stack.Pop();
                if (current.hasChildren)
                {
                    parentsBelow.Add(current.id);
                    foreach (var T in current.children)
                    {
                        stack.Push(T);
                    }
                }
            }

            return(parentsBelow);
        }
예제 #3
0
        public void AddElement(T element, TreeElement parent, int insertIndex)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element", "element is null");
            }
            if (parent == null)
            {
                throw new ArgumentNullException("parent", "parent is null");
            }

            if (parent.children == null)
            {
                parent.children = new List <TreeElement> ();
            }

            parent.children.Insert(insertIndex, element);
            element.parent = parent;

            TreeElementUtility.UpdateDepthValues(parent);
            TreeElementUtility.TreeToList(m_Root, m_Data);

            Changed();
        }