diff --git a/ICSharpCode.ILSpyX/AssemblyListManager.cs b/ICSharpCode.ILSpyX/AssemblyListManager.cs index 83f264f6d..8a886df5f 100644 --- a/ICSharpCode.ILSpyX/AssemblyListManager.cs +++ b/ICSharpCode.ILSpyX/AssemblyListManager.cs @@ -56,6 +56,7 @@ namespace ICSharpCode.ILSpyX } public bool ApplyWinRTProjections { get; set; } + public bool UseDebugSymbols { get; set; } public ObservableCollection AssemblyLists { get; } = new ObservableCollection(); diff --git a/ILSpy.ReadyToRun/ReadyToRunLanguage.cs b/ILSpy.ReadyToRun/ReadyToRunLanguage.cs index 410e49b67..b201a6608 100644 --- a/ILSpy.ReadyToRun/ReadyToRunLanguage.cs +++ b/ILSpy.ReadyToRun/ReadyToRunLanguage.cs @@ -33,6 +33,7 @@ using ICSharpCode.Decompiler; using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.Solution; using ICSharpCode.Decompiler.TypeSystem; +using ICSharpCode.ILSpy.Util; using ICSharpCode.ILSpyX; using ILCompiler.Reflection.ReadyToRun; @@ -174,7 +175,7 @@ namespace ICSharpCode.ILSpy.ReadyToRun .GroupBy(m => m.MethodHandle) .ToDictionary(g => g.Key, g => g.ToArray()); } - var displaySettings = MainWindow.Instance.CurrentDisplaySettings; + var displaySettings = SettingsService.Instance.DisplaySettings; bool showMetadataTokens = displaySettings.ShowMetadataTokens; bool showMetadataTokensInBase10 = displaySettings.ShowMetadataTokensInBase10; #if STRESS diff --git a/ILSpy/App.xaml.cs b/ILSpy/App.xaml.cs index d0b08f0f5..c136891a1 100644 --- a/ILSpy/App.xaml.cs +++ b/ILSpy/App.xaml.cs @@ -201,7 +201,8 @@ namespace ICSharpCode.ILSpy protected override void OnStartup(StartupEventArgs e) { var output = new StringBuilder(); - if (ILSpy.MainWindow.FormatExceptions(StartupExceptions.ToArray(), output)) + + if (StartupExceptions.FormatExceptions(output)) { MessageBox.Show(output.ToString(), "Sorry we crashed!"); Environment.Exit(1); diff --git a/ILSpy/ExtensionMethods.cs b/ILSpy/ExtensionMethods.cs index 68c604a0d..374ad026e 100644 --- a/ILSpy/ExtensionMethods.cs +++ b/ILSpy/ExtensionMethods.cs @@ -20,12 +20,14 @@ using System; using System.Collections.Generic; +using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.TypeSystem; +using ICSharpCode.ILSpy.Util; using ICSharpCode.ILSpyX; namespace ICSharpCode.ILSpy @@ -75,7 +77,7 @@ namespace ICSharpCode.ILSpy public static ICompilation? GetTypeSystemWithCurrentOptionsOrNull(this MetadataFile file) { return LoadedAssemblyExtensions.GetLoadedAssembly(file) - .GetTypeSystemOrNull(DecompilerTypeSystem.GetOptions(MainWindow.Instance.CurrentDecompilerSettings)); + .GetTypeSystemOrNull(DecompilerTypeSystem.GetOptions(SettingsService.Instance.DecompilerSettings)); } #region DPI independence @@ -162,5 +164,34 @@ namespace ICSharpCode.ILSpy { return color?.R * 0.3 + color?.G * 0.6 + color?.B * 0.1 ?? 0.0; } + + internal static bool FormatExceptions(this IList exceptions, StringBuilder output) + { + if (exceptions.Count == 0) + return false; + bool first = true; + + foreach (var item in exceptions) + { + if (first) + first = false; + else + output.AppendLine("-------------------------------------------------"); + output.AppendLine("Error(s) loading plugin: " + item.PluginName); + if (item.Exception is System.Reflection.ReflectionTypeLoadException) + { + var e = (System.Reflection.ReflectionTypeLoadException)item.Exception; + foreach (var ex in e.LoaderExceptions) + { + output.AppendLine(ex.ToString()); + output.AppendLine(); + } + } + else + output.AppendLine(item.Exception.ToString()); + } + + return true; + } } } diff --git a/ILSpy/Languages/CSharpILMixedLanguage.cs b/ILSpy/Languages/CSharpILMixedLanguage.cs index 31975cc24..4f7ca57cc 100644 --- a/ILSpy/Languages/CSharpILMixedLanguage.cs +++ b/ILSpy/Languages/CSharpILMixedLanguage.cs @@ -34,6 +34,7 @@ using ICSharpCode.Decompiler.Disassembler; using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.Util; +using ICSharpCode.ILSpy.Util; using ICSharpCode.ILSpyX; using ICSharpCode.ILSpyX.Extensions; @@ -49,7 +50,7 @@ namespace ICSharpCode.ILSpy protected override ReflectionDisassembler CreateDisassembler(ITextOutput output, DecompilationOptions options) { - var displaySettings = MainWindow.Instance.CurrentDisplaySettings; + var displaySettings = SettingsService.Instance.DisplaySettings; return new ReflectionDisassembler(output, new MixedMethodBodyDisassembler(output, options) { DetectControlStructure = detectControlStructure, diff --git a/ILSpy/Languages/CSharpLanguage.cs b/ILSpy/Languages/CSharpLanguage.cs index dcf7e91a2..df801511c 100644 --- a/ILSpy/Languages/CSharpLanguage.cs +++ b/ILSpy/Languages/CSharpLanguage.cs @@ -41,6 +41,7 @@ using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.Util; using ICSharpCode.ILSpy.TextView; using ICSharpCode.ILSpy.TreeNodes; +using ICSharpCode.ILSpy.Util; using ICSharpCode.ILSpyX; using LanguageVersion = ICSharpCode.ILSpyX.LanguageVersion; @@ -572,7 +573,7 @@ namespace ICSharpCode.ILSpy CSharpAmbience ambience = new CSharpAmbience(); // Do not forget to update CSharpAmbienceTests.ILSpyMainTreeViewTypeFlags, if this ever changes. ambience.ConversionFlags = ConversionFlags.ShowTypeParameterList | ConversionFlags.PlaceReturnTypeAfterParameterList; - if (MainWindow.Instance.CurrentDecompilerSettings.LiftNullables) + if (SettingsService.Instance.DecompilerSettings.LiftNullables) { ambience.ConversionFlags |= ConversionFlags.UseNullableSpecifierForValueTypes; } @@ -775,7 +776,7 @@ namespace ICSharpCode.ILSpy public override bool ShowMember(IEntity member) { MetadataFile assembly = member.ParentModule.MetadataFile; - return showAllMembers || !CSharpDecompiler.MemberIsHidden(assembly, member.MetadataToken, MainWindow.Instance.CurrentDecompilerSettings); + return showAllMembers || !CSharpDecompiler.MemberIsHidden(assembly, member.MetadataToken, SettingsService.Instance.DecompilerSettings); } public override RichText GetRichTextTooltip(IEntity entity) @@ -784,7 +785,7 @@ namespace ICSharpCode.ILSpy var output = new StringWriter(); var decoratedWriter = new TextWriterTokenWriter(output); var writer = new CSharpHighlightingTokenWriter(TokenWriter.InsertRequiredSpaces(decoratedWriter), locatable: decoratedWriter); - var settings = MainWindow.Instance.CurrentDecompilerSettings; + var settings = SettingsService.Instance.DecompilerSettings; if (!settings.LiftNullables) { flags &= ~ConversionFlags.UseNullableSpecifierForValueTypes; diff --git a/ILSpy/Languages/ILLanguage.cs b/ILSpy/Languages/ILLanguage.cs index ab8f89ab7..22d060b37 100644 --- a/ILSpy/Languages/ILLanguage.cs +++ b/ILSpy/Languages/ILLanguage.cs @@ -30,6 +30,7 @@ using ICSharpCode.Decompiler.Solution; using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.Util; using ICSharpCode.ILSpy.TextView; +using ICSharpCode.ILSpy.Util; using ICSharpCode.ILSpyX; namespace ICSharpCode.ILSpy @@ -57,7 +58,7 @@ namespace ICSharpCode.ILSpy protected virtual ReflectionDisassembler CreateDisassembler(ITextOutput output, DecompilationOptions options) { - var displaySettings = MainWindow.Instance.CurrentDisplaySettings; + var displaySettings = SettingsService.Instance.DisplaySettings; output.IndentationString = options.DecompilerSettings.CSharpFormattingOptions.IndentationString; return new ReflectionDisassembler(output, options.CancellationToken) { DetectControlStructure = detectControlStructure, diff --git a/ILSpy/MainWindow.xaml.cs b/ILSpy/MainWindow.xaml.cs index 810e70f99..d87bd31ff 100644 --- a/ILSpy/MainWindow.xaml.cs +++ b/ILSpy/MainWindow.xaml.cs @@ -83,8 +83,6 @@ namespace ICSharpCode.ILSpy get { return instance; } } - internal AssemblyListManager AssemblyListManager { get; } - public SharpTreeView AssemblyTreeView { get { return FindResource("AssemblyTreeView") as SharpTreeView; @@ -97,40 +95,28 @@ namespace ICSharpCode.ILSpy } } - public DecompilerSettings CurrentDecompilerSettings { get; internal set; } - - public DisplaySettingsViewModel CurrentDisplaySettings { get; internal set; } - public DecompilationOptions CreateDecompilationOptions() { var decompilerView = DockWorkspace.Instance.ActiveTabPage.Content as IProgress; - return new DecompilationOptions(CurrentLanguageVersion, CurrentDecompilerSettings, CurrentDisplaySettings) { Progress = decompilerView }; + return new DecompilationOptions(CurrentLanguageVersion, SettingsService.Instance.DecompilerSettings, SettingsService.Instance.DisplaySettings) { Progress = decompilerView }; } public MainWindow() { instance = this; - var spySettings = SettingsService.Instance.SpySettings; var sessionSettings = SettingsService.Instance.SessionSettings; - this.CurrentDecompilerSettings = DecompilerSettingsPanel.LoadDecompilerSettings(spySettings); - this.CurrentDisplaySettings = DisplaySettingsPanel.LoadDisplaySettings(spySettings); - this.AssemblyListManager = new AssemblyListManager(spySettings) { - ApplyWinRTProjections = CurrentDecompilerSettings.ApplyWindowsRuntimeProjections, - UseDebugSymbols = CurrentDecompilerSettings.UseDebugSymbols - }; - // Make sure Images are initialized on the UI thread. this.Icon = Images.ILSpyIcon; this.DataContext = new MainWindowViewModel { Workspace = DockWorkspace.Instance, SessionSettings = sessionSettings, - AssemblyListManager = AssemblyListManager + AssemblyListManager = SettingsService.Instance.AssemblyListManager }; - AssemblyListManager.CreateDefaultAssemblyLists(); + SettingsService.Instance.AssemblyListManager.CreateDefaultAssemblyLists(); if (!string.IsNullOrEmpty(sessionSettings.CurrentCulture)) { System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(sessionSettings.CurrentCulture); @@ -840,12 +826,12 @@ namespace ICSharpCode.ILSpy { // 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(sessionSettings.ActiveAssemblyList); + this.assemblyList = SettingsService.Instance.AssemblyListManager.LoadList(sessionSettings.ActiveAssemblyList); } else { - AssemblyListManager.ClearAll(); - this.assemblyList = AssemblyListManager.CreateList(AssemblyListManager.DefaultListName); + SettingsService.Instance.AssemblyListManager.ClearAll(); + this.assemblyList = SettingsService.Instance.AssemblyListManager.CreateList(AssemblyListManager.DefaultListName); } HandleCommandLineArguments(App.CommandLineArguments); @@ -877,10 +863,10 @@ namespace ICSharpCode.ILSpy DockWorkspace.Instance.ShowText(output); } - bool FormatExceptions(App.ExceptionData[] exceptions, ITextOutput output) + static bool FormatExceptions(App.ExceptionData[] exceptions, ITextOutput output) { var stringBuilder = new StringBuilder(); - var result = FormatExceptions(exceptions, stringBuilder); + var result = exceptions.FormatExceptions(stringBuilder); if (result) { output.Write(stringBuilder.ToString()); @@ -888,35 +874,6 @@ namespace ICSharpCode.ILSpy return result; } - internal static bool FormatExceptions(App.ExceptionData[] exceptions, StringBuilder output) - { - if (exceptions.Length == 0) - return false; - bool first = true; - - foreach (var item in exceptions) - { - if (first) - first = false; - else - output.AppendLine("-------------------------------------------------"); - output.AppendLine("Error(s) loading plugin: " + item.PluginName); - if (item.Exception is System.Reflection.ReflectionTypeLoadException) - { - var e = (System.Reflection.ReflectionTypeLoadException)item.Exception; - foreach (var ex in e.LoaderExceptions) - { - output.AppendLine(ex.ToString()); - output.AppendLine(); - } - } - else - output.AppendLine(item.Exception.ToString()); - } - - return true; - } - #region Update Check string updateAvailableDownloadUrl; @@ -974,7 +931,7 @@ namespace ICSharpCode.ILSpy public void ShowAssemblyList(string name) { - AssemblyList list = this.AssemblyListManager.LoadList(name); + AssemblyList list = SettingsService.Instance.AssemblyListManager.LoadList(name); //Only load a new list when it is a different one if (list.ListName != CurrentAssemblyList.ListName) { @@ -1388,7 +1345,7 @@ namespace ICSharpCode.ILSpy { refreshInProgress = true; var path = GetPathForNode(AssemblyTreeView.SelectedItem as SharpTreeNode); - ShowAssemblyList(AssemblyListManager.LoadList(assemblyList.ListName)); + ShowAssemblyList(SettingsService.Instance.AssemblyListManager.LoadList(assemblyList.ListName)); SelectNode(FindNodeByPath(path, true), inNewTabPage: false, AssemblyTreeView.IsFocused); } finally diff --git a/ILSpy/Metadata/DebugMetadataTablesTreeNode.cs b/ILSpy/Metadata/DebugMetadataTablesTreeNode.cs index af8dd974a..9ec211751 100644 --- a/ILSpy/Metadata/DebugMetadataTablesTreeNode.cs +++ b/ILSpy/Metadata/DebugMetadataTablesTreeNode.cs @@ -21,6 +21,7 @@ using System.Reflection.Metadata.Ecma335; using ICSharpCode.Decompiler; using ICSharpCode.Decompiler.Metadata; using ICSharpCode.ILSpy.TreeNodes; +using ICSharpCode.ILSpy.Util; using ICSharpCode.ILSpy.ViewModels; namespace ICSharpCode.ILSpy.Metadata @@ -58,7 +59,7 @@ namespace ICSharpCode.ILSpy.Metadata if (ShowTable(TableIndex.CustomDebugInformation)) this.Children.Add(new CustomDebugInformationTableTreeNode(metadataFile)); - bool ShowTable(TableIndex table) => !MainWindow.Instance.CurrentDisplaySettings.HideEmptyMetadataTables || metadataFile.Metadata.GetTableRowCount(table) > 0; + bool ShowTable(TableIndex table) => !SettingsService.Instance.DisplaySettings.HideEmptyMetadataTables || metadataFile.Metadata.GetTableRowCount(table) > 0; } public override bool View(TabPageModel tabPage) diff --git a/ILSpy/Metadata/MetadataTablesTreeNode.cs b/ILSpy/Metadata/MetadataTablesTreeNode.cs index 26bb59b21..1572ed4e3 100644 --- a/ILSpy/Metadata/MetadataTablesTreeNode.cs +++ b/ILSpy/Metadata/MetadataTablesTreeNode.cs @@ -23,6 +23,7 @@ using System.Reflection.Metadata.Ecma335; using ICSharpCode.Decompiler; using ICSharpCode.Decompiler.Metadata; using ICSharpCode.ILSpy.TreeNodes; +using ICSharpCode.ILSpy.Util; using ICSharpCode.ILSpy.ViewModels; namespace ICSharpCode.ILSpy.Metadata @@ -50,7 +51,7 @@ namespace ICSharpCode.ILSpy.Metadata } } - internal static bool ShowTable(TableIndex table, MetadataReader metadata) => !MainWindow.Instance.CurrentDisplaySettings.HideEmptyMetadataTables || metadata.GetTableRowCount(table) > 0; + internal static bool ShowTable(TableIndex table, MetadataReader metadata) => !SettingsService.Instance.DisplaySettings.HideEmptyMetadataTables || metadata.GetTableRowCount(table) > 0; internal static MetadataTableTreeNode CreateTableTreeNode(TableIndex table, MetadataFile metadataFile) { diff --git a/ILSpy/Options/DecompilerSettingsPanel.xaml.cs b/ILSpy/Options/DecompilerSettingsPanel.xaml.cs index 8a55d73fb..d530079dc 100644 --- a/ILSpy/Options/DecompilerSettingsPanel.xaml.cs +++ b/ILSpy/Options/DecompilerSettingsPanel.xaml.cs @@ -19,6 +19,7 @@ using System.ComponentModel.Composition; using System.Xml.Linq; +using ICSharpCode.ILSpy.Util; using ICSharpCode.ILSpyX.Settings; namespace ICSharpCode.ILSpy.Options @@ -50,15 +51,15 @@ namespace ICSharpCode.ILSpy.Options var newSettings = ((DecompilerSettingsViewModel)this.DataContext).ToDecompilerSettings(); ISettingsProvider.SaveDecompilerSettings(root, newSettings); - MainWindow.Instance.CurrentDecompilerSettings = newSettings; - MainWindow.Instance.AssemblyListManager.ApplyWinRTProjections = newSettings.ApplyWindowsRuntimeProjections; - MainWindow.Instance.AssemblyListManager.UseDebugSymbols = newSettings.UseDebugSymbols; + SettingsService.Instance.DecompilerSettings = newSettings; + SettingsService.Instance.AssemblyListManager.ApplyWinRTProjections = newSettings.ApplyWindowsRuntimeProjections; + SettingsService.Instance.AssemblyListManager.UseDebugSymbols = newSettings.UseDebugSymbols; } public void LoadDefaults() { - MainWindow.Instance.CurrentDecompilerSettings = new(); - this.DataContext = new DecompilerSettingsViewModel(MainWindow.Instance.CurrentDecompilerSettings); + SettingsService.Instance.DecompilerSettings = new(); + this.DataContext = new DecompilerSettingsViewModel(SettingsService.Instance.DecompilerSettings); } } } diff --git a/ILSpy/Options/DisplaySettingsPanel.xaml.cs b/ILSpy/Options/DisplaySettingsPanel.xaml.cs index 3e81eb7fe..8358a3cf5 100644 --- a/ILSpy/Options/DisplaySettingsPanel.xaml.cs +++ b/ILSpy/Options/DisplaySettingsPanel.xaml.cs @@ -99,7 +99,7 @@ namespace ICSharpCode.ILSpy.Options select ff).ToArray(); } - public static DisplaySettingsViewModel LoadDisplaySettings(ILSpySettings settings) + public static DisplaySettingsViewModel LoadDisplaySettings(ILSpySettings settings, SessionSettings sessionSettings = null) { XElement e = settings["DisplaySettings"]; var s = new DisplaySettingsViewModel(); @@ -124,7 +124,7 @@ namespace ICSharpCode.ILSpy.Options s.ShowRawOffsetsAndBytesBeforeInstruction = (bool?)e.Attribute("ShowRawOffsetsAndBytesBeforeInstruction") ?? false; s.StyleWindowTitleBar = (bool?)e.Attribute("StyleWindowTitleBar") ?? false; - s.Theme = SettingsService.Instance.SessionSettings.Theme; + s.Theme = (sessionSettings ?? SettingsService.Instance.SessionSettings).Theme; return s; } @@ -158,7 +158,7 @@ namespace ICSharpCode.ILSpy.Options SettingsService.Instance.SessionSettings.Theme = s.Theme; var sessionSettings = SettingsService.Instance.SessionSettings.ToXml(); - MainWindow.Instance.CurrentDisplaySettings.CopyValues(s); + SettingsService.Instance.DisplaySettings.CopyValues(s); Update(section); Update(sessionSettings); @@ -190,8 +190,8 @@ namespace ICSharpCode.ILSpy.Options public void LoadDefaults() { - MainWindow.Instance.CurrentDisplaySettings.CopyValues(new DisplaySettingsViewModel()); - this.DataContext = MainWindow.Instance.CurrentDisplaySettings; + SettingsService.Instance.DisplaySettings.CopyValues(new DisplaySettingsViewModel()); + this.DataContext = SettingsService.Instance.DisplaySettings; } } diff --git a/ILSpy/Search/SearchPane.cs b/ILSpy/Search/SearchPane.cs index f3bd6a550..7c0a2acd9 100644 --- a/ILSpy/Search/SearchPane.cs +++ b/ILSpy/Search/SearchPane.cs @@ -243,7 +243,7 @@ namespace ICSharpCode.ILSpy.Search } MainWindow mainWindow = MainWindow.Instance; - resultsComparer = mainWindow.CurrentDisplaySettings.SortResults ? + resultsComparer = SettingsService.Instance.DisplaySettings.SortResults ? SearchResult.ComparerByFitness : SearchResult.ComparerByName; Results.Clear(); @@ -454,7 +454,7 @@ namespace ICSharpCode.ILSpy.Search request.RegEx = regex; request.SearchResultFactory = new SearchResultFactory(language); request.TreeNodeFactory = new TreeNodeFactory(); - request.DecompilerSettings = MainWindow.Instance.CurrentDecompilerSettings; + request.DecompilerSettings = SettingsService.Instance.DecompilerSettings; return request; } diff --git a/ILSpy/TextView/DecompilerTextView.cs b/ILSpy/TextView/DecompilerTextView.cs index 5d7eb069e..8aaa005ec 100644 --- a/ILSpy/TextView/DecompilerTextView.cs +++ b/ILSpy/TextView/DecompilerTextView.cs @@ -113,9 +113,9 @@ namespace ICSharpCode.ILSpy.TextView textEditor.TextArea.Caret.PositionChanged += HighlightBrackets; textEditor.MouseMove += TextEditorMouseMove; textEditor.MouseLeave += TextEditorMouseLeave; - textEditor.SetBinding(Control.FontFamilyProperty, new Binding { Source = MainWindow.Instance.CurrentDisplaySettings, Path = new PropertyPath("SelectedFont") }); - textEditor.SetBinding(Control.FontSizeProperty, new Binding { Source = MainWindow.Instance.CurrentDisplaySettings, Path = new PropertyPath("SelectedFontSize") }); - textEditor.SetBinding(TextEditor.WordWrapProperty, new Binding { Source = MainWindow.Instance.CurrentDisplaySettings, Path = new PropertyPath("EnableWordWrap") }); + textEditor.SetBinding(Control.FontFamilyProperty, new Binding { Source = SettingsService.Instance.DisplaySettings, Path = new PropertyPath("SelectedFont") }); + textEditor.SetBinding(Control.FontSizeProperty, new Binding { Source = SettingsService.Instance.DisplaySettings, Path = new PropertyPath("SelectedFontSize") }); + textEditor.SetBinding(TextEditor.WordWrapProperty, new Binding { Source = SettingsService.Instance.DisplaySettings, Path = new PropertyPath("EnableWordWrap") }); // disable Tab editing command (useless for read-only editor); allow using tab for focus navigation instead RemoveEditCommand(EditingCommands.TabForward); @@ -125,7 +125,7 @@ namespace ICSharpCode.ILSpy.TextView textEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService); textEditor.TextArea.TextView.LineTransformers.Add(textMarkerService); textEditor.ShowLineNumbers = true; - MainWindow.Instance.CurrentDisplaySettings.PropertyChanged += CurrentDisplaySettings_PropertyChanged; + SettingsService.Instance.DisplaySettings.PropertyChanged += CurrentDisplaySettings_PropertyChanged; // SearchPanel SearchPanel searchPanel = SearchPanel.Install(textEditor.TextArea); @@ -197,14 +197,14 @@ namespace ICSharpCode.ILSpy.TextView { if (margin is LineNumberMargin || margin is System.Windows.Shapes.Line) { - margin.Visibility = MainWindow.Instance.CurrentDisplaySettings.ShowLineNumbers ? Visibility.Visible : Visibility.Collapsed; + margin.Visibility = SettingsService.Instance.DisplaySettings.ShowLineNumbers ? Visibility.Visible : Visibility.Collapsed; } } } void SetHighlightCurrentLine() { - textEditor.Options.HighlightCurrentLine = MainWindow.Instance.CurrentDisplaySettings.HighlightCurrentLine; + textEditor.Options.HighlightCurrentLine = SettingsService.Instance.DisplaySettings.HighlightCurrentLine; } #endregion @@ -485,7 +485,7 @@ namespace ICSharpCode.ILSpy.TextView public FlowDocumentTooltip(FlowDocument document) { TextOptions.SetTextFormattingMode(this, TextFormattingMode.Display); - double fontSize = MainWindow.Instance.CurrentDisplaySettings.SelectedFontSize; + double fontSize = SettingsService.Instance.DisplaySettings.SelectedFontSize; viewer = new FlowDocumentScrollViewer() { Width = document.MinPageWidth + fontSize * 5, MaxWidth = MainWindow.Instance.ActualWidth @@ -532,7 +532,7 @@ namespace ICSharpCode.ILSpy.TextView #region Highlight brackets void HighlightBrackets(object? sender, EventArgs e) { - if (MainWindow.Instance.CurrentDisplaySettings.HighlightMatchingBraces) + if (SettingsService.Instance.DisplaySettings.HighlightMatchingBraces) { var result = SettingsService.Instance.SessionSettings.LanguageSettings.Language.BracketSearcher.SearchBracket(textEditor.Document, textEditor.CaretOffset); bracketHighlightRenderer.SetHighlight(result); @@ -754,7 +754,7 @@ namespace ICSharpCode.ILSpy.TextView { if (state != null) { - state.RestoreFoldings(textOutput.Foldings, MainWindow.Instance.CurrentDisplaySettings.ExpandMemberDefinitions); + state.RestoreFoldings(textOutput.Foldings, SettingsService.Instance.DisplaySettings.ExpandMemberDefinitions); textEditor.ScrollToVerticalOffset(state.VerticalOffset); textEditor.ScrollToHorizontalOffset(state.HorizontalOffset); } @@ -778,7 +778,7 @@ namespace ICSharpCode.ILSpy.TextView } currentAddress = textOutput.Address; currentTitle = textOutput.Title; - expandMemberDefinitions = MainWindow.Instance.CurrentDisplaySettings.ExpandMemberDefinitions; + expandMemberDefinitions = SettingsService.Instance.DisplaySettings.ExpandMemberDefinitions; } #endregion @@ -1289,7 +1289,7 @@ namespace ICSharpCode.ILSpy.TextView public void Dispose() { - MainWindow.Instance.CurrentDisplaySettings.PropertyChanged -= CurrentDisplaySettings_PropertyChanged; + SettingsService.Instance.DisplaySettings.PropertyChanged -= CurrentDisplaySettings_PropertyChanged; } #region Unfold diff --git a/ILSpy/TextView/DocumentationUIBuilder.cs b/ILSpy/TextView/DocumentationUIBuilder.cs index 41cad9d61..bc7a9a409 100644 --- a/ILSpy/TextView/DocumentationUIBuilder.cs +++ b/ILSpy/TextView/DocumentationUIBuilder.cs @@ -37,6 +37,7 @@ using ICSharpCode.Decompiler.Documentation; using ICSharpCode.Decompiler.Output; using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.ILSpy.Options; +using ICSharpCode.ILSpy.Util; namespace ICSharpCode.ILSpy.TextView { @@ -115,7 +116,7 @@ namespace ICSharpCode.ILSpy.TextView // Paragraph sadly does not support TextWrapping.NoWrap var text = new TextBlock { FontFamily = GetCodeFont(), - FontSize = MainWindow.Instance.CurrentDisplaySettings.SelectedFontSize, + FontSize = SettingsService.Instance.DisplaySettings.SelectedFontSize, TextAlignment = TextAlignment.Left }; text.Inlines.AddRange(richText.CreateRuns(document)); @@ -435,7 +436,7 @@ namespace ICSharpCode.ILSpy.TextView FontFamily GetCodeFont() { - return MainWindow.Instance.CurrentDisplaySettings.SelectedFont; + return SettingsService.Instance.DisplaySettings.SelectedFont; } public void AddInline(Inline inline) diff --git a/ILSpy/Themes/WindowStyleManagerBehavior.cs b/ILSpy/Themes/WindowStyleManagerBehavior.cs index 55d0c2c9b..60c7e6ada 100644 --- a/ILSpy/Themes/WindowStyleManagerBehavior.cs +++ b/ILSpy/Themes/WindowStyleManagerBehavior.cs @@ -24,6 +24,7 @@ using System.Windows.Interop; using System.Windows.Media; using ICSharpCode.ILSpy.Options; +using ICSharpCode.ILSpy.Util; using TomsToolbox.Essentials; using TomsToolbox.Wpf; @@ -42,7 +43,7 @@ namespace ICSharpCode.ILSpy.Themes { base.OnAttached(); - MainWindow.Instance.CurrentDisplaySettings.PropertyChanged += DisplaySettings_PropertyChanged; + SettingsService.Instance.DisplaySettings.PropertyChanged += DisplaySettings_PropertyChanged; _foreground = AssociatedObject.Track(Control.ForegroundProperty); _background = AssociatedObject.Track(Control.BackgroundProperty); @@ -61,7 +62,7 @@ namespace ICSharpCode.ILSpy.Themes _foreground.Changed -= Color_Changed; _background.Changed -= Color_Changed; - MainWindow.Instance.CurrentDisplaySettings.PropertyChanged -= DisplaySettings_PropertyChanged; + SettingsService.Instance.DisplaySettings.PropertyChanged -= DisplaySettings_PropertyChanged; } private void Color_Changed(object sender, EventArgs e) @@ -73,7 +74,7 @@ namespace ICSharpCode.ILSpy.Themes { var window = AssociatedObject; - if (MainWindow.Instance.CurrentDisplaySettings.StyleWindowTitleBar) + if (SettingsService.Instance.DisplaySettings.StyleWindowTitleBar) window.Style = (Style)window.FindResource(TomsToolbox.Wpf.Styles.ResourceKeys.WindowStyle); } @@ -86,7 +87,7 @@ namespace ICSharpCode.ILSpy.Themes { if (e.PropertyName == nameof(DisplaySettingsViewModel.StyleWindowTitleBar)) { - if (!MainWindow.Instance.CurrentDisplaySettings.StyleWindowTitleBar) + if (!SettingsService.Instance.DisplaySettings.StyleWindowTitleBar) { restartNotificationThrottle.Tick(); return; diff --git a/ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs b/ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs index f0046694b..25602d875 100644 --- a/ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs @@ -26,6 +26,7 @@ using ICSharpCode.Decompiler; using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.ILSpy.Themes; +using ICSharpCode.ILSpy.Util; using ICSharpCode.ILSpyX.TreeView.PlatformAbstractions; namespace ICSharpCode.ILSpy.TreeNodes @@ -85,7 +86,7 @@ namespace ICSharpCode.ILSpy.TreeNodes { this.Children.Add(new AssemblyReferenceReferencedTypesTreeNode(module, r)); - var resolver = parentAssembly.LoadedAssembly.GetAssemblyResolver(MainWindow.Instance.CurrentDecompilerSettings.AutoLoadAssemblyReferences); + var resolver = parentAssembly.LoadedAssembly.GetAssemblyResolver(SettingsService.Instance.DecompilerSettings.AutoLoadAssemblyReferences); var referencedModule = resolver.Resolve(r); if (referencedModule != null) { diff --git a/ILSpy/TreeNodes/AssemblyTreeNode.cs b/ILSpy/TreeNodes/AssemblyTreeNode.cs index b28c0809f..d2f102ef2 100644 --- a/ILSpy/TreeNodes/AssemblyTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyTreeNode.cs @@ -33,6 +33,7 @@ using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.ILSpy.Controls.TreeView; using ICSharpCode.ILSpy.Metadata; using ICSharpCode.ILSpy.Properties; +using ICSharpCode.ILSpy.Util; using ICSharpCode.ILSpy.ViewModels; using ICSharpCode.ILSpyX; using ICSharpCode.ILSpyX.FileLoaders; @@ -261,7 +262,7 @@ namespace ICSharpCode.ILSpy.TreeNodes ns.Children.Clear(); } namespaces.Clear(); - bool useNestedStructure = MainWindow.Instance.CurrentDisplaySettings.UseNestedNamespaceNodes; + bool useNestedStructure = SettingsService.Instance.DisplaySettings.UseNestedNamespaceNodes; foreach (var type in assembly.TopLevelTypeDefinitions.OrderBy(t => t.ReflectionName, NaturalStringComparer.Instance)) { var ns = GetOrCreateNamespaceTreeNode(type.Namespace); @@ -327,7 +328,7 @@ namespace ICSharpCode.ILSpy.TreeNodes ns.Children.Clear(); } namespaces.Clear(); - bool useNestedStructure = MainWindow.Instance.CurrentDisplaySettings.UseNestedNamespaceNodes; + bool useNestedStructure = SettingsService.Instance.DisplaySettings.UseNestedNamespaceNodes; foreach (var type in assembly.TopLevelTypeDefinitions.OrderBy(t => t.ReflectionName, NaturalStringComparer.Instance)) { var ns = GetOrCreateNamespaceTreeNode(type.Namespace); diff --git a/ILSpy/TreeNodes/ILSpyTreeNode.cs b/ILSpy/TreeNodes/ILSpyTreeNode.cs index d2a3c93dc..e3958a1bb 100644 --- a/ILSpy/TreeNodes/ILSpyTreeNode.cs +++ b/ILSpy/TreeNodes/ILSpyTreeNode.cs @@ -158,11 +158,11 @@ namespace ICSharpCode.ILSpy.TreeNodes protected string GetSuffixString(EntityHandle handle) { - if (!MainWindow.Instance.CurrentDisplaySettings.ShowMetadataTokens) + if (!SettingsService.Instance.DisplaySettings.ShowMetadataTokens) return string.Empty; int token = MetadataTokens.GetToken(handle); - if (MainWindow.Instance.CurrentDisplaySettings.ShowMetadataTokensInBase10) + if (SettingsService.Instance.DisplaySettings.ShowMetadataTokensInBase10) return " @" + token; return " @" + token.ToString("x8"); } diff --git a/ILSpy/Util/SettingsService.cs b/ILSpy/Util/SettingsService.cs index 0f7a07e6a..a55e2f54c 100644 --- a/ILSpy/Util/SettingsService.cs +++ b/ILSpy/Util/SettingsService.cs @@ -1,20 +1,34 @@ -using ICSharpCode.ILSpyX.Settings; +using ICSharpCode.Decompiler; +using ICSharpCode.ILSpy.Options; +using ICSharpCode.ILSpyX; +using ICSharpCode.ILSpyX.Settings; namespace ICSharpCode.ILSpy.Util { - internal class SettingsService + public class SettingsService { - public static readonly SettingsService Instance = new SettingsService(); + public static readonly SettingsService Instance = new(); private SettingsService() { - this.SpySettings = ILSpySettings.Load(); - - SessionSettings = new(this.SpySettings); + SpySettings = ILSpySettings.Load(); + SessionSettings = new(SpySettings); + DecompilerSettings = DecompilerSettingsPanel.LoadDecompilerSettings(SpySettings); + DisplaySettings = DisplaySettingsPanel.LoadDisplaySettings(SpySettings, SessionSettings); + AssemblyListManager = new(SpySettings) { + ApplyWinRTProjections = DecompilerSettings.ApplyWindowsRuntimeProjections, + UseDebugSymbols = DecompilerSettings.UseDebugSymbols + }; } public ILSpySettings SpySettings { get; } public SessionSettings SessionSettings { get; } + + public DecompilerSettings DecompilerSettings { get; set; } + + public DisplaySettingsViewModel DisplaySettings { get; } + + public AssemblyListManager AssemblyListManager { get; } } } diff --git a/ILSpy/ViewModels/ManageAssemblyListsViewModel.cs b/ILSpy/ViewModels/ManageAssemblyListsViewModel.cs index 23959c2c3..ec039552f 100644 --- a/ILSpy/ViewModels/ManageAssemblyListsViewModel.cs +++ b/ILSpy/ViewModels/ManageAssemblyListsViewModel.cs @@ -39,7 +39,7 @@ namespace ICSharpCode.ILSpy.ViewModels public ManageAssemblyListsViewModel(Window parent) { - this.manager = MainWindow.Instance.AssemblyListManager; + this.manager = SettingsService.Instance.AssemblyListManager; this.parent = parent; NewCommand = new DelegateCommand(ExecuteNew); diff --git a/ILSpy/ViewModels/SearchPaneModel.cs b/ILSpy/ViewModels/SearchPaneModel.cs index ea6fca679..d1670f72c 100644 --- a/ILSpy/ViewModels/SearchPaneModel.cs +++ b/ILSpy/ViewModels/SearchPaneModel.cs @@ -33,7 +33,7 @@ namespace ICSharpCode.ILSpy.ViewModels ContentId = PaneContentId; Title = Properties.Resources.SearchPane_Search; Icon = "Images/Search"; - ShortcutKey = new KeyGesture(Key.F, ModifierKeys.Control | ModifierKeys.Shift); + ShortcutKey = new(Key.F, ModifierKeys.Control | ModifierKeys.Shift); IsCloseable = true; } diff --git a/ILSpy/Views/DebugSteps.xaml.cs b/ILSpy/Views/DebugSteps.xaml.cs index c4177e3aa..b619cc6b7 100644 --- a/ILSpy/Views/DebugSteps.xaml.cs +++ b/ILSpy/Views/DebugSteps.xaml.cs @@ -124,7 +124,7 @@ namespace ICSharpCode.ILSpy var window = MainWindow.Instance; var state = DockWorkspace.Instance.ActiveTabPage.GetState(); DockWorkspace.Instance.ActiveTabPage.ShowTextViewAsync(textView => textView.DecompileAsync(window.CurrentLanguage, window.SelectedNodes, - new DecompilationOptions(window.CurrentLanguageVersion, window.CurrentDecompilerSettings, window.CurrentDisplaySettings) { + new DecompilationOptions(window.CurrentLanguageVersion, SettingsService.Instance.DecompilerSettings, SettingsService.Instance.DisplaySettings) { StepLimit = step, IsDebug = isDebug, TextViewState = state as TextView.DecompilerTextViewState