protected override AdvancedDropdownItem FetchData() { var rootGroup = new AdvancedDropdownItem(m_Label, -1); 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, menuPath, i); element.searchable = true; element.SetParent(parent); parent.AddChild(element); if (i == m_SelectedIndex) { 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)) { 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 List <AdvancedDropdownItem>(); var matchesWithin = new List <AdvancedDropdownItem>(); foreach (var e in m_MainTree.GetSearchableElements()) { var name = e.name.ToLower().Replace(" ", ""); var didMatchAll = true; var didMatchStart = false; // See if we match ALL the seaarch words. for (var w = 0; w < searchWords.Length; w++) { var search = searchWords[w]; if (name.Contains(search)) { // If the start of the item matches the first search word, make a note of that. if (w == 0 && name.StartsWith(search)) { didMatchStart = true; } } else { // As soon as any word is not matched, we disregard this item. didMatchAll = false; break; } } // We always need to match all search words. // If we ALSO matched the start, this item gets priority. if (didMatchAll) { if (didMatchStart) { matchesStart.Add(e); } else { matchesWithin.Add(e); } } } matchesStart.Sort(); matchesWithin.Sort(); var searchTree = new AdvancedDropdownItem(kSearchHeader, -1); foreach (var element in matchesStart) { searchTree.AddChild(element); } foreach (var element in matchesWithin) { searchTree.AddChild(element); } return(searchTree); }