예제 #1
0
        public void AddElements(IList <T> elements, TreeElement parent, int insertPosition)
        {
            if (elements == null)
            {
                throw new ArgumentNullException("elements", "elements is null");
            }
            if (elements.Count == 0)
            {
                throw new ArgumentNullException("elements", "elements Count is 0: nothing to add");
            }
            if (parent == null)
            {
                throw new ArgumentNullException("parent", "parent is null");
            }

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

            parent.Children.InsertRange(insertPosition, elements.Cast <TreeElement> ());
            foreach (var element in elements)
            {
                element.Parent = parent;
                element.Depth  = parent.Depth + 1;
                TreeElementUtility.UpdateDepthValues(element);
            }

            TreeElementUtility.TreeToList(m_Root, m_Data);

            Changed();
        }
예제 #2
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();
        }
예제 #3
0
        public void AddElement(T element, TreeElement parent, int insertPosition)
        {
            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(insertPosition, element);
            element.Parent = parent;

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

            Changed();
        }