From 8c433ea3ff5be23a4867d02e0c5a67448687fd3c Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 9 Jun 2026 18:02:50 +0200 Subject: [PATCH] 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 --- ICSharpCode.ILSpyX/TreeView/SharpTreeNode.cs | 17 +++++++++++++++++ ILSpy/AssemblyTree/AssemblyTreeModel.cs | 17 +++-------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/ICSharpCode.ILSpyX/TreeView/SharpTreeNode.cs b/ICSharpCode.ILSpyX/TreeView/SharpTreeNode.cs index ea54bd4e1..74b66cd6b 100644 --- a/ICSharpCode.ILSpyX/TreeView/SharpTreeNode.cs +++ b/ICSharpCode.ILSpyX/TreeView/SharpTreeNode.cs @@ -374,6 +374,23 @@ namespace ICSharpCode.ILSpyX.TreeView } } + /// + /// Rebuilds the children of an already-loaded node in place: clears them, re-arms lazy + /// loading, and re-runs . A no-op for a node that is still lazy + /// (it will build fresh on first expand anyway). Use this when external state that + /// reads has changed and the materialized subtree must be + /// regenerated -- e.g. a display setting that alters the tree's shape. Like setting + /// , this collapses the node. + /// + public void ReloadChildren() + { + if (LazyLoading) + return; + Children.Clear(); + LazyLoading = true; + EnsureLazyChildren(); + } + #endregion #region Ancestors / Descendants diff --git a/ILSpy/AssemblyTree/AssemblyTreeModel.cs b/ILSpy/AssemblyTree/AssemblyTreeModel.cs index 950074275..23b6412e1 100644 --- a/ILSpy/AssemblyTree/AssemblyTreeModel.cs +++ b/ILSpy/AssemblyTree/AssemblyTreeModel.cs @@ -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()) - { - 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 { if (node is Metadata.MetadataTablesTreeNode tables) { - if (!tables.LazyLoading) - { - tables.Children.Clear(); - tables.LazyLoading = true; - tables.EnsureLazyChildren(); - } + tables.ReloadChildren(); return; } if (node.LazyLoading)