From 7be3277a1b48b210da2ab544775132bb042c8c57 Mon Sep 17 00:00:00 2001 From: Eusebiu Marcu Date: Tue, 8 Feb 2011 11:23:46 +0200 Subject: [PATCH 1/5] Add "Remove assembly" item in AssemblyTreeNode context menu. --- ILSpy/ILSpy.csproj | 1 + ILSpy/Images/Delete.png | Bin 0 -> 575 bytes ILSpy/Images/Images.cs | 2 ++ ILSpy/TreeNodes/AssemblyTreeNode.cs | 29 ++++++++++++++++++++++++++++ 4 files changed, 32 insertions(+) create mode 100644 ILSpy/Images/Delete.png diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj index 61843f00b3..90c83b900e 100644 --- a/ILSpy/ILSpy.csproj +++ b/ILSpy/ILSpy.csproj @@ -109,6 +109,7 @@ + diff --git a/ILSpy/Images/Delete.png b/ILSpy/Images/Delete.png new file mode 100644 index 0000000000000000000000000000000000000000..824d938dd67435984f22217cceab55e0c4438e15 GIT binary patch literal 575 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9EWV9eN~w38hu$dc~p z>&U>cv9IQL;A9|QA=x9ymw};5m4Tt5nStTwe<1ymfuYoZf#FpG1B2BJ1_tr`N%2SB z7#JA0db&7e#t z!M*2y`Qtr|CtQ~#G%zIn*qvE-NME__e*%vQ%aP+N8CAqH3*;hs6dDd3nSc4W?7o|v zd;Vvg_#od>pYLM)Q+?m_{EBq18;_&$6 z-g5A#yu$Uj@$wDtv>F(k9{ypz^~LbcgFn^_7#033)l2-RuJHG!*a}Ja9}Fx4Vf*XW z`Of$sHUFVK&;Mh>I~W*`w8&}i&yO?sQTD6huztd)hKKsz>dzi`xdP2He0zAyueRe= zJpUbkq^>yl^L+PjZn-|#KZ99vEsoCF$X>XBb&j~ L)z4*}Q$iB}*vs=~ literal 0 HcmV?d00001 diff --git a/ILSpy/Images/Images.cs b/ILSpy/Images/Images.cs index 684bbde326..6b3d334149 100644 --- a/ILSpy/Images/Images.cs +++ b/ILSpy/Images/Images.cs @@ -65,5 +65,7 @@ static BitmapImage LoadBitmap(string name) public static readonly BitmapImage ProtectedEnum = LoadBitmap("ProtectedEnum"); public static readonly BitmapImage ProtectedInterface = LoadBitmap("ProtectedInterface"); public static readonly BitmapImage ProtectedStruct = LoadBitmap("ProtectedStruct"); + + public static readonly BitmapImage Delete = LoadBitmap("Delete"); } } diff --git a/ILSpy/TreeNodes/AssemblyTreeNode.cs b/ILSpy/TreeNodes/AssemblyTreeNode.cs index 12de869633..7ad607f8d8 100644 --- a/ILSpy/TreeNodes/AssemblyTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyTreeNode.cs @@ -24,6 +24,7 @@ using System.Threading; using System.Threading.Tasks; using System.Windows; +using System.Windows.Controls; using ICSharpCode.Decompiler; using ICSharpCode.TreeView; @@ -37,6 +38,7 @@ namespace ICSharpCode.ILSpy.TreeNodes /// sealed class AssemblyTreeNode : ILSpyTreeNode { + readonly AssemblyList assemblyList; readonly string fileName; string shortName; @@ -44,6 +46,9 @@ sealed class AssemblyTreeNode : ILSpyTreeNode readonly List classes = new List(); readonly Dictionary namespaces = new Dictionary(); + // UI + ContextMenu menu; + public AssemblyTreeNode(string fileName, AssemblyList assemblyList) { if (fileName == null) @@ -57,6 +62,8 @@ public AssemblyTreeNode(string fileName, AssemblyList assemblyList) assemblyTask.ContinueWith(OnAssemblyLoaded, TaskScheduler.FromCurrentSynchronizationContext()); this.LazyLoading = true; + + CreateRemoveItemContextMenu(); } public string FileName { @@ -122,6 +129,20 @@ void OnAssemblyLoaded(Task assemblyTask) } } + void CreateRemoveItemContextMenu() + { + var menu = GetContextMenu(); + + MenuItem item = new MenuItem() { + Header = "Remove assembly", + Icon = new Image() { Source = Images.Delete } + }; + + item.Click += delegate { Delete(); }; + + menu.Items.Add(item); + } + sealed class MyAssemblyResolver : IAssemblyResolver { readonly AssemblyTreeNode parent; @@ -156,6 +177,14 @@ public AssemblyDefinition Resolve(string fullName, ReaderParameters parameters) } } + public override ContextMenu GetContextMenu() + { + if (menu != null) + return menu; + + return (menu = new ContextMenu()); + } + protected override void LoadChildren() { try { From b2c532bfe98b84e3634850de8f69d432db5938f9 Mon Sep 17 00:00:00 2001 From: Eusebiu Marcu Date: Tue, 8 Feb 2011 15:22:21 +0200 Subject: [PATCH 2/5] Generalize the work with the tree-nodes context menu. --- ILSpy/TreeNodes/AssemblyTreeNode.cs | 23 +++++++---------------- ILSpy/TreeNodes/ILSpyTreeNode.cs | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/ILSpy/TreeNodes/AssemblyTreeNode.cs b/ILSpy/TreeNodes/AssemblyTreeNode.cs index 7ad607f8d8..d36ac543f3 100644 --- a/ILSpy/TreeNodes/AssemblyTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyTreeNode.cs @@ -46,9 +46,6 @@ sealed class AssemblyTreeNode : ILSpyTreeNode 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 @@ public AssemblyTreeNode(string fileName, AssemblyList assemblyList) this.LazyLoading = true; - CreateRemoveItemContextMenu(); + CreateContextMenu(); } public string FileName { @@ -129,10 +126,12 @@ void OnAssemblyLoaded(Task assemblyTask) } } - 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 @@ void CreateRemoveItemContextMenu() item.Click += delegate { Delete(); }; - menu.Items.Add(item); + contextMenu.Items.Add(item); } sealed class MyAssemblyResolver : IAssemblyResolver @@ -177,14 +176,6 @@ public AssemblyDefinition Resolve(string fullName, ReaderParameters parameters) } } - 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 aaf614a6c0..650276bce9 100644 --- a/ILSpy/TreeNodes/ILSpyTreeNode.cs +++ b/ILSpy/TreeNodes/ILSpyTreeNode.cs @@ -20,6 +20,8 @@ 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 @@ public virtual FilterResult Filter(FilterSettings settings) 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 From e3431d762eddf3b6be5d2b1133c509a4f0d9b826 Mon Sep 17 00:00:00 2001 From: Eusebiu Marcu Date: Tue, 8 Feb 2011 20:55:31 +0200 Subject: [PATCH 3/5] Revert "Generalize the work with the tree-nodes context menu." This reverts commit b2c532bfe98b84e3634850de8f69d432db5938f9. --- ILSpy/TreeNodes/AssemblyTreeNode.cs | 23 ++++++++++++++++------- ILSpy/TreeNodes/ILSpyTreeNode.cs | 17 ----------------- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/ILSpy/TreeNodes/AssemblyTreeNode.cs b/ILSpy/TreeNodes/AssemblyTreeNode.cs index d36ac543f3..7ad607f8d8 100644 --- a/ILSpy/TreeNodes/AssemblyTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyTreeNode.cs @@ -46,6 +46,9 @@ sealed class AssemblyTreeNode : ILSpyTreeNode 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 @@ public AssemblyTreeNode(string fileName, AssemblyList assemblyList) this.LazyLoading = true; - CreateContextMenu(); + CreateRemoveItemContextMenu(); } public string FileName { @@ -126,12 +129,10 @@ void OnAssemblyLoaded(Task assemblyTask) } } - 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 @@ protected override void CreateContextMenu() item.Click += delegate { Delete(); }; - contextMenu.Items.Add(item); + menu.Items.Add(item); } sealed class MyAssemblyResolver : IAssemblyResolver @@ -176,6 +177,14 @@ public AssemblyDefinition Resolve(string fullName, ReaderParameters parameters) } } + 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 650276bce9..aaf614a6c0 100644 --- a/ILSpy/TreeNodes/ILSpyTreeNode.cs +++ b/ILSpy/TreeNodes/ILSpyTreeNode.cs @@ -20,8 +20,6 @@ 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 @@ public virtual FilterResult Filter(FilterSettings settings) 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 From 7d7216ecbf8983b21cdb59a443c072b1e953386a Mon Sep 17 00:00:00 2001 From: Eusebiu Marcu Date: Tue, 8 Feb 2011 21:24:04 +0200 Subject: [PATCH 4/5] Move creation of the menuitem in GetContextMenu and remove the ContextMenu field member. --- ILSpy/TreeNodes/AssemblyTreeNode.cs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/ILSpy/TreeNodes/AssemblyTreeNode.cs b/ILSpy/TreeNodes/AssemblyTreeNode.cs index 7ad607f8d8..e091700f87 100644 --- a/ILSpy/TreeNodes/AssemblyTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyTreeNode.cs @@ -62,8 +62,6 @@ public AssemblyTreeNode(string fileName, AssemblyList assemblyList) assemblyTask.ContinueWith(OnAssemblyLoaded, TaskScheduler.FromCurrentSynchronizationContext()); this.LazyLoading = true; - - CreateRemoveItemContextMenu(); } public string FileName { @@ -129,10 +127,8 @@ void OnAssemblyLoaded(Task assemblyTask) } } - void CreateRemoveItemContextMenu() + MenuItem CreateRemoveAssemblyItem() { - var menu = GetContextMenu(); - MenuItem item = new MenuItem() { Header = "Remove assembly", Icon = new Image() { Source = Images.Delete } @@ -140,7 +136,7 @@ void CreateRemoveItemContextMenu() item.Click += delegate { Delete(); }; - menu.Items.Add(item); + return item; } sealed class MyAssemblyResolver : IAssemblyResolver @@ -179,10 +175,11 @@ public AssemblyDefinition Resolve(string fullName, ReaderParameters parameters) public override ContextMenu GetContextMenu() { - if (menu != null) - return menu; + // specific to AssemblyTreeNode + var menu = new ContextMenu(); + menu.Items.Add(CreateRemoveAssemblyItem()); - return (menu = new ContextMenu()); + return menu; } protected override void LoadChildren() From 10651d014560505781944a436e546510f4147a14 Mon Sep 17 00:00:00 2001 From: Eusebiu Marcu Date: Tue, 8 Feb 2011 21:30:01 +0200 Subject: [PATCH 5/5] Remove the ContextMenu field member. --- ILSpy/TreeNodes/AssemblyTreeNode.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/ILSpy/TreeNodes/AssemblyTreeNode.cs b/ILSpy/TreeNodes/AssemblyTreeNode.cs index e091700f87..2a003e4cdf 100644 --- a/ILSpy/TreeNodes/AssemblyTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyTreeNode.cs @@ -46,9 +46,6 @@ sealed class AssemblyTreeNode : ILSpyTreeNode readonly List classes = new List(); readonly Dictionary namespaces = new Dictionary(); - // UI - ContextMenu menu; - public AssemblyTreeNode(string fileName, AssemblyList assemblyList) { if (fileName == null)