From 84c5e6337014c5439349f2e29eb82b87f1813371 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 12 Dec 2023 20:36:09 +0100 Subject: [PATCH] Fix #3118: Add "Clear assembly list" menu item. --- ICSharpCode.ILSpyX/AssemblyList.cs | 11 ++++++++++- ILSpy/Commands/RemoveAssembliesWithLoadErrors.cs | 16 ++++++++++++++-- ILSpy/Properties/Resources.Designer.cs | 9 +++++++++ ILSpy/Properties/Resources.resx | 3 +++ 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/ICSharpCode.ILSpyX/AssemblyList.cs b/ICSharpCode.ILSpyX/AssemblyList.cs index 90123d6432..d7070498ba 100644 --- a/ICSharpCode.ILSpyX/AssemblyList.cs +++ b/ICSharpCode.ILSpyX/AssemblyList.cs @@ -23,7 +23,6 @@ using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Threading; @@ -395,6 +394,16 @@ public void Unload(LoadedAssembly assembly) } } + public void Clear() + { + VerifyAccess(); + lock (lockObj) + { + dirty = true; + assemblies.Clear(); + byFilename.Clear(); + } + } public void Sort(IComparer comparer) { Sort(0, int.MaxValue, comparer); diff --git a/ILSpy/Commands/RemoveAssembliesWithLoadErrors.cs b/ILSpy/Commands/RemoveAssembliesWithLoadErrors.cs index a0ca794791..a2a4430be0 100644 --- a/ILSpy/Commands/RemoveAssembliesWithLoadErrors.cs +++ b/ILSpy/Commands/RemoveAssembliesWithLoadErrors.cs @@ -16,8 +16,6 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -using System; -using System.Collections.Generic; using System.Linq; using ICSharpCode.ILSpy.Properties; @@ -44,4 +42,18 @@ public override void Execute(object parameter) } } } + + [ExportMainMenuCommand(ParentMenuID = nameof(Resources._File), Header = nameof(Resources.ClearAssemblyList), MenuCategory = nameof(Resources.Remove), MenuOrder = 2.6)] + class ClearAssemblyList : SimpleCommand + { + public override bool CanExecute(object parameter) + { + return MainWindow.Instance.CurrentAssemblyList?.Count > 0; + } + + public override void Execute(object parameter) + { + MainWindow.Instance.CurrentAssemblyList?.Clear(); + } + } } diff --git a/ILSpy/Properties/Resources.Designer.cs b/ILSpy/Properties/Resources.Designer.cs index 397e5da3a7..07d6d8832b 100644 --- a/ILSpy/Properties/Resources.Designer.cs +++ b/ILSpy/Properties/Resources.Designer.cs @@ -495,6 +495,15 @@ public static string CheckUpdates { } } + /// + /// Looks up a localized string similar to Clear assembly list. + /// + public static string ClearAssemblyList { + get { + return ResourceManager.GetString("ClearAssemblyList", resourceCulture); + } + } + /// /// Looks up a localized string similar to Close. /// diff --git a/ILSpy/Properties/Resources.resx b/ILSpy/Properties/Resources.resx index 6623f03530..e7bc5c4e7a 100644 --- a/ILSpy/Properties/Resources.resx +++ b/ILSpy/Properties/Resources.resx @@ -186,6 +186,9 @@ Are you sure you want to continue? Checking... + + Clear assembly list + Close