Make guidebook start with some entries collapsed (#16181)

This commit is contained in:
Leon Friedrich
2023-05-07 15:12:29 +12:00
committed by GitHub
parent d0a90e7e86
commit 883d6646ea
3 changed files with 21 additions and 6 deletions

View File

@@ -176,20 +176,30 @@ public sealed partial class FancyTree : Control
OnSelectedItemChanged?.Invoke(newSelection);
}
public void SetAllExpanded(bool value)
/// <summary>
/// Recursively expands or collapse all entries, optionally up to some depth.
/// </summary>
/// <param name="value">Whether to expand or collapse the entries</param>
/// <param name="depth">The recursion depth. If negative, implies no limit. Zero will expand only the top-level entries.</param>
public void SetAllExpanded(bool value, int depth = -1)
{
foreach (var item in Body.Children)
{
RecursiveSetExpanded((TreeItem) item, value);
RecursiveSetExpanded((TreeItem) item, value, depth);
}
}
public void RecursiveSetExpanded(TreeItem item, bool value)
public void RecursiveSetExpanded(TreeItem item, bool value, int depth)
{
item.SetExpanded(value);
if (depth == 0)
return;
depth--;
foreach (var child in item.Body.Children)
{
RecursiveSetExpanded((TreeItem) child, value);
RecursiveSetExpanded((TreeItem) child, value, depth);
}
}