protected override AdvancedDropdownItem FetchData()
        {
            var rootGroup = new AdvancedDropdownItem(m_Label, -1);

            m_SearchableElements = new List <AdvancedDropdownItem>();

            for (int i = 0; i < m_DisplayedOptions.Length; i++)
            {
                var menuPath = m_DisplayedOptions[i];
                var paths    = menuPath.Split('/');

                AdvancedDropdownItem parent = rootGroup;
                for (var j = 0; j < paths.Length; j++)
                {
                    var path = paths[j];
                    if (j == paths.Length - 1)
                    {
                        var element = new AdvancedDropdownItem(path, path, menuPath, i);
                        element.SetParent(parent);
                        parent.AddChild(element);
                        m_SearchableElements.Add(element);

                        if (i == m_SelectedIndex)
                        {
                            selectedIds.Add(element.id);
                            var tempParent = parent;
                            AdvancedDropdownItem searchedItem = element;
                            while (tempParent != null)
                            {
                                tempParent.selectedItem = tempParent.children.IndexOf(searchedItem);
                                searchedItem            = tempParent;
                                tempParent = tempParent.parent;
                            }
                        }
                        continue;
                    }

                    var groupPathId = "";
                    for (int k = 0; k <= j; k++)
                    {
                        groupPathId += paths[k] + ".";
                    }

                    var group = parent.children.SingleOrDefault(c => c.id == groupPathId);
                    if (group == null)
                    {
                        group = new AdvancedDropdownItem(path, groupPathId, -1);
                        group.SetParent(parent);
                        parent.AddChild(group);
                    }
                    parent = group;
                }
            }
            return(rootGroup);
        }
        virtual protected AdvancedDropdownItem Search(string searchString)
        {
            if (string.IsNullOrEmpty(searchString) || m_SearchableElements == null)
            {
                return(null);
            }

            // Support multiple search words separated by spaces.
            var searchWords = searchString.ToLower().Split(' ');

            // We keep two lists. Matches that matches the start of an item always get first priority.
            var matchesStart  = new SortedList <string, AdvancedDropdownItem>();
            var matchesWithin = new SortedList <string, AdvancedDropdownItem>();

            bool found = false;

            foreach (var e in m_SearchableElements)
            {
                var name = e.searchableName.ToLower().Replace(" ", "");
                if (AddMatchItem(e, name, searchWords, matchesStart, matchesWithin))
                {
                    found = true;
                }
            }
            if (!found)
            {
                foreach (var e in m_SearchableElements)
                {
                    var name = e.searchableNameLocalized.Replace(" ", "");
                    AddMatchItem(e, name, searchWords, matchesStart, matchesWithin);
                }
            }

            var searchTree = new AdvancedDropdownItem(kSearchHeader, kSearchHeaderLocalized, -1);

            foreach (var element in matchesStart)
            {
                searchTree.AddChild(element.Value);
            }
            foreach (var element in matchesWithin)
            {
                searchTree.AddChild(element.Value);
            }
            return(searchTree);
        }
Beispiel #3
0
        protected override AdvancedDropdownItem FetchData()
        {
            var rootGroup = new AdvancedDropdownItem(string.Empty, -1);

            for (var i = 0; i < m_OptionNames.Length; i++)
            {
                if (i == 2)
                {
                    rootGroup.AddSeparator();
                }
                var element = new AdvancedDropdownItem(m_OptionNames[i], i);
                element.SetParent(rootGroup);
                rootGroup.AddChild(element);
            }

            RebuildSelection();
            return(rootGroup);
        }
        protected override AdvancedDropdownItem FetchData()
        {
            selectedIds.Clear();
            var rootGroup = new AdvancedDropdownItem("", -1);

            for (int i = 0; i < m_DisplayedOptions.Length; i++)
            {
                var option = m_DisplayedOptions[i];

                var element = new AdvancedDropdownItem(option, i);
                element.SetParent(rootGroup);
                rootGroup.AddChild(element);

                if (i == m_SelectedIndex)
                {
                    selectedIds.Add(element.id);
                    rootGroup.selectedItem = i;
                }
            }
            return(rootGroup);
        }