diff --git a/ILSpy/TreeNodes/AssemblyTreeNode.cs b/ILSpy/TreeNodes/AssemblyTreeNode.cs index 7ad607f8d..d36ac543f 100644 --- a/ILSpy/TreeNodes/AssemblyTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyTreeNode.cs @@ -46,9 +46,6 @@ 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) @@ -63,7 +60,7 @@ namespace ICSharpCode.ILSpy.TreeNodes this.LazyLoading = true; - CreateRemoveItemContextMenu(); + CreateContextMenu(); } public string FileName { @@ -129,10 +126,12 @@ namespace ICSharpCode.ILSpy.TreeNodes } } - void CreateRemoveItemContextMenu() + protected override void CreateContextMenu() { - var menu = GetContextMenu(); - + // this is necesary since it create the instance of the context menu + base.CreateContextMenu(); + + // add specific items - remove assembly MenuItem item = new MenuItem() { Header = "Remove assembly", Icon = new Image() { Source = Images.Delete } @@ -140,7 +139,7 @@ namespace ICSharpCode.ILSpy.TreeNodes item.Click += delegate { Delete(); }; - menu.Items.Add(item); + contextMenu.Items.Add(item); } sealed class MyAssemblyResolver : IAssemblyResolver @@ -177,14 +176,6 @@ 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 aaf614a6c..650276bce 100644 --- a/ILSpy/TreeNodes/ILSpyTreeNode.cs +++ b/ILSpy/TreeNodes/ILSpyTreeNode.cs @@ -20,6 +20,8 @@ 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; @@ -31,6 +33,9 @@ namespace ICSharpCode.ILSpy.TreeNodes /// abstract class ILSpyTreeNodeBase : SharpTreeNode { + // UI + protected ContextMenu contextMenu; + FilterSettings filterSettings; public FilterSettings FilterSettings { @@ -61,6 +66,18 @@ 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