From 388c8f611cbf6a83432fa12a512e2ce26c73ca83 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 16 Nov 2019 19:49:26 +0100 Subject: [PATCH] Add DecompileInNewViewCommand to TextView context menu. --- ILSpy/Commands/DecompileInNewViewCommand.cs | 27 ++++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/ILSpy/Commands/DecompileInNewViewCommand.cs b/ILSpy/Commands/DecompileInNewViewCommand.cs index e5ca26f03..92fdd7275 100644 --- a/ILSpy/Commands/DecompileInNewViewCommand.cs +++ b/ILSpy/Commands/DecompileInNewViewCommand.cs @@ -18,6 +18,7 @@ using System; using System.Linq; +using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.ILSpy.Docking; using ICSharpCode.ILSpy.Properties; using ICSharpCode.ILSpy.TextView; @@ -30,27 +31,35 @@ namespace ICSharpCode.ILSpy.Commands { public bool IsVisible(TextViewContext context) { - if (context.SelectedTreeNodes == null) - return false; - return true; + return context.SelectedTreeNodes != null || context.Reference?.Reference is IEntity; } public bool IsEnabled(TextViewContext context) { - if (context.SelectedTreeNodes == null) - return false; - return true; + return context.SelectedTreeNodes != null || context.Reference?.Reference is IEntity; } public void Execute(TextViewContext context) { - var nodes = context.SelectedTreeNodes.Cast().ToArray(); + if (context.SelectedTreeNodes != null) { + var nodes = context.SelectedTreeNodes.Cast().ToArray(); + DecompileNodes(nodes); + } else if (context.Reference?.Reference is IEntity entity) { + var node = MainWindow.Instance.FindTreeNode(entity); + if (node != null) { + DecompileNodes(node); + } + } + } + + private static void DecompileNodes(params ILSpyTreeNode[] nodes) + { var title = string.Join(", ", nodes.Select(x => x.ToString())); DockWorkspace.Instance.Documents.Add(new ViewModels.DecompiledDocumentModel(title, title)); DockWorkspace.Instance.ActiveDocument = DockWorkspace.Instance.Documents.Last(); - MainWindow.Instance.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (Action)(delegate { + MainWindow.Instance.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (Action)delegate { DockWorkspace.Instance.GetTextView().DecompileAsync(MainWindow.Instance.CurrentLanguage, nodes, new DecompilationOptions()); - })); + }); } } }