public void SetGroup(string groupName)
        {
            groups.Clear();
            selection.Clear();

            var allTreeViewSelection = new TreeItemIdentifier(groupName, TreeItemIdentifier.kAll);

            groups.Add(allTreeViewSelection.nameWithIndex);
        }
示例#2
0
        protected override TreeViewItem BuildRoot()
        {
            int          idForHiddenRoot    = -1;
            int          depthForHiddenRoot = -1;
            TreeViewItem root = new TreeViewItem(idForHiddenRoot, depthForHiddenRoot, "root");

            int depth = 0;

            var top = new SelectionWindowTreeViewItem(-1, depth, m_AllIdentifier.name, m_AllIdentifier);

            root.AddChild(top);

            var expandList = new List <int>()
            {
                -1
            };
            string       lastName = "";
            TreeViewItem node     = root;

            for (int index = 0; index < m_Names.Length; ++index)
            {
                var nameWithIndex = m_Names[index];
                if (nameWithIndex == m_AllIdentifier.nameWithIndex)
                {
                    continue;
                }

                var identifier = new TreeItemIdentifier(nameWithIndex);
                var item       = new SelectionWindowTreeViewItem(index, depth, m_Names[index], identifier);

                if (identifier.name != lastName)
                {
                    // New items at root
                    node  = top;
                    depth = 0;
                }

                node.AddChild(item);

                if (identifier.name != lastName)
                {
                    // Extra instances hang of the parent
                    lastName = identifier.name;
                    node     = item;
                    depth    = 1;
                }
            }

            SetExpanded(expandList);

            SetupDepthsFromParentsAndChildren(root);

            return(root);
        }
示例#3
0
        protected int GetChildCount(TreeItemIdentifier selectedIdentifier, out int selected)
        {
            var count         = 0;
            var selectedCount = 0;

            if (selectedIdentifier.index == TreeItemIdentifier.kAll)
            {
                if (selectedIdentifier.name == "All")
                {
                    for (var index = 0; index < m_Names.Length; ++index)
                    {
                        var nameWithIndex = m_Names[index];
                        var identifier    = new TreeItemIdentifier(nameWithIndex);

                        if (identifier.index != TreeItemIdentifier.kAll)
                        {
                            count++;
                            if (m_Selection.selection.Contains(nameWithIndex))
                            {
                                selectedCount++;
                            }
                        }
                    }
                }
                else
                {
                    for (var index = 0; index < m_Names.Length; ++index)
                    {
                        var nameWithIndex = m_Names[index];
                        var identifier    = new TreeItemIdentifier(nameWithIndex);

                        if (selectedIdentifier.name == identifier.name &&
                            identifier.index != TreeItemIdentifier.kAll)
                        {
                            count++;
                            if (m_Selection.selection.Contains(nameWithIndex))
                            {
                                selectedCount++;
                            }
                        }
                    }
                }
            }

            selected = selectedCount;
            return(count);
        }
        public void SetAll(string[] names)
        {
            groups.Clear();
            var allIdentifier = new TreeItemIdentifier("All", TreeItemIdentifier.kAll);

            groups.Add(allIdentifier.nameWithIndex);

            selection.Clear();
            foreach (var nameWithIndex in names)
            {
                if (nameWithIndex != allIdentifier.nameWithIndex)
                {
                    var identifier = new TreeItemIdentifier(nameWithIndex);
                    if (identifier.index != TreeItemIdentifier.kAll)
                    {
                        selection.Add(nameWithIndex);
                    }
                }
            }
        }
示例#5
0
        public MultiSelectionTable(TreeViewState state, MultiColumnHeader multicolumnHeader, string[] names, TreeViewSelection selection) : base(state, multicolumnHeader)
        {
            m_AllIdentifier = new TreeItemIdentifier();
            m_AllIdentifier.SetName("All");
            m_AllIdentifier.SetAll();

            Assert.AreEqual(m_SortOptions.Length, Enum.GetValues(typeof(MyColumns)).Length, "Ensure number of sort options are in sync with number of MyColumns enum values");

            // Custom setup
            rowHeight = kRowHeights;
            showAlternatingRowBackgrounds = true;
            showBorder           = true;
            customFoldoutYOffset = (kRowHeights - EditorGUIUtility.singleLineHeight) * 0.5f; // center foldout in the row since we also center content. See RowGUI
            // extraSpaceBeforeIconAndLabel = 0;
            multicolumnHeader.sortingChanged += OnSortingChanged;

            m_Names     = names;
            m_Selection = new TreeViewSelection(selection);
            Reload();
        }
示例#6
0
        private void CellGUI(Rect cellRect, SelectionWindowTreeViewItem item, MyColumns column, ref RowGUIArgs args)
        {
            // Center cell rect vertically (makes it easier to place controls, icons etc in the cells)
            CenterRectUsingSingleLineHeight(ref cellRect);

            switch (column)
            {
            case MyColumns.ItemName:
            {
                args.rowRect = cellRect;
                // base.RowGUI(args);    // Required to show tree indenting

                // Draw manually to keep indenting by add a tooltip
                var rect = cellRect;
                if (Event.current.rawType == EventType.Repaint)
                {
                    int selectedChildren;
                    var childCount = GetChildCount(item.TreeItemIdentifier, out selectedChildren);

                    string text;
                    string tooltip;
                    var    fullName  = item.TreeItemIdentifier.name;
                    var    groupName = GetItemGroupName(item);

                    if (childCount <= 1)
                    {
                        text    = item.displayName;
                        tooltip = groupName == "" ? text : string.Format("{0}\n{1}", text, groupName);
                    }
                    else if (selectedChildren != childCount)
                    {
                        text    = string.Format("{0} ({1} of {2})", fullName, selectedChildren, childCount);
                        tooltip = groupName == "" ? text : string.Format("{0}\n{1}", text, groupName);
                    }
                    else
                    {
                        text    = string.Format("{0} (All)", fullName);
                        tooltip = groupName == "" ? text : string.Format("{0}\n{1}", text, groupName);
                    }

                    var content = new GUIContent(text, tooltip);

                    if (m_ActiveLineStyle == null)
                    {
                        m_ActiveLineStyle = new GUIStyle(DefaultStyles.label);
                        m_ActiveLineStyle.normal.textColor = DefaultStyles.boldLabel.onActive.textColor;
                    }

                    // The rect is assumed indented and sized after the content when pinging
                    var indent = GetContentIndent(item) + extraSpaceBeforeIconAndLabel;
                    rect.xMin += indent;

                    var iconRectWidth            = 16;
                    var kSpaceBetweenIconAndText = 2;

                    // Draw icon
                    var iconRect = rect;
                    iconRect.width = iconRectWidth;
                    // iconRect.x += 7f;

                    Texture icon = args.item.icon;
                    if (icon != null)
                    {
                        GUI.DrawTexture(iconRect, icon, ScaleMode.ScaleToFit);
                    }

                    rect.xMin += icon == null ? 0 : iconRectWidth + kSpaceBetweenIconAndText;

                    //bool mouseOver = rect.Contains(Event.current.mousePosition);
                    //DefaultStyles.label.Draw(rect, content, mouseOver, false, args.selected, args.focused);

                    // Must use this call to draw tooltip
                    EditorGUI.LabelField(rect, content, args.selected ? m_ActiveLineStyle : DefaultStyles.label);
                }
            }
            break;

            case MyColumns.GroupName:
            {
                var groupName = GetItemGroupName(item);
                var content   = new GUIContent(groupName, groupName);
                EditorGUI.LabelField(cellRect, content);
            }
            break;

            case MyColumns.State:
                var oldState = TreeItemSelected(item.TreeItemIdentifier);
                var newState = EditorGUI.Toggle(cellRect, oldState);
                if (newState != oldState)
                {
                    if (item.TreeItemIdentifier.nameWithIndex == m_AllIdentifier.nameWithIndex)
                    {
                        // Record active groups
                        m_Selection.groups.Clear();
                        if (newState)
                        {
                            if (!m_Selection.groups.Contains(item.TreeItemIdentifier.nameWithIndex))
                            {
                                m_Selection.groups.Add(item.TreeItemIdentifier.nameWithIndex);
                            }
                        }

                        // Update selection
                        m_Selection.selection.Clear();
                        if (newState)
                        {
                            foreach (var nameWithIndex in m_Names)
                            {
                                if (nameWithIndex != m_AllIdentifier.nameWithIndex)
                                {
                                    var identifier = new TreeItemIdentifier(nameWithIndex);
                                    if (identifier.index != TreeItemIdentifier.kAll)
                                    {
                                        m_Selection.selection.Add(nameWithIndex);
                                    }
                                }
                            }
                        }
                    }
                    else if (item.TreeItemIdentifier.index == TreeItemIdentifier.kAll)
                    {
                        // Record active groups
                        if (newState)
                        {
                            if (!m_Selection.groups.Contains(item.TreeItemIdentifier.nameWithIndex))
                            {
                                m_Selection.groups.Add(item.TreeItemIdentifier.nameWithIndex);
                            }
                        }
                        else
                        {
                            m_Selection.groups.Remove(item.TreeItemIdentifier.nameWithIndex);
                            // When turning off a sub group, turn of the 'all' group too
                            m_Selection.groups.Remove(m_AllIdentifier.nameWithIndex);
                        }

                        // Update selection
                        if (newState)
                        {
                            foreach (var nameWithIndex in m_Names)
                            {
                                var identifier = new TreeItemIdentifier(nameWithIndex);
                                if (identifier.name == item.TreeItemIdentifier.name &&
                                    identifier.index != TreeItemIdentifier.kAll)
                                {
                                    if (!m_Selection.selection.Contains(nameWithIndex))
                                    {
                                        m_Selection.selection.Add(nameWithIndex);
                                    }
                                }
                            }
                        }
                        else
                        {
                            var removeSelection = new List <string>();
                            foreach (var nameWithIndex in m_Selection.selection)
                            {
                                var identifier = new TreeItemIdentifier(nameWithIndex);
                                if (identifier.name == item.TreeItemIdentifier.name &&
                                    identifier.index != TreeItemIdentifier.kAll)
                                {
                                    removeSelection.Add(nameWithIndex);
                                }
                            }

                            foreach (var nameWithIndex in removeSelection)
                            {
                                m_Selection.selection.Remove(nameWithIndex);
                            }
                        }
                    }
                    else
                    {
                        if (newState)
                        {
                            m_Selection.selection.Add(item.TreeItemIdentifier.nameWithIndex);
                        }
                        else
                        {
                            m_Selection.selection.Remove(item.TreeItemIdentifier.nameWithIndex);

                            // Turn off any group its in too
                            var groupIdentifier = new TreeItemIdentifier(item.TreeItemIdentifier);
                            groupIdentifier.SetAll();
                            m_Selection.groups.Remove(groupIdentifier.nameWithIndex);

                            // Turn of the 'all' group too
                            m_Selection.groups.Remove(m_AllIdentifier.nameWithIndex);
                        }
                    }
                }

                break;
            }
        }
示例#7
0
        private bool TreeItemSelected(TreeItemIdentifier selectedIdentifier)
        {
            if (m_Selection.selection != null &&
                m_Selection.selection.Count > 0 &&
                m_Selection.selection.Contains(selectedIdentifier.nameWithIndex))
            {
                return(true);
            }

            // If querying the 'All' filter then check if all selected
            if (selectedIdentifier.nameWithIndex == m_AllIdentifier.nameWithIndex)
            {
                // Check all items without All in the name are selected
                foreach (var nameWithIndex in m_Names)
                {
                    var identifier = new TreeItemIdentifier(nameWithIndex);
                    if (identifier.index ==
                        TreeItemIdentifier.kAll /* || identifier.index == TreeItemIdentifier.kSingle*/)
                    {
                        continue;
                    }

                    if (!m_Selection.selection.Contains(nameWithIndex))
                    {
                        return(false);
                    }
                }

                return(true);
            }

            // Need to check 'all' and item group all.
            if (selectedIdentifier.index == TreeItemIdentifier.kAll)
            {
                // Count all items that match this item group
                var count = 0;
                foreach (var nameWithIndex in m_Names)
                {
                    var identifier = new TreeItemIdentifier(nameWithIndex);
                    if (identifier.index == TreeItemIdentifier.kAll || identifier.index == TreeItemIdentifier.kSingle)
                    {
                        continue;
                    }

                    if (selectedIdentifier.name != identifier.name)
                    {
                        continue;
                    }

                    count++;
                }

                // Count all the items we have selected that match this item group
                var selectedCount = 0;
                foreach (var nameWithIndex in m_Selection.selection)
                {
                    var identifier = new TreeItemIdentifier(nameWithIndex);
                    if (selectedIdentifier.name != identifier.name)
                    {
                        continue;
                    }
                    if (identifier.index > count)
                    {
                        continue;
                    }

                    selectedCount++;
                }

                if (count == selectedCount)
                {
                    return(true);
                }
            }

            return(false);
        }
示例#8
0
 public TreeItemIdentifier(TreeItemIdentifier treeItemIdentifier)
 {
     name          = treeItemIdentifier.name;
     index         = treeItemIdentifier.index;
     nameWithIndex = treeItemIdentifier.nameWithIndex;
 }
示例#9
0
 public SelectionWindowTreeViewItem(int id, int depth, string displayName, TreeItemIdentifier treeItemIdentifier) : base(id, depth, displayName)
 {
     this.TreeItemIdentifier = treeItemIdentifier;
 }
        // SteveM TODO - This seems wildly more complex than it needs to be... UNLESS assemblies can have sub-assemblies?
        // If that's the case, we need to test for that. Otherwise we need to strip a bunch of this complexity out.
        private string GetSelectedSummary(TreeViewSelection selection, string[] names)
        {
            if (selection.selection == null || selection.selection.Count == 0)
            {
                return("None");
            }

            // Count all items in a group
            var dict          = new Dictionary <string, int>();
            var selectionDict = new Dictionary <string, int>();

            foreach (var nameWithIndex in names)
            {
                var identifier = new TreeItemIdentifier(nameWithIndex);
                if (identifier.index == TreeItemIdentifier.kAll)
                {
                    continue;
                }

                int count;
                if (dict.TryGetValue(identifier.name, out count))
                {
                    dict[identifier.name] = count + 1;
                }
                else
                {
                    dict[identifier.name] = 1;
                }

                selectionDict[identifier.name] = 0;
            }

            // Count all the items we have 'selected' in a group
            foreach (var nameWithIndex in selection.selection)
            {
                var identifier = new TreeItemIdentifier(nameWithIndex);

                if (dict.ContainsKey(identifier.name) &&
                    selectionDict.ContainsKey(identifier.name) &&
                    identifier.index <= dict[identifier.name])
                {
                    // Selected assembly valid and in the assembly list
                    // and also within the range of valid assemblies for this data set
                    selectionDict[identifier.name]++;
                }
            }

            // Count all groups where we have 'selected all the items'
            var selectedCount = 0;

            foreach (var name in dict.Keys)
            {
                if (selectionDict[name] != dict[name])
                {
                    continue;
                }

                selectedCount++;
            }

            // If we've just added all the item names we have everything selected
            // Note we don't compare against the names array directly as this contains the 'all' versions
            if (selectedCount == dict.Keys.Count)
            {
                return("All");
            }

            // Add all the individual items were we haven't already added the group
            var individualItems = new List <string>();

            foreach (var name in selectionDict.Keys)
            {
                var selectionCount = selectionDict[name];
                if (selectionCount <= 0)
                {
                    continue;
                }
                var itemCount = dict[name];
                if (itemCount == 1)
                {
                    individualItems.Add(name);
                }
                else if (selectionCount != itemCount)
                {
                    individualItems.Add(string.Format("{0} ({1} of {2})", name, selectionCount, itemCount));
                }
                else
                {
                    individualItems.Add(string.Format("{0} (All)", name));
                }
            }

            // Maintain alphabetical order
            individualItems.Sort(CompareUINames);

            if (individualItems.Count == 0)
            {
                return("None");
            }

            return(string.Join(", ", individualItems.ToArray()));
        }