Browse Source

Add SharpTreeNode.ReloadChildren for the lazy-subtree reset

The UseNestedNamespaceNodes and HideEmptyMetadataTables handlers both
force a materialised node to re-create its children (clear, re-arm
LazyLoading, EnsureLazyChildren), guarded on it not already being lazy.
That's a general tree-node operation -- a soft, in-place rebuild that
re-runs LoadChildren without reloading the assembly -- so it belongs on
SharpTreeNode next to the lazy contract it builds on, not as a private
helper in the model. Both call sites now use node.ReloadChildren().

Assisted-by: Claude:claude-opus-4-8:Claude Code
pull/3755/head
Siegfried Pammer 4 weeks ago
parent
commit
8c433ea3ff
  1. 17
      ICSharpCode.ILSpyX/TreeView/SharpTreeNode.cs
  2. 17
      ILSpy/AssemblyTree/AssemblyTreeModel.cs

17
ICSharpCode.ILSpyX/TreeView/SharpTreeNode.cs

@ -374,6 +374,23 @@ namespace ICSharpCode.ILSpyX.TreeView @@ -374,6 +374,23 @@ namespace ICSharpCode.ILSpyX.TreeView
}
}
/// <summary>
/// Rebuilds the children of an already-loaded node in place: clears them, re-arms lazy
/// loading, and re-runs <see cref="LoadChildren"/>. A no-op for a node that is still lazy
/// (it will build fresh on first expand anyway). Use this when external state that
/// <see cref="LoadChildren"/> reads has changed and the materialized subtree must be
/// regenerated -- e.g. a display setting that alters the tree's shape. Like setting
/// <see cref="LazyLoading"/>, this collapses the node.
/// </summary>
public void ReloadChildren()
{
if (LazyLoading)
return;
Children.Clear();
LazyLoading = true;
EnsureLazyChildren();
}
#endregion
#region Ancestors / Descendants

17
ILSpy/AssemblyTree/AssemblyTreeModel.cs

@ -264,15 +264,9 @@ namespace ILSpy.AssemblyTree @@ -264,15 +264,9 @@ namespace ILSpy.AssemblyTree
break;
case nameof(Options.DisplaySettings.UseNestedNamespaceNodes):
// Tree shape changes — every loaded AssemblyTreeNode's namespace subtree
// needs rebuilding. Reset Children + LazyLoading and re-trigger the load.
// needs rebuilding.
foreach (var asm in Root.Children.OfType<TreeNodes.AssemblyTreeNode>())
{
if (asm.LazyLoading)
continue;
asm.Children.Clear();
asm.LazyLoading = true;
asm.EnsureLazyChildren();
}
asm.ReloadChildren();
// AssemblyListPane caches a snapshot of each expanded node's children via
// the HierarchicalOptions.ChildrenSelector — mid-expand mutations of
// node.Children aren't observed. Re-raising Root forces BindTree to fire,
@ -294,12 +288,7 @@ namespace ILSpy.AssemblyTree @@ -294,12 +288,7 @@ namespace ILSpy.AssemblyTree
{
if (node is Metadata.MetadataTablesTreeNode tables)
{
if (!tables.LazyLoading)
{
tables.Children.Clear();
tables.LazyLoading = true;
tables.EnsureLazyChildren();
}
tables.ReloadChildren();
return;
}
if (node.LazyLoading)

Loading…
Cancel
Save