diff --git a/ILSpy/TreeNodes/AssemblyTreeNode.cs b/ILSpy/TreeNodes/AssemblyTreeNode.cs index d36ac543f..7ad607f8d 100644 --- a/ILSpy/TreeNodes/AssemblyTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyTreeNode.cs @@ -46,6 +46,9 @@ namespace ICSharpCode.ILSpy.TreeNodes readonly List classes = new List(); readonly Dictionary namespaces = new Dictionary(); + // UI + ContextMenu menu; + public AssemblyTreeNode(string fileName, AssemblyList assemblyList) { if (fileName == null) @@ -60,7 +63,7 @@ namespace ICSharpCode.ILSpy.TreeNodes this.LazyLoading = true; - CreateContextMenu(); + CreateRemoveItemContextMenu(); } public string FileName { @@ -126,12 +129,10 @@ namespace ICSharpCode.ILSpy.TreeNodes } } - protected override void CreateContextMenu() + void CreateRemoveItemContextMenu() { - // this is necesary since it create the instance of the context menu - base.CreateContextMenu(); - - // add specific items - remove assembly + var menu = GetContextMenu(); + MenuItem item = new MenuItem() { Header = "Remove assembly", Icon = new Image() { Source = Images.Delete } @@ -139,7 +140,7 @@ namespace ICSharpCode.ILSpy.TreeNodes item.Click += delegate { Delete(); }; - contextMenu.Items.Add(item); + menu.Items.Add(item); } sealed class MyAssemblyResolver : IAssemblyResolver @@ -176,6 +177,14 @@ namespace ICSharpCode.ILSpy.TreeNodes } } + public override ContextMenu GetContextMenu() + { + if (menu != null) + return menu; + + return (menu = new ContextMenu()); + } + protected override void LoadChildren() { try { diff --git a/ILSpy/TreeNodes/ILSpyTreeNode.cs b/ILSpy/TreeNodes/ILSpyTreeNode.cs index 650276bce..aaf614a6c 100644 --- a/ILSpy/TreeNodes/ILSpyTreeNode.cs +++ b/ILSpy/TreeNodes/ILSpyTreeNode.cs @@ -20,8 +20,6 @@ using System; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.ComponentModel; -using System.Windows; -using System.Windows.Controls; using ICSharpCode.Decompiler; using ICSharpCode.TreeView; @@ -33,9 +31,6 @@ namespace ICSharpCode.ILSpy.TreeNodes /// abstract class ILSpyTreeNodeBase : SharpTreeNode { - // UI - protected ContextMenu contextMenu; - FilterSettings filterSettings; public FilterSettings FilterSettings { @@ -66,18 +61,6 @@ namespace ICSharpCode.ILSpy.TreeNodes return FilterResult.Hidden; } - protected virtual void CreateContextMenu() - { - contextMenu = new ContextMenu(); - - // add common context menu items, e.g. copy. - } - - public override ContextMenu GetContextMenu() - { - return contextMenu; - } - protected object HighlightSearchMatch(string text, string suffix = null) { // TODO: implement highlighting the search match