diff --git a/ILSpy/AssemblyListManager.cs b/ILSpy/AssemblyListManager.cs index 7c989f4eb..1dd6ebd5d 100644 --- a/ILSpy/AssemblyListManager.cs +++ b/ILSpy/AssemblyListManager.cs @@ -30,21 +30,24 @@ namespace ICSharpCode.ILSpy /// sealed class AssemblyListManager { + readonly ILSpySettings spySettings; + public AssemblyListManager(ILSpySettings spySettings) { + this.spySettings = spySettings; XElement doc = spySettings["AssemblyLists"]; foreach (var list in doc.Elements("List")) { AssemblyLists.Add((string)list.Attribute("name")); } } - public readonly ObservableCollection AssemblyLists = new ObservableCollection(); + public ObservableCollection AssemblyLists { get; } = new ObservableCollection(); /// /// Loads an assembly list from the ILSpySettings. /// If no list with the specified name is found, the default list is loaded instead. /// - public AssemblyList LoadList(ILSpySettings spySettings, string listName) + public AssemblyList LoadList(string listName) { AssemblyList list = DoLoadList(spySettings, listName); if (!AssemblyLists.Contains(list.ListName)) diff --git a/ILSpy/MainWindow.xaml b/ILSpy/MainWindow.xaml index 212c192b5..d52b09892 100644 --- a/ILSpy/MainWindow.xaml +++ b/ILSpy/MainWindow.xaml @@ -6,7 +6,6 @@ xmlns:local="clr-namespace:ICSharpCode.ILSpy" xmlns:avalondock="http://schemas.xceed.com/wpf/xaml/avalondock" xmlns:controls="clr-namespace:ICSharpCode.ILSpy.Controls" - xmlns:avalondockproperties="clr-namespace:Xceed.Wpf.AvalonDock.Properties;assembly=Xceed.Wpf.AvalonDock" xmlns:docking="clr-namespace:ICSharpCode.ILSpy.Docking" xmlns:textview="clr-namespace:ICSharpCode.ILSpy.TextView" xmlns:analyzers="clr-namespace:ICSharpCode.ILSpy.Analyzers" @@ -121,6 +120,10 @@ + + diff --git a/ILSpy/MainWindow.xaml.cs b/ILSpy/MainWindow.xaml.cs index c9b2612aa..d9c11e41f 100644 --- a/ILSpy/MainWindow.xaml.cs +++ b/ILSpy/MainWindow.xaml.cs @@ -24,6 +24,7 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection.Metadata; +using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using System.Windows; @@ -56,6 +57,7 @@ namespace ICSharpCode.ILSpy { public DockWorkspace Workspace { get; set; } public SessionSettings SessionSettings { get; set; } + public AssemblyListManager AssemblyListManager { get; set; } } /// @@ -113,13 +115,15 @@ namespace ICSharpCode.ILSpy this.DataContext = new MainWindowDataContext { Workspace = DockWorkspace.Instance, - SessionSettings = sessionSettings + SessionSettings = sessionSettings, + AssemblyListManager = assemblyListManager }; DockWorkspace.Instance.LoadSettings(sessionSettings); InitializeComponent(); DockWorkspace.Instance.InitializeLayout(DockManager); sessionSettings.FilterSettings.PropertyChanged += filterSettings_PropertyChanged; + sessionSettings.PropertyChanged += SessionSettings_PropertyChanged; InitMainMenu(); InitToolbar(); @@ -128,6 +132,13 @@ namespace ICSharpCode.ILSpy this.Loaded += MainWindow_Loaded; } + private void SessionSettings_PropertyChanged(object sender, PropertyChangedEventArgs e) + { + if (e.PropertyName == "ActiveAssemblyList") { + ShowAssemblyList(sessionSettings.ActiveAssemblyList); + } + } + void SetWindowBounds(Rect bounds) { this.Left = bounds.Left; @@ -376,7 +387,7 @@ namespace ICSharpCode.ILSpy } else if (spySettings != null) { SharpTreeNode node = null; if (activeTreeViewPath?.Length > 0) { - foreach (var asm in assemblyList.GetAssemblies()) { + foreach (var asm in CurrentAssemblyList.GetAssemblies()) { if (asm.FileName == activeTreeViewPath[0]) { // FindNodeByPath() blocks the UI if the assembly is not yet loaded, // so use an async wait instead. @@ -466,7 +477,7 @@ namespace ICSharpCode.ILSpy if (loadPreviousAssemblies) { // Load AssemblyList only in Loaded event so that WPF is initialized before we start the CPU-heavy stuff. // This makes the UI come up a bit faster. - this.assemblyList = assemblyListManager.LoadList(spySettings, sessionSettings.ActiveAssemblyList); + this.assemblyList = assemblyListManager.LoadList(sessionSettings.ActiveAssemblyList); } else { this.assemblyList = new AssemblyList(AssemblyListManager.DefaultListName); assemblyListManager.ClearAll(); @@ -584,8 +595,7 @@ namespace ICSharpCode.ILSpy public void ShowAssemblyList(string name) { - ILSpySettings settings = ILSpySettings.Load(); - AssemblyList list = this.assemblyListManager.LoadList(settings, name); + AssemblyList list = this.assemblyListManager.LoadList(name); //Only load a new list when it is a different one if (list.ListName != CurrentAssemblyList.ListName) { ShowAssemblyList(list); @@ -906,7 +916,7 @@ namespace ICSharpCode.ILSpy try { refreshInProgress = true; var path = GetPathForNode(treeView.SelectedItem as SharpTreeNode); - ShowAssemblyList(assemblyListManager.LoadList(ILSpySettings.Load(), assemblyList.ListName)); + ShowAssemblyList(assemblyListManager.LoadList(assemblyList.ListName)); SelectNode(FindNodeByPath(path, true)); } finally { refreshInProgress = false; diff --git a/ILSpy/Properties/Resources.Designer.cs b/ILSpy/Properties/Resources.Designer.cs index bfa98006d..35ddfdfd2 100644 --- a/ILSpy/Properties/Resources.Designer.cs +++ b/ILSpy/Properties/Resources.Designer.cs @@ -1710,6 +1710,15 @@ namespace ICSharpCode.ILSpy.Properties { } } + /// + /// Looks up a localized string similar to Select a list of assemblies. + /// + public static string SelectAssemblyListDropdownTooltip { + get { + return ResourceManager.GetString("SelectAssemblyListDropdownTooltip", resourceCulture); + } + } + /// /// Looks up a localized string similar to Select language to decompile to. /// diff --git a/ILSpy/Properties/Resources.resx b/ILSpy/Properties/Resources.resx index c7e3398ea..f83bc46f1 100644 --- a/ILSpy/Properties/Resources.resx +++ b/ILSpy/Properties/Resources.resx @@ -808,4 +808,7 @@ Are you sure you want to continue? Do you really want to load the default settings for the active page? + + Select a list of assemblies + \ No newline at end of file diff --git a/ILSpy/SessionSettings.cs b/ILSpy/SessionSettings.cs index b05a45e23..bd7faa5cf 100644 --- a/ILSpy/SessionSettings.cs +++ b/ILSpy/SessionSettings.cs @@ -20,6 +20,7 @@ using System; using System.ComponentModel; using System.Globalization; using System.Linq; +using System.Runtime.CompilerServices; using System.Text; using System.Text.RegularExpressions; using System.Windows; @@ -63,10 +64,9 @@ namespace ICSharpCode.ILSpy public event PropertyChangedEventHandler PropertyChanged; - void OnPropertyChanged(string propertyName) + void OnPropertyChanged([CallerMemberName] string propertyName = null) { - if (PropertyChanged != null) - PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } public FilterSettings FilterSettings { get; private set; } @@ -75,7 +75,15 @@ namespace ICSharpCode.ILSpy public string[] ActiveTreeViewPath; public string ActiveAutoLoadedAssembly; - public string ActiveAssemblyList; + public string ActiveAssemblyList { + get => activeAssemblyList; + set { + if (value != activeAssemblyList) { + activeAssemblyList = value; + OnPropertyChanged(); + } + } + } public WindowState WindowState = WindowState.Normal; public Rect WindowBounds; @@ -118,6 +126,7 @@ namespace ICSharpCode.ILSpy } static Regex regex = new Regex("\\\\x(?[0-9A-f]{4})"); + private string activeAssemblyList; static string Escape(string p) {