From e7da8bc3053a84cc33f63e1799cb21f05acc3c36 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 16 Feb 2019 10:58:29 +0100 Subject: [PATCH] Add context menu for Pdb2XmlCommand --- ILSpy/Commands/Pdb2XmlCommand.cs | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/ILSpy/Commands/Pdb2XmlCommand.cs b/ILSpy/Commands/Pdb2XmlCommand.cs index c633692fb..96932a1d9 100644 --- a/ILSpy/Commands/Pdb2XmlCommand.cs +++ b/ILSpy/Commands/Pdb2XmlCommand.cs @@ -18,8 +18,7 @@ #if DEBUG -using System; -using System.Diagnostics; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; @@ -42,10 +41,13 @@ namespace ICSharpCode.ILSpy } public override void Execute(object parameter) + { + Execute(MainWindow.Instance.SelectedNodes.OfType()); + } + + internal static void Execute(IEnumerable nodes) { var highlighting = HighlightingManager.Instance.GetDefinitionByExtension(".xml"); - var language = MainWindow.Instance.CurrentLanguage; - var nodes = MainWindow.Instance.SelectedNodes.OfType(); var options = PdbToXmlOptions.IncludeEmbeddedSources | PdbToXmlOptions.IncludeMethodSpans | PdbToXmlOptions.IncludeTokens; MainWindow.Instance.TextView.RunWithCancellation(ct => Task.Factory.StartNew(() => { AvalonEditTextOutput output = new AvalonEditTextOutput(); @@ -61,6 +63,25 @@ namespace ICSharpCode.ILSpy }, ct)).Then(output => MainWindow.Instance.TextView.ShowNodes(output, null, highlighting)).HandleExceptions(); } } + + [ExportContextMenuEntry(Header = "DEBUG -- Dump PDB as XML")] + class Pdb2XmlCommandContextMenuEntry : IContextMenuEntry + { + public void Execute(TextViewContext context) + { + Pdb2XmlCommand.Execute(context.SelectedTreeNodes.OfType()); + } + + public bool IsEnabled(TextViewContext context) => true; + + public bool IsVisible(TextViewContext context) + { + var selectedNodes = context.SelectedTreeNodes; + return selectedNodes?.Any() == true + && selectedNodes.All(n => n is AssemblyTreeNode asm && !asm.LoadedAssembly.HasLoadError); + } + } + } #endif \ No newline at end of file