protected void AddItemToIndex(SearcherItem item, ref int lastId, Action <SearcherItem> action) { m_ItemList.Insert(lastId, item); // We can only set the id here as we only know the final index of the item here. item.OverwriteId(lastId); item.GeneratePath(); action?.Invoke(item); lastId++; // This is used for sorting results between databases. item.OverwriteDatabase(this); if (!item.HasChildren) { return; } var childrenIds = new List <int>(); foreach (SearcherItem child in item.Children) { AddItemToIndex(child, ref lastId, action); childrenIds.Add(child.Id); } item.OverwriteChildrenIds(childrenIds); }
void Expand(SearcherItem item) { m_ExpandedResults.Add(item); RegenerateVisibleResults(); HideUnexpandedItems(); m_ListView.Refresh(); }
public virtual VisualElement Bind(VisualElement element, SearcherItem item, ItemExpanderState expanderState, string query) { var indent = element.Q <VisualElement>("itemIndent"); indent.style.width = item.Depth * k_IndentDepthFactor; var expander = element.Q <VisualElement>("itemChildExpander"); var icon = expander.Query("expanderIcon").First(); icon.ClearClassList(); switch (expanderState) { case ItemExpanderState.Expanded: icon.AddToClassList("Expanded"); break; case ItemExpanderState.Collapsed: icon.AddToClassList("Collapsed"); break; } var nameLabelsContainer = element.Q <VisualElement>("labelsContainer"); nameLabelsContainer.Clear(); if (string.IsNullOrWhiteSpace(query)) { if (string.IsNullOrEmpty(item.Help)) { nameLabelsContainer.Add(new Label(item.Name)); } else { var name = new Label(item.Name); var help = new Label(" (" + item.Help + ")"); help.style.opacity = .5f; nameLabelsContainer.Add(name); nameLabelsContainer.Add(help); } } else { SearcherHighlighter.HighlightTextBasedOnQuery(nameLabelsContainer, item.Name, query); } element.userData = item; element.name = k_EntryName; return(expander); }
static void GetItemsToHide(SearcherItem parent, ref HashSet <SearcherItem> itemsToHide) { if (!parent.HasChildren) { itemsToHide.Add(parent); return; } foreach (var child in parent.Children) { itemsToHide.Add(child); GetItemsToHide(child, ref itemsToHide); } }
bool HasChildResult(SearcherItem item) { if (m_Results.Contains(item)) { return(true); } foreach (var child in item.Children) { if (HasChildResult(child)) { return(true); } } return(false); }
void AddResultChildren(SearcherItem item, ISet <SearcherItem> idSet) { if (!item.HasChildren) { return; } foreach (var child in item.Children) { if (!idSet.Contains(child)) { idSet.Add(child); m_VisibleResults.Add(child); } AddResultChildren(child, idSet); } }
public void AddChild(SearcherItem child) { if (child == null) { throw new ArgumentNullException(nameof(child)); } if (Database != null) { throw new InvalidOperationException( "Cannot add more children to an item that was already used in a database."); } if (Children == null) { Children = new List <SearcherItem>(); } Children.Add(child); child.OverwriteParent(this); }
void Collapse(SearcherItem item) { // if it's already collapsed or not collapsed if (!m_ExpandedResults.Remove(item)) { // this case applies for a left arrow key press if (item.Parent != null) { SetSelectedElementInResultsList(m_VisibleResults.IndexOf(item.Parent)); } // even if it's a root item and has no parents, do nothing more return; } RegenerateVisibleResults(); HideUnexpandedItems(); m_ListView.Refresh(); // RefreshListViewOn(); }
protected virtual bool Match(string query, SearcherItem item, out float score) { var filter = MatchFilter?.Invoke(query, item) ?? true; return(Match(query, item.Path, out score) && filter); }
void OverwriteParent(SearcherItem newParent) { Parent = newParent; }