Skip to content

Commit

Permalink
Avoid round-trip from view into model
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-englert committed Aug 18, 2024
1 parent 347b89c commit 723b4b1
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions ILSpy/Analyzers/AnalyzerTreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,6 @@ public AnalyzerTreeView()
this.BorderThickness = new();
this.Root = new AnalyzerRootNode();
ContextMenuProvider.Add(this);
MessageBus<CurrentAssemblyListChangedEventArgs>.Subscribers += (sender, e) => CurrentAssemblyList_Changed(sender, e);
}


void CurrentAssemblyList_Changed(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Reset)
{
this.Root.Children.Clear();
}
else
{
List<LoadedAssembly> removedAssemblies = new List<LoadedAssembly>();
if (e.OldItems != null)
removedAssemblies.AddRange(e.OldItems.Cast<LoadedAssembly>());
List<LoadedAssembly> addedAssemblies = new List<LoadedAssembly>();
if (e.NewItems != null)
addedAssemblies.AddRange(e.NewItems.Cast<LoadedAssembly>());
((AnalyzerRootNode)this.Root).HandleAssemblyListChanged(removedAssemblies, addedAssemblies);
}
}

public void Show()
Expand Down Expand Up @@ -144,6 +124,26 @@ public void Analyze(IEntity entity)

sealed class AnalyzerRootNode : AnalyzerTreeNode
{
public AnalyzerRootNode()
{
MessageBus<CurrentAssemblyListChangedEventArgs>.Subscribers += (sender, e) => CurrentAssemblyList_Changed(sender, e);
}

void CurrentAssemblyList_Changed(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Reset)
{
this.Children.Clear();
}
else
{
var removedAssemblies = e.OldItems?.Cast<LoadedAssembly>().ToArray() ?? [];
var addedAssemblies = e.NewItems?.Cast<LoadedAssembly>().ToArray() ?? [];

HandleAssemblyListChanged(removedAssemblies, addedAssemblies);
}
}

public override bool HandleAssemblyListChanged(ICollection<LoadedAssembly> removedAssemblies, ICollection<LoadedAssembly> addedAssemblies)
{
this.Children.RemoveAll(
Expand Down

0 comments on commit 723b4b1

Please sign in to comment.