private void SelectChild(FuzzyOptionNode node) { if (node == null || node.option is FuzzySeparator) { return; } if (node.option.mode == FuzzyOptionMode.Branch) { if (node.EvaluateHasChildren(tree)) { EnterChild(node); } } else if (node.option.mode == FuzzyOptionMode.Leaf) { if (node == activeNode) { node.option.OnFocusLeave(node); } callback?.Invoke(node.option); } }
private void UpdateFavorites() { if (tree.favorites != null) { DisplayProgressBar("Fetching favorites...", 0); favoritesRoot.children.Clear(); favoritesRoot.hasChildren = null; favoritesRoot.isPopulated = false; // Adding a where clause in case a favorited item was later changed to be unfavoritable. Populate(favoritesRoot, tree.favorites.Where(favorite => tree.CanFavorite(favorite))); } else { favoritesRoot.children.Clear(); favoritesRoot.isPopulated = true; } root.children.Remove(favoritesRoot); if (favoritesRoot.EvaluateHasChildren(tree)) { root.children.Insert(0, favoritesRoot); } }
public void Populate(FuzzyOptionNode node, IEnumerable <IFuzzyOption> children, CancellationToken?cancellation = null) { if (node.isPopulated) { return; } if (node.option.mode == FuzzyOptionMode.Branch) { var i = 0; var _children = children.ToArray(); lock (guiLock) { if (node.hasChildren == null) { node.hasChildren = _children.Length > 0; } } var childNodes = new List <FuzzyOptionNode>(); foreach (var child in _children) { if (child == null) { continue; } try { child.OnPopulate(); } catch (Exception ex) { Debug.LogWarning($"Failed to display {child.GetType()}: \n{ex}"); continue; } string label; if (node.option is SearchOption) { label = tree.SearchResultLabel(child, query); } else if (node == favoritesRoot || tree.UseExplicitLabel(node.option, child)) { label = tree.ExplicitLabel(child) ?? child.label; } else { label = child.label; } FuzzyOptionNode childNode; try { childNode = new FuzzyOptionNode(child, label); } catch (Exception ex) { Debug.LogWarning($"Failed to create option node for {child.GetType()} (value = {child.value}): \n{ex}"); continue; } DisplayProgressBar($"{child.label}... ({++i} / {_children.Length})", (float)i / _children.Length); var evaluateBranchesEarly = false; if (child.mode == FuzzyOptionMode.Leaf) { childNode.hasChildren = false; childNodes.Add(childNode); } else if (child.mode == FuzzyOptionMode.Branch) { if (evaluateBranchesEarly) { if (childNode.EvaluateHasChildren(tree)) { childNodes.Add(childNode); } } else { childNodes.Add(childNode); } } cancellation?.ThrowIfCancellationRequested(); } lock (guiLock) { node.children.AddRange(childNodes); } } lock (guiLock) { node.isPopulated = true; } }