From 0cbd146c8476bff2112b0390d0cdf09b2b5e7338 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 10 Jul 2018 08:21:50 +0200 Subject: [PATCH] Add "Generate portable PDB" to main menu --- .../GeneratePdbContextMenuEntry.cs | 59 +++++++++++++++---- ILSpy/ILSpy.csproj | 2 +- 2 files changed, 50 insertions(+), 11 deletions(-) rename ILSpy/{TreeNodes => Commands}/GeneratePdbContextMenuEntry.cs (53%) diff --git a/ILSpy/TreeNodes/GeneratePdbContextMenuEntry.cs b/ILSpy/Commands/GeneratePdbContextMenuEntry.cs similarity index 53% rename from ILSpy/TreeNodes/GeneratePdbContextMenuEntry.cs rename to ILSpy/Commands/GeneratePdbContextMenuEntry.cs index 244a995ad..19952b4a5 100644 --- a/ILSpy/TreeNodes/GeneratePdbContextMenuEntry.cs +++ b/ILSpy/Commands/GeneratePdbContextMenuEntry.cs @@ -1,26 +1,56 @@ -using System; -using System.Collections.Generic; +// Copyright (c) 2018 Siegfried Pammer +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; using System.Diagnostics; using System.IO; using System.Linq; -using System.Text; using System.Threading.Tasks; using ICSharpCode.Decompiler; using ICSharpCode.Decompiler.CSharp; using ICSharpCode.Decompiler.DebugInfo; using ICSharpCode.ILSpy.TextView; +using ICSharpCode.ILSpy.TreeNodes; using Microsoft.Win32; -namespace ICSharpCode.ILSpy.TreeNodes +namespace ICSharpCode.ILSpy { [ExportContextMenuEntry(Header = "Generate portable PDB")] class GeneratePdbContextMenuEntry : IContextMenuEntry { public void Execute(TextViewContext context) { - var language = MainWindow.Instance.CurrentLanguage; var assembly = (context.SelectedTreeNodes?.FirstOrDefault() as AssemblyTreeNode)?.LoadedAssembly; if (assembly == null) return; + GeneratePdbForAssembly(assembly); + } + + public bool IsEnabled(TextViewContext context) => true; + + public bool IsVisible(TextViewContext context) + { + return context.SelectedTreeNodes?.Length == 1 + && context.SelectedTreeNodes?.FirstOrDefault() is AssemblyTreeNode tn + && !tn.LoadedAssembly.HasLoadError; + } + + internal static void GeneratePdbForAssembly(LoadedAssembly assembly) + { SaveFileDialog dlg = new SaveFileDialog(); dlg.FileName = DecompilerTextView.CleanUpName(assembly.ShortName) + ".pdb"; dlg.Filter = "Portable PDB|*.pdb|All files|*.*"; @@ -49,14 +79,23 @@ namespace ICSharpCode.ILSpy.TreeNodes return output; }, ct)).Then(output => MainWindow.Instance.TextView.ShowText(output)).HandleExceptions(); } + } - public bool IsEnabled(TextViewContext context) => true; - - public bool IsVisible(TextViewContext context) + [ExportMainMenuCommand(Menu = "_File", Header = "Generate portable PDB", MenuCategory = "Save")] + class GeneratePdbMainMenuEntry : SimpleCommand + { + public override bool CanExecute(object parameter) { - return context.SelectedTreeNodes?.Length == 1 - && context.SelectedTreeNodes?.FirstOrDefault() is AssemblyTreeNode tn + return MainWindow.Instance.SelectedNodes?.Count() == 1 + && MainWindow.Instance.SelectedNodes?.FirstOrDefault() is AssemblyTreeNode tn && !tn.LoadedAssembly.HasLoadError; } + + public override void Execute(object parameter) + { + var assembly = (MainWindow.Instance.SelectedNodes?.FirstOrDefault() as AssemblyTreeNode)?.LoadedAssembly; + if (assembly == null) return; + GeneratePdbContextMenuEntry.GeneratePdbForAssembly(assembly); + } } } diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj index f83a9d532..8896377f1 100644 --- a/ILSpy/ILSpy.csproj +++ b/ILSpy/ILSpy.csproj @@ -219,7 +219,7 @@ - +