File size: 1,392 Bytes
18a519f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#if UNITY_EDITOR
using System;
using UnityEditor.IMGUI.Controls;

namespace UnityEngine.InputSystem.Editor
{
    /// <summary>
    /// Extension methods for working with tree views.
    /// </summary>
    /// <seealso cref="TreeView"/>
    internal static class TreeViewHelpers
    {
        public static TItem TryFindItemInHierarchy<TItem>(this TreeViewItem item)
            where TItem : TreeViewItem
        {
            while (item != null)
            {
                if (item is TItem result)
                    return result;
                item = item.parent;
            }

            return null;
        }

        public static bool IsParentOf(this TreeViewItem parent, TreeViewItem child)
        {
            if (parent == null)
                throw new ArgumentNullException(nameof(parent));
            if (child == null)
                throw new ArgumentNullException(nameof(child));

            do
            {
                child = child.parent;
            }
            while (child != null && child != parent);
            return child != null;
        }

        public static void ExpandChildren(this TreeView treeView, TreeViewItem item)
        {
            if (!item.hasChildren)
                return;

            foreach (var child in item.children)
                treeView.SetExpanded(child.id, true);
        }
    }
}
#endif // UNITY_EDITOR