Пример #1
0
        internal static void SetChildParentReferences(IList <TreeViewItem> visibleItems, TreeViewItem root)
        {
            for (int i = 0; i < visibleItems.Count; i++)
            {
                visibleItems[i].parent = null;
            }
            int num = 0;

            for (int j = 0; j < visibleItems.Count; j++)
            {
                TreeViewUtility.SetChildParentReferences(j, visibleItems);
                if (visibleItems[j].parent == null)
                {
                    num++;
                }
            }
            if (num > 0)
            {
                List <TreeViewItem> list = new List <TreeViewItem>(num);
                for (int k = 0; k < visibleItems.Count; k++)
                {
                    if (visibleItems[k].parent == null)
                    {
                        list.Add(visibleItems[k]);
                        visibleItems[k].parent = root;
                    }
                }
                root.children = list;
            }
        }
Пример #2
0
        private static TreeViewItem FindItemRecursive(int id, TreeViewItem item)
        {
            TreeViewItem result;

            if (item == null)
            {
                result = null;
            }
            else if (item.id == id)
            {
                result = item;
            }
            else if (!item.hasChildren)
            {
                result = null;
            }
            else
            {
                foreach (TreeViewItem current in item.children)
                {
                    TreeViewItem treeViewItem = TreeViewUtility.FindItemRecursive(id, current);
                    if (treeViewItem != null)
                    {
                        result = treeViewItem;
                        return(result);
                    }
                }
                result = null;
            }
            return(result);
        }
Пример #3
0
        virtual public void SetExpandedWithChildren(TreeViewItem fromItem, bool expand)
        {
            if (fromItem == null)
            {
                Debug.LogError("item is null");
                return;
            }

            HashSet <int> parents = new HashSet <int>();

            TreeViewUtility.GetParentsBelowItem(fromItem, parents);

            // Get existing expanded in hashset
            HashSet <int> oldExpandedSet = new HashSet <int>(expandedIDs);

            if (expand)
            {
                oldExpandedSet.UnionWith(parents);
            }
            else
            {
                oldExpandedSet.ExceptWith(parents);
            }

            // Bulk set expanded ids (is sorted in SetExpandedIDs)
            SetExpandedIDs(oldExpandedSet.ToArray());
        }
Пример #4
0
        void FinalizeDragPerformed(bool revertExpanded)
        {
            DragCleanup(revertExpanded);
            DragAndDrop.AcceptDrag();

            List <Object> objs = new List <Object>(DragAndDrop.objectReferences); // TODO, what about when dragging non objects...

            bool draggedItemsFromOwnTreeView = true;

            if (objs.Count > 0 && objs[0] != null && TreeViewUtility.FindItemInList(objs[0].GetInstanceID(), m_TreeView.data.GetRows()) == null)
            {
                draggedItemsFromOwnTreeView = false;
            }

            int[] newSelection = new int[objs.Count];
            for (int i = 0; i < objs.Count; ++i)
            {
                if (objs[i] == null)
                {
                    continue;
                }

                newSelection[i] = (objs[i].GetInstanceID());
            }
            m_TreeView.NotifyListenersThatDragEnded(newSelection, draggedItemsFromOwnTreeView);
            Undo.SetCurrentGroupName(Constants.UndoActionName);
        }
Пример #5
0
        // Used to reveal an item
        protected virtual IList <int> GetAncestors(int id)
        {
            // Default behavior assumes complete tree
            HashSet <int> parentsAbove = new HashSet <int>();

            TreeViewUtility.GetParentsAboveItem(FindItem(id), parentsAbove);
            return(parentsAbove.ToArray());
        }
Пример #6
0
        // Used to expand children recursively below an item
        protected virtual IList <int> GetDescendantsThatHaveChildren(int id)
        {
            // Default behavior assumes complete tree
            HashSet <int> parentsBelow = new HashSet <int>();

            TreeViewUtility.GetParentsBelowItem(FindItem(id), parentsBelow);
            return(parentsBelow.ToArray());
        }
Пример #7
0
 private static void GetExpandedRowsRecursive(TreeView treeView, TreeViewItem item, IList <TreeViewItem> expandedRows)
 {
     expandedRows.Add(item);
     if (item.hasChildren && treeView.IsExpanded(item.id))
     {
         foreach (TreeViewItem current in item.children)
         {
             TreeViewUtility.GetExpandedRowsRecursive(treeView, current, expandedRows);
         }
     }
 }
Пример #8
0
 internal static void DebugPrintToEditorLogRecursive(TreeViewItem item)
 {
     if (item != null)
     {
         Console.WriteLine(new string(' ', item.depth * 3) + item.displayName);
         if (item.hasChildren)
         {
             foreach (TreeViewItem current in item.children)
             {
                 TreeViewUtility.DebugPrintToEditorLogRecursive(current);
             }
         }
     }
 }
Пример #9
0
        private TreeViewItem FindItem(int id)
        {
            if (this.rootItem == null)
            {
                throw new InvalidOperationException("FindItem failed: root item has not been created yet");
            }
            TreeViewItem treeViewItem = TreeViewUtility.FindItem(id, this.rootItem);

            if (treeViewItem == null)
            {
                throw new ArgumentException(string.Format("Could not find item with id: {0}. FindItem assumes complete tree is built.", id));
            }
            return(treeViewItem);
        }
Пример #10
0
        TreeViewItem FindItem(int id)
        {
            if (rootItem == null)
            {
                throw new InvalidOperationException("FindItem failed: root item has not been created yet");
            }

            var item = TreeViewUtility.FindItem(id, rootItem);

            if (item == null)
            {
                throw new ArgumentException(string.Format("Could not find item with id: {0}. FindItem assumes complete tree is built. Most likely the item is not allocated because it is hidden under a collapsed item. Check if GetAncestors are overriden for the tree view.", id));
            }
            return(item);
        }
Пример #11
0
        private static void SetChildParentReferences(int parentIndex, IList <TreeViewItem> visibleItems)
        {
            TreeViewItem treeViewItem = visibleItems[parentIndex];
            bool         flag         = treeViewItem.children != null && treeViewItem.children.Count > 0 && treeViewItem.children[0] != null;

            if (!flag)
            {
                int depth = treeViewItem.depth;
                int num   = 0;
                for (int i = parentIndex + 1; i < visibleItems.Count; i++)
                {
                    if (visibleItems[i].depth == depth + 1)
                    {
                        num++;
                    }
                    if (visibleItems[i].depth <= depth)
                    {
                        break;
                    }
                }
                List <TreeViewItem> list = null;
                if (num != 0)
                {
                    list = new List <TreeViewItem>(num);
                    num  = 0;
                    for (int j = parentIndex + 1; j < visibleItems.Count; j++)
                    {
                        if (visibleItems[j].depth == depth + 1)
                        {
                            visibleItems[j].parent = treeViewItem;
                            list.Add(visibleItems[j]);
                            num++;
                        }
                        if (visibleItems[j].depth <= depth)
                        {
                            break;
                        }
                    }
                }
                TreeViewUtility.SetChildren(treeViewItem, list);
            }
        }
Пример #12
0
 public virtual void SetExpandedWithChildren(TreeViewItem fromItem, bool expand)
 {
     if (fromItem == null)
     {
         Debug.LogError("item is null");
     }
     else
     {
         HashSet <int> parentsBelowItem = TreeViewUtility.GetParentsBelowItem(fromItem);
         HashSet <int> hashSet          = new HashSet <int>(this.expandedIDs);
         if (expand)
         {
             hashSet.UnionWith(parentsBelowItem);
         }
         else
         {
             hashSet.ExceptWith(parentsBelowItem);
         }
         this.SetExpandedIDs(hashSet.ToArray <int>());
     }
 }
Пример #13
0
        private void FinalizeDragPerformed(bool revertExpanded)
        {
            this.DragCleanup(revertExpanded);
            DragAndDrop.AcceptDrag();
            List <UnityEngine.Object> list   = new List <UnityEngine.Object>(DragAndDrop.objectReferences);
            bool draggedItemsFromOwnTreeView = true;

            if (list.Count > 0 && list[0] != null && TreeViewUtility.FindItemInList <TreeViewItem>(list[0].GetInstanceID(), this.m_TreeView.data.GetRows()) == null)
            {
                draggedItemsFromOwnTreeView = false;
            }
            int[] array = new int[list.Count];
            for (int i = 0; i < list.Count; i++)
            {
                if (!(list[i] == null))
                {
                    array[i] = list[i].GetInstanceID();
                }
            }
            this.m_TreeView.NotifyListenersThatDragEnded(array, draggedItemsFromOwnTreeView);
        }
Пример #14
0
 public static void BuildRowsUsingExpandedState(IList <TreeViewItem> rows, TreeViewItem root, TreeView treeView)
 {
     if (treeView == null)
     {
         throw new ArgumentNullException("treeView", "treeView is null");
     }
     if (root == null)
     {
         throw new ArgumentNullException("root", "root is null");
     }
     if (rows == null)
     {
         throw new ArgumentNullException("rows", "rows is null");
     }
     if (root.hasChildren)
     {
         foreach (TreeViewItem current in root.children)
         {
             TreeViewUtility.GetExpandedRowsRecursive(treeView, current, rows);
         }
     }
 }
Пример #15
0
 internal static TreeViewItem FindItem(int id, TreeViewItem searchFromThisItem)
 {
     return(TreeViewUtility.FindItemRecursive(id, searchFromThisItem));
 }
Пример #16
0
 protected static void SetupDepthsFromParentsAndChildren(TreeViewItem root)
 {
     TreeViewUtility.SetDepthValuesForItems(root);
 }
Пример #17
0
 protected static void SetupParentsAndChildrenFromDepths(TreeViewItem root, IList <TreeViewItem> rows)
 {
     TreeViewUtility.SetChildParentReferences(rows, root);
 }
Пример #18
0
 virtual public TreeViewItem FindItem(int id)
 {
     return(TreeViewUtility.FindItem(id, m_RootItem));
 }
Пример #19
0
 public virtual TreeViewItem FindItem(int id)
 {
     return(TreeViewUtility.FindItem(id, this.m_RootItem));
 }
Пример #20
0
 // Used to reveal an item
 protected virtual IList <int> GetAncestors(int id)
 {
     // Default behavior assumes complete tree
     return(TreeViewUtility.GetParentsAboveItem(FindItem(id)).ToList());
 }
Пример #21
0
 protected TreeViewItem FindItem(int id, TreeViewItem searchFromThisItem)
 {
     return(TreeViewUtility.FindItem(id, searchFromThisItem));
 }
Пример #22
0
 // Used to expand children recursively below an item
 protected virtual IList <int> GetDescendantsThatHaveChildren(int id)
 {
     // Default behavior assumes complete tree
     return(TreeViewUtility.GetParentsBelowItem(FindItem(id)).ToList());
 }
Пример #23
0
 protected virtual IList <int> GetDescendantsThatHaveChildren(int id)
 {
     return(TreeViewUtility.GetParentsBelowItem(this.FindItem(id)).ToList <int>());
 }
Пример #24
0
 protected virtual IList <int> GetAncestors(int id)
 {
     return(TreeViewUtility.GetParentsAboveItem(this.FindItem(id)).ToList <int>());
 }
Пример #25
0
 public static void SetParentAndChildrenForItems(IList <TreeViewItem> rows, TreeViewItem root)
 {
     TreeViewUtility.SetChildParentReferences(rows, root);
 }