Exemplo n.º 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;
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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());
        }
Exemplo n.º 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);
        }
Exemplo n.º 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());
        }
Exemplo n.º 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());
        }
Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 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);
             }
         }
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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>());
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 15
0
 internal static TreeViewItem FindItem(int id, TreeViewItem searchFromThisItem)
 {
     return(TreeViewUtility.FindItemRecursive(id, searchFromThisItem));
 }
Exemplo n.º 16
0
 protected static void SetupDepthsFromParentsAndChildren(TreeViewItem root)
 {
     TreeViewUtility.SetDepthValuesForItems(root);
 }
Exemplo n.º 17
0
 protected static void SetupParentsAndChildrenFromDepths(TreeViewItem root, IList <TreeViewItem> rows)
 {
     TreeViewUtility.SetChildParentReferences(rows, root);
 }
Exemplo n.º 18
0
 virtual public TreeViewItem FindItem(int id)
 {
     return(TreeViewUtility.FindItem(id, m_RootItem));
 }
Exemplo n.º 19
0
 public virtual TreeViewItem FindItem(int id)
 {
     return(TreeViewUtility.FindItem(id, this.m_RootItem));
 }
Exemplo n.º 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());
 }
Exemplo n.º 21
0
 protected TreeViewItem FindItem(int id, TreeViewItem searchFromThisItem)
 {
     return(TreeViewUtility.FindItem(id, searchFromThisItem));
 }
Exemplo n.º 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());
 }
Exemplo n.º 23
0
 protected virtual IList <int> GetDescendantsThatHaveChildren(int id)
 {
     return(TreeViewUtility.GetParentsBelowItem(this.FindItem(id)).ToList <int>());
 }
Exemplo n.º 24
0
 protected virtual IList <int> GetAncestors(int id)
 {
     return(TreeViewUtility.GetParentsAboveItem(this.FindItem(id)).ToList <int>());
 }
Exemplo n.º 25
0
 public static void SetParentAndChildrenForItems(IList <TreeViewItem> rows, TreeViewItem root)
 {
     TreeViewUtility.SetChildParentReferences(rows, root);
 }