diff --git a/ICSharpCode.ILSpyX/Analyzers/IAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/IAnalyzer.cs index d21a871837..e028e4b7fd 100644 --- a/ICSharpCode.ILSpyX/Analyzers/IAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/IAnalyzer.cs @@ -42,6 +42,7 @@ public interface IAnalyzer public interface IAnalyzerMetadata { string Header { get; } + int Order { get; } } } diff --git a/ILSpy/AboutPage.cs b/ILSpy/AboutPage.cs index eb8007ce9d..319017fe06 100644 --- a/ILSpy/AboutPage.cs +++ b/ILSpy/AboutPage.cs @@ -78,14 +78,14 @@ private void Display(DecompilerTextView textView) HorizontalAlignment = HorizontalAlignment.Center, Orientation = Orientation.Horizontal }; - if (NotifyOfUpdatesStrategy.LatestAvailableVersion == null) + if (UpdateService.LatestAvailableVersion == null) { AddUpdateCheckButton(stackPanel, textView); } else { // we already retrieved the latest version sometime earlier - ShowAvailableVersion(NotifyOfUpdatesStrategy.LatestAvailableVersion, stackPanel); + ShowAvailableVersion(UpdateService.LatestAvailableVersion, stackPanel); } CheckBox checkBox = new() { Margin = new Thickness(4), @@ -171,7 +171,7 @@ static void AddUpdateCheckButton(StackPanel stackPanel, DecompilerTextView textV try { - AvailableVersionInfo vInfo = await NotifyOfUpdatesStrategy.GetLatestVersionAsync(); + AvailableVersionInfo vInfo = await UpdateService.GetLatestVersionAsync(); stackPanel.Children.Clear(); ShowAvailableVersion(vInfo, stackPanel); } diff --git a/ILSpy/App.xaml.cs b/ILSpy/App.xaml.cs index 17fc0961c3..c82af3125e 100644 --- a/ILSpy/App.xaml.cs +++ b/ILSpy/App.xaml.cs @@ -25,8 +25,6 @@ using System.Runtime.Loader; using System.Threading.Tasks; using System.Windows; -using System.Windows.Documents; -using System.Windows.Navigation; using System.Windows.Threading; using ICSharpCode.ILSpy.AppEnv; @@ -135,7 +133,7 @@ public App() public new MainWindow MainWindow { get => (MainWindow)base.MainWindow; - set => base.MainWindow = value; + private set => base.MainWindow = value; } private static void SingleInstance_NewInstanceDetected(object sender, NewInstanceEventArgs e) => ExportProvider.GetExportedValue().HandleSingleInstanceCommandLineArguments(e.Args).HandleExceptions(); diff --git a/ILSpy/AssemblyTree/AssemblyTreeModel.cs b/ILSpy/AssemblyTree/AssemblyTreeModel.cs index c908c3fc1d..a212e763e0 100644 --- a/ILSpy/AssemblyTree/AssemblyTreeModel.cs +++ b/ILSpy/AssemblyTree/AssemblyTreeModel.cs @@ -303,7 +303,7 @@ private async Task NavigateOnLaunch(string? navigateTo, string[]? activeTreeView SelectNode(node); // only if not showing the about page, perform the update check: - await App.Current.MainWindow.ShowMessageIfUpdatesAvailableAsync(updateSettings); + MessageBus.Send(this, new CheckIfUpdateAvailableEventArgs()); } else { diff --git a/ILSpy/Commands/CheckForUpdatesCommand.cs b/ILSpy/Commands/CheckForUpdatesCommand.cs index 54fb1ac8a1..83923cde97 100644 --- a/ILSpy/Commands/CheckForUpdatesCommand.cs +++ b/ILSpy/Commands/CheckForUpdatesCommand.cs @@ -20,7 +20,6 @@ using System.Composition; using ICSharpCode.ILSpy.Properties; -using ICSharpCode.ILSpy.Updates; namespace ICSharpCode.ILSpy { @@ -30,7 +29,7 @@ sealed class CheckForUpdatesCommand(SettingsService settingsService) : SimpleCom { public override async void Execute(object parameter) { - await App.Current.MainWindow.ShowMessageIfUpdatesAvailableAsync(settingsService.GetSettings(), forceCheck: true); + MessageBus.Send(this, new CheckIfUpdateAvailableEventArgs(notify: true)); } } } diff --git a/ILSpy/Commands/ExitCommand.cs b/ILSpy/Commands/ExitCommand.cs index 67f698bfee..91483d829b 100644 --- a/ILSpy/Commands/ExitCommand.cs +++ b/ILSpy/Commands/ExitCommand.cs @@ -23,11 +23,11 @@ namespace ICSharpCode.ILSpy { [ExportMainMenuCommand(ParentMenuID = nameof(Resources._File), Header = nameof(Resources.E_xit), MenuOrder = 99999, MenuCategory = nameof(Resources.Exit))] [Shared] - sealed class ExitCommand : SimpleCommand + sealed class ExitCommand(MainWindow mainWindow) : SimpleCommand { public override void Execute(object parameter) { - App.Current.MainWindow.Close(); + mainWindow.Close(); } } } \ No newline at end of file diff --git a/ILSpy/Commands/ManageAssemblyListsCommand.cs b/ILSpy/Commands/ManageAssemblyListsCommand.cs index 8172f2182b..02eb5284cc 100644 --- a/ILSpy/Commands/ManageAssemblyListsCommand.cs +++ b/ILSpy/Commands/ManageAssemblyListsCommand.cs @@ -18,6 +18,8 @@ using System.Composition; +using System.Windows; +using System.Windows.Data; using ICSharpCode.ILSpy.Properties; @@ -25,13 +27,21 @@ namespace ICSharpCode.ILSpy { [ExportMainMenuCommand(ParentMenuID = nameof(Resources._File), Header = nameof(Resources.ManageAssembly_Lists), MenuIcon = "Images/AssemblyList", MenuCategory = nameof(Resources.Open), MenuOrder = 1.7)] [Shared] - sealed class ManageAssemblyListsCommand(SettingsService settingsService) : SimpleCommand + sealed class ManageAssemblyListsCommand(SettingsService settingsService) : SimpleCommand, IProvideParameterBinding { public override void Execute(object parameter) { - ManageAssemblyListsDialog dlg = new ManageAssemblyListsDialog(settingsService); - dlg.Owner = App.Current.MainWindow; + ManageAssemblyListsDialog dlg = new(settingsService) { + Owner = parameter as Window + }; + dlg.ShowDialog(); } + + public Binding ParameterBinding => new() { + RelativeSource = new(RelativeSourceMode.FindAncestor) { + AncestorType = typeof(Window) + } + }; } } diff --git a/ILSpy/Commands/OpenFromGacCommand.cs b/ILSpy/Commands/OpenFromGacCommand.cs index ba65bfe214..b66e1c644a 100644 --- a/ILSpy/Commands/OpenFromGacCommand.cs +++ b/ILSpy/Commands/OpenFromGacCommand.cs @@ -26,15 +26,8 @@ namespace ICSharpCode.ILSpy { [ExportMainMenuCommand(ParentMenuID = nameof(Resources._File), Header = nameof(Resources.OpenFrom_GAC), MenuIcon = "Images/AssemblyListGAC", MenuCategory = nameof(Resources.Open), MenuOrder = 1)] [Shared] - sealed class OpenFromGacCommand : SimpleCommand + sealed class OpenFromGacCommand(AssemblyTreeModel assemblyTreeModel, MainWindow mainWindow) : SimpleCommand { - private readonly AssemblyTreeModel assemblyTreeModel; - - public OpenFromGacCommand(AssemblyTreeModel assemblyTreeModel) - { - this.assemblyTreeModel = assemblyTreeModel; - } - public override bool CanExecute(object parameter) { return AppEnvironment.IsWindows; @@ -42,8 +35,8 @@ public override bool CanExecute(object parameter) public override void Execute(object parameter) { - OpenFromGacDialog dlg = new OpenFromGacDialog { - Owner = App.Current.MainWindow + OpenFromGacDialog dlg = new() { + Owner = mainWindow }; if (dlg.ShowDialog() == true) diff --git a/ILSpy/Commands/SimpleCommand.cs b/ILSpy/Commands/SimpleCommand.cs index 67c7f517e1..19c1c7c9ec 100644 --- a/ILSpy/Commands/SimpleCommand.cs +++ b/ILSpy/Commands/SimpleCommand.cs @@ -17,7 +17,7 @@ // DEALINGS IN THE SOFTWARE. using System; -using System.ComponentModel; +using System.Windows.Data; using System.Windows.Input; namespace ICSharpCode.ILSpy @@ -37,38 +37,8 @@ public virtual bool CanExecute(object parameter) } } - public abstract class ToggleableCommand : ICommand, INotifyPropertyChanged + public interface IProvideParameterBinding { - private bool isChecked; - - public event EventHandler CanExecuteChanged { - add { CommandManager.RequerySuggested += value; } - remove { CommandManager.RequerySuggested -= value; } - } - - public event PropertyChangedEventHandler PropertyChanged; - - void ICommand.Execute(object parameter) - { - IsChecked = Execute(parameter); - } - - public bool IsChecked { - get => isChecked; - set { - if (isChecked != value) - { - isChecked = value; - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsChecked))); - } - } - } - - public abstract bool Execute(object parameter); - - public virtual bool CanExecute(object parameter) - { - return true; - } + Binding ParameterBinding { get; } } } diff --git a/ILSpy/Docking/DockWorkspace.cs b/ILSpy/Docking/DockWorkspace.cs index d9f3b85c32..d92b928476 100644 --- a/ILSpy/Docking/DockWorkspace.cs +++ b/ILSpy/Docking/DockWorkspace.cs @@ -33,7 +33,6 @@ using ICSharpCode.AvalonEdit.Highlighting; using ICSharpCode.ILSpy.Analyzers; -using ICSharpCode.ILSpy.AssemblyTree; using ICSharpCode.ILSpy.Search; using ICSharpCode.ILSpy.TextView; using ICSharpCode.ILSpy.ViewModels; @@ -50,17 +49,17 @@ public class DockWorkspace : ObservableObject, ILayoutUpdateStrategy { private readonly IExportProvider exportProvider; - private SessionSettings SessionSettings { get; } - private readonly ObservableCollection tabPages = []; + readonly SessionSettings sessionSettings; + private DockingManager DockingManager => exportProvider.GetExportedValue(); public DockWorkspace(SettingsService settingsService, IExportProvider exportProvider) { this.exportProvider = exportProvider; - SessionSettings = settingsService.SessionSettings; + sessionSettings = settingsService.SessionSettings; this.tabPages.CollectionChanged += TabPages_CollectionChanged; TabPages = new(tabPages); @@ -70,10 +69,9 @@ public DockWorkspace(SettingsService settingsService, IExportProvider exportProv private void CurrentAssemblyList_Changed(object sender, NotifyCollectionChangedEventArgs e) { - if (e.OldItems == null) - { + if (e.OldItems is not { } oldItems) return; - } + foreach (var tab in tabPages.ToArray()) { var state = tab.GetState(); @@ -84,7 +82,7 @@ private void CurrentAssemblyList_Changed(object sender, NotifyCollectionChangedE bool found = decompiledNodes .Select(node => node.Ancestors().OfType().LastOrDefault()) .ExceptNullItems() - .Any(assemblyNode => !e.OldItems.Contains(assemblyNode.LoadedAssembly)); + .Any(assemblyNode => !oldItems.Contains(assemblyNode.LoadedAssembly)); if (!found) { @@ -190,7 +188,7 @@ public void InitializeLayout() serializer.LayoutSerializationCallback += LayoutSerializationCallback; try { - SessionSettings.DockLayout.Deserialize(serializer); + sessionSettings.DockLayout.Deserialize(serializer); } finally { @@ -247,7 +245,7 @@ internal void ResetLayout() pane.IsVisible = false; } CloseAllTabs(); - SessionSettings.DockLayout.Reset(); + sessionSettings.DockLayout.Reset(); InitializeLayout(); App.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, () => MessageBus.Send(this, new ResetLayoutEventArgs())); diff --git a/ILSpy/MainWindow.xaml b/ILSpy/MainWindow.xaml index b0a437d439..3223ee1ff8 100644 --- a/ILSpy/MainWindow.xaml +++ b/ILSpy/MainWindow.xaml @@ -50,8 +50,9 @@ - - + + + @@ -63,7 +64,7 @@