From 6cdfc22f1cf1a3463c476eaa751bd4428688d10d Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 27 Apr 2016 23:02:06 +0900 Subject: [PATCH] fix #350 - Refresh item in context menu of assemblies --- ILSpy/AssemblyList.cs | 22 ++++++++++++++++-- ILSpy/MainWindow.xaml.cs | 10 +++++++- ILSpy/TreeNodes/AssemblyTreeNode.cs | 36 +++++++++++++++++++++++++++-- 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/ILSpy/AssemblyList.cs b/ILSpy/AssemblyList.cs index a32a06291..03dd6e9e2 100644 --- a/ILSpy/AssemblyList.cs +++ b/ILSpy/AssemblyList.cs @@ -178,8 +178,26 @@ namespace ICSharpCode.ILSpy var index = this.assemblies.IndexOf(target); var newAsm = new LoadedAssembly(this, file, stream); newAsm.IsAutoLoaded = target.IsAutoLoaded; - lock (assemblies) - { + lock (assemblies) { + this.assemblies.Remove(target); + this.assemblies.Insert(index, newAsm); + } + return newAsm; + } + + public LoadedAssembly ReloadAssembly(string file) + { + App.Current.Dispatcher.VerifyAccess(); + file = Path.GetFullPath(file); + + var target = this.assemblies.FirstOrDefault(asm => file.Equals(asm.FileName, StringComparison.OrdinalIgnoreCase)); + if (target == null) + return null; + + var index = this.assemblies.IndexOf(target); + var newAsm = new LoadedAssembly(this, file); + newAsm.IsAutoLoaded = target.IsAutoLoaded; + lock (assemblies) { this.assemblies.Remove(target); this.assemblies.Insert(index, newAsm); } diff --git a/ILSpy/MainWindow.xaml.cs b/ILSpy/MainWindow.xaml.cs index 493a55d70..c85a6cf2e 100644 --- a/ILSpy/MainWindow.xaml.cs +++ b/ILSpy/MainWindow.xaml.cs @@ -531,6 +531,14 @@ namespace ICSharpCode.ILSpy } } } + + public void SelectNodes(IEnumerable nodes) + { + if (nodes.Any() && nodes.All(n => !n.AncestorsAndSelf().Any(a => a.IsHidden))) { + treeView.FocusNode(nodes.First()); + treeView.SetSelectedNodes(nodes); + } + } /// /// Retrieves a node using the .ToString() representations of its ancestors. @@ -557,7 +565,7 @@ namespace ICSharpCode.ILSpy /// /// Gets the .ToString() representation of the node's ancestors. /// - public string[] GetPathForNode(SharpTreeNode node) + public static string[] GetPathForNode(SharpTreeNode node) { if (node == null) return null; diff --git a/ILSpy/TreeNodes/AssemblyTreeNode.cs b/ILSpy/TreeNodes/AssemblyTreeNode.cs index 89a17eae6..ce5b11bd4 100644 --- a/ILSpy/TreeNodes/AssemblyTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyTreeNode.cs @@ -318,7 +318,39 @@ namespace ICSharpCode.ILSpy.TreeNodes } } - [ExportContextMenuEntryAttribute(Header = "_Load Dependencies")] + [ExportContextMenuEntry(Header = "_Reload", Icon = "images/Refresh.png")] + sealed class ReloadAssembly : IContextMenuEntry + { + public bool IsVisible(TextViewContext context) + { + if (context.SelectedTreeNodes == null) + return false; + return context.SelectedTreeNodes.All(n => n is AssemblyTreeNode); + } + + public bool IsEnabled(TextViewContext context) + { + return true; + } + + public void Execute(TextViewContext context) + { + if (context.SelectedTreeNodes == null) + return; + var paths = new List(); + using (context.TreeView.LockUpdates()) { + foreach (var node in context.SelectedTreeNodes) { + paths.Add(MainWindow.GetPathForNode(node)); + var la = ((AssemblyTreeNode)node).LoadedAssembly; + la.AssemblyList.ReloadAssembly(la.FileName); + } + } + MainWindow.Instance.SelectNodes(paths.Select(p => MainWindow.Instance.FindNodeByPath(p, true)).ToArray()); + MainWindow.Instance.RefreshDecompiledView(); + } + } + + [ExportContextMenuEntry(Header = "_Load Dependencies")] sealed class LoadDependencies : IContextMenuEntry { public bool IsVisible(TextViewContext context) @@ -349,7 +381,7 @@ namespace ICSharpCode.ILSpy.TreeNodes } } - [ExportContextMenuEntryAttribute(Header = "_Add To Main List")] + [ExportContextMenuEntry(Header = "_Add To Main List")] sealed class AddToMainList : IContextMenuEntry { public bool IsVisible(TextViewContext context)