diff --git a/ILSpy.ReadyToRun/ReadyToRunLanguage.cs b/ILSpy.ReadyToRun/ReadyToRunLanguage.cs index 33c0a46e2..ec3ced0bc 100644 --- a/ILSpy.ReadyToRun/ReadyToRunLanguage.cs +++ b/ILSpy.ReadyToRun/ReadyToRunLanguage.cs @@ -157,8 +157,9 @@ namespace ICSharpCode.ILSpy.ReadyToRun .GroupBy(m => m.MethodHandle) .ToDictionary(g => g.Key, g => g.ToArray()); } - bool showMetadataTokens = ILSpy.Options.DisplaySettingsPanel.CurrentDisplaySettings.ShowMetadataTokens; - bool showMetadataTokensInBase10 = ILSpy.Options.DisplaySettingsPanel.CurrentDisplaySettings.ShowMetadataTokensInBase10; + var displaySettings = MainWindow.Instance.CurrentDisplaySettings; + bool showMetadataTokens = displaySettings.ShowMetadataTokens; + bool showMetadataTokensInBase10 = displaySettings.ShowMetadataTokensInBase10; #if STRESS ITextOutput originalOutput = output; output = new DummyOutput(); diff --git a/ILSpy/Commands/DecompileAllCommand.cs b/ILSpy/Commands/DecompileAllCommand.cs index bda0d7a93..7bc61a167 100644 --- a/ILSpy/Commands/DecompileAllCommand.cs +++ b/ILSpy/Commands/DecompileAllCommand.cs @@ -29,6 +29,8 @@ using ICSharpCode.ILSpy.Properties; using ICSharpCode.ILSpy.TextView; using ICSharpCode.ILSpyX; +using TomsToolbox.Essentials; + namespace ICSharpCode.ILSpy { [ExportMainMenuCommand(ParentMenuID = nameof(Resources._File), Header = nameof(Resources.DEBUGDecompile), MenuCategory = nameof(Resources.Open), MenuOrder = 2.5)] @@ -55,7 +57,10 @@ namespace ICSharpCode.ILSpy { try { - new CSharpLanguage().DecompileAssembly(asm, new Decompiler.PlainTextOutput(writer), new DecompilationOptions() { FullDecompilation = true, CancellationToken = ct }); + var options = MainWindow.Instance.CreateDecompilationOptions(); + options.CancellationToken = ct; + options.FullDecompilation = true; + new CSharpLanguage().DecompileAssembly(asm, new PlainTextOutput(writer), options); } catch (Exception ex) { @@ -88,7 +93,7 @@ namespace ICSharpCode.ILSpy const int numRuns = 100; var language = MainWindow.Instance.CurrentLanguage; var nodes = MainWindow.Instance.SelectedNodes.ToArray(); - var options = new DecompilationOptions(); + var options = MainWindow.Instance.CreateDecompilationOptions(); Docking.DockWorkspace.Instance.RunWithCancellation(ct => Task.Factory.StartNew(() => { options.CancellationToken = ct; Stopwatch w = Stopwatch.StartNew(); diff --git a/ILSpy/Commands/DisassembleAllCommand.cs b/ILSpy/Commands/DisassembleAllCommand.cs index a127c5203..34f7f8575 100644 --- a/ILSpy/Commands/DisassembleAllCommand.cs +++ b/ILSpy/Commands/DisassembleAllCommand.cs @@ -53,7 +53,10 @@ namespace ICSharpCode.ILSpy { try { - new ILLanguage().DecompileAssembly(asm, new Decompiler.PlainTextOutput(writer), new DecompilationOptions { FullDecompilation = true, CancellationToken = ct }); + var options = MainWindow.Instance.CreateDecompilationOptions(); + options.FullDecompilation = true; + options.CancellationToken = ct; + new ILLanguage().DecompileAssembly(asm, new Decompiler.PlainTextOutput(writer), options); } catch (Exception ex) { diff --git a/ILSpy/Commands/GeneratePdbContextMenuEntry.cs b/ILSpy/Commands/GeneratePdbContextMenuEntry.cs index 351e96e10..3af1c3b64 100644 --- a/ILSpy/Commands/GeneratePdbContextMenuEntry.cs +++ b/ILSpy/Commands/GeneratePdbContextMenuEntry.cs @@ -70,7 +70,7 @@ namespace ICSharpCode.ILSpy dlg.InitialDirectory = Path.GetDirectoryName(assembly.FileName); if (dlg.ShowDialog() != true) return; - DecompilationOptions options = new DecompilationOptions(); + DecompilationOptions options = MainWindow.Instance.CreateDecompilationOptions(); string fileName = dlg.FileName; Docking.DockWorkspace.Instance.RunWithCancellation(ct => Task.Factory.StartNew(() => { AvalonEditTextOutput output = new AvalonEditTextOutput(); diff --git a/ILSpy/Commands/SaveCodeContextMenuEntry.cs b/ILSpy/Commands/SaveCodeContextMenuEntry.cs index a16316fac..13b06a3b3 100644 --- a/ILSpy/Commands/SaveCodeContextMenuEntry.cs +++ b/ILSpy/Commands/SaveCodeContextMenuEntry.cs @@ -22,6 +22,7 @@ using System.IO; using System.Linq; using System.Windows; +using ICSharpCode.Decompiler.IL; using ICSharpCode.ILSpy.Options; using ICSharpCode.ILSpy.Properties; using ICSharpCode.ILSpy.TreeNodes; @@ -83,7 +84,8 @@ namespace ICSharpCode.ILSpy.TextView // Fallback: if nobody was able to handle the request, use default behavior. // try to save all nodes to disk. - var options = new DecompilationOptions() { FullDecompilation = true }; + var options = MainWindow.Instance.CreateDecompilationOptions(); + options.FullDecompilation = true; textView.SaveToDisk(currentLanguage, selectedNodes.OfType(), options); }); } diff --git a/ILSpy/DecompilationOptions.cs b/ILSpy/DecompilationOptions.cs index 0b95dd0ea..d241da8f1 100644 --- a/ILSpy/DecompilationOptions.cs +++ b/ILSpy/DecompilationOptions.cs @@ -74,17 +74,7 @@ namespace ICSharpCode.ILSpy internal int StepLimit = int.MaxValue; internal bool IsDebug = false; - public DecompilationOptions() - : this(MainWindow.Instance.CurrentLanguageVersion, DecompilerSettingsPanel.CurrentDecompilerSettings, DisplaySettingsPanel.CurrentDisplaySettings) - { - } - - public DecompilationOptions(LanguageVersion version) - : this(version, DecompilerSettingsPanel.CurrentDecompilerSettings, DisplaySettingsPanel.CurrentDisplaySettings) - { - } - - public DecompilationOptions(LanguageVersion version, Decompiler.DecompilerSettings settings, Options.DisplaySettings displaySettings) + public DecompilationOptions(LanguageVersion version, Decompiler.DecompilerSettings settings, DisplaySettings displaySettings) { if (!Enum.TryParse(version?.Version, out Decompiler.CSharp.LanguageVersion languageVersion)) languageVersion = Decompiler.CSharp.LanguageVersion.Latest; diff --git a/ILSpy/ExtensionMethods.cs b/ILSpy/ExtensionMethods.cs index 732dc7b4e..55339b316 100644 --- a/ILSpy/ExtensionMethods.cs +++ b/ILSpy/ExtensionMethods.cs @@ -78,7 +78,8 @@ namespace ICSharpCode.ILSpy public static ICompilation? GetTypeSystemWithCurrentOptionsOrNull(this PEFile file) { - return LoadedAssemblyExtensions.GetLoadedAssembly(file).GetTypeSystemOrNull(DecompilerTypeSystem.GetOptions(new DecompilationOptions().DecompilerSettings)); + return LoadedAssemblyExtensions.GetLoadedAssembly(file) + .GetTypeSystemOrNull(DecompilerTypeSystem.GetOptions(MainWindow.Instance.CurrentDecompilerSettings)); } #region DPI independence diff --git a/ILSpy/Languages/CSharpILMixedLanguage.cs b/ILSpy/Languages/CSharpILMixedLanguage.cs index 2de42e3aa..b54a161ba 100644 --- a/ILSpy/Languages/CSharpILMixedLanguage.cs +++ b/ILSpy/Languages/CSharpILMixedLanguage.cs @@ -50,15 +50,16 @@ namespace ICSharpCode.ILSpy protected override ReflectionDisassembler CreateDisassembler(ITextOutput output, DecompilationOptions options) { + var displaySettings = MainWindow.Instance.CurrentDisplaySettings; return new ReflectionDisassembler(output, new MixedMethodBodyDisassembler(output, options) { DetectControlStructure = detectControlStructure, ShowSequencePoints = options.DecompilerSettings.ShowDebugInfo }, options.CancellationToken) { - ShowMetadataTokens = Options.DisplaySettingsPanel.CurrentDisplaySettings.ShowMetadataTokens, - ShowMetadataTokensInBase10 = Options.DisplaySettingsPanel.CurrentDisplaySettings.ShowMetadataTokensInBase10, - ShowRawRVAOffsetAndBytes = Options.DisplaySettingsPanel.CurrentDisplaySettings.ShowRawOffsetsAndBytesBeforeInstruction, + ShowMetadataTokens = displaySettings.ShowMetadataTokens, + ShowMetadataTokensInBase10 = displaySettings.ShowMetadataTokensInBase10, + ShowRawRVAOffsetAndBytes = displaySettings.ShowRawOffsetsAndBytesBeforeInstruction, ExpandMemberDefinitions = options.DecompilerSettings.ExpandMemberDefinitions }; } diff --git a/ILSpy/Languages/CSharpLanguage.cs b/ILSpy/Languages/CSharpLanguage.cs index ae1e4e0e4..a1d942882 100644 --- a/ILSpy/Languages/CSharpLanguage.cs +++ b/ILSpy/Languages/CSharpLanguage.cs @@ -533,7 +533,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 (new DecompilationOptions().DecompilerSettings.LiftNullables) + if (MainWindow.Instance.CurrentDecompilerSettings.LiftNullables) { ambience.ConversionFlags |= ConversionFlags.UseNullableSpecifierForValueTypes; } @@ -721,7 +721,7 @@ namespace ICSharpCode.ILSpy public override bool ShowMember(IEntity member) { PEFile assembly = member.ParentModule.PEFile; - return showAllMembers || !CSharpDecompiler.MemberIsHidden(assembly, member.MetadataToken, new DecompilationOptions().DecompilerSettings); + return showAllMembers || !CSharpDecompiler.MemberIsHidden(assembly, member.MetadataToken, MainWindow.Instance.CurrentDecompilerSettings); } public override RichText GetRichTextTooltip(IEntity entity) @@ -730,7 +730,7 @@ namespace ICSharpCode.ILSpy var output = new StringWriter(); var decoratedWriter = new TextWriterTokenWriter(output); var writer = new CSharpHighlightingTokenWriter(TokenWriter.InsertRequiredSpaces(decoratedWriter), locatable: decoratedWriter); - var settings = new DecompilationOptions().DecompilerSettings; + var settings = MainWindow.Instance.CurrentDecompilerSettings; if (!settings.LiftNullables) { flags &= ~ConversionFlags.UseNullableSpecifierForValueTypes; diff --git a/ILSpy/Languages/ILLanguage.cs b/ILSpy/Languages/ILLanguage.cs index 2019fa9b0..711778581 100644 --- a/ILSpy/Languages/ILLanguage.cs +++ b/ILSpy/Languages/ILLanguage.cs @@ -56,13 +56,14 @@ namespace ICSharpCode.ILSpy protected virtual ReflectionDisassembler CreateDisassembler(ITextOutput output, DecompilationOptions options) { + var displaySettings = MainWindow.Instance.CurrentDisplaySettings; output.IndentationString = options.DecompilerSettings.CSharpFormattingOptions.IndentationString; return new ReflectionDisassembler(output, options.CancellationToken) { DetectControlStructure = detectControlStructure, ShowSequencePoints = options.DecompilerSettings.ShowDebugInfo, - ShowMetadataTokens = Options.DisplaySettingsPanel.CurrentDisplaySettings.ShowMetadataTokens, - ShowMetadataTokensInBase10 = Options.DisplaySettingsPanel.CurrentDisplaySettings.ShowMetadataTokensInBase10, - ShowRawRVAOffsetAndBytes = Options.DisplaySettingsPanel.CurrentDisplaySettings.ShowRawOffsetsAndBytesBeforeInstruction, + ShowMetadataTokens = displaySettings.ShowMetadataTokens, + ShowMetadataTokensInBase10 = displaySettings.ShowMetadataTokensInBase10, + ShowRawRVAOffsetAndBytes = displaySettings.ShowRawOffsetsAndBytesBeforeInstruction, ExpandMemberDefinitions = options.DecompilerSettings.ExpandMemberDefinitions }; } @@ -194,7 +195,7 @@ namespace ICSharpCode.ILSpy public override RichText GetRichTextTooltip(IEntity entity) { var output = new AvalonEditTextOutput() { IgnoreNewLineAndIndent = true }; - var disasm = CreateDisassembler(output, new DecompilationOptions()); + var disasm = CreateDisassembler(output, MainWindow.Instance.CreateDecompilationOptions()); PEFile module = entity.ParentModule?.PEFile; if (module == null) { diff --git a/ILSpy/MainWindow.xaml.cs b/ILSpy/MainWindow.xaml.cs index 20c680e8f..cf64691d7 100644 --- a/ILSpy/MainWindow.xaml.cs +++ b/ILSpy/MainWindow.xaml.cs @@ -45,6 +45,7 @@ using ICSharpCode.Decompiler.TypeSystem.Implementation; using ICSharpCode.ILSpy.Analyzers; using ICSharpCode.ILSpy.Commands; using ICSharpCode.ILSpy.Docking; +using ICSharpCode.ILSpy.Options; using ICSharpCode.ILSpy.Search; using ICSharpCode.ILSpy.TextView; using ICSharpCode.ILSpy.Themes; @@ -100,15 +101,23 @@ namespace ICSharpCode.ILSpy } } + public DecompilerSettings CurrentDecompilerSettings { get; internal set; } + + public DisplaySettings CurrentDisplaySettings { get; internal set; } + + public DecompilationOptions CreateDecompilationOptions() => new DecompilationOptions(CurrentLanguageVersion, CurrentDecompilerSettings, CurrentDisplaySettings); + public MainWindow() { instance = this; var spySettings = ILSpySettings.Load(); this.spySettingsForMainWindow_Loaded = spySettings; this.sessionSettings = new SessionSettings(spySettings); + this.CurrentDecompilerSettings = DecompilerSettingsPanel.LoadDecompilerSettings(spySettings); + this.CurrentDisplaySettings = DisplaySettingsPanel.LoadDisplaySettings(spySettings); this.AssemblyListManager = new AssemblyListManager(spySettings) { - ApplyWinRTProjections = Options.DecompilerSettingsPanel.CurrentDecompilerSettings.ApplyWindowsRuntimeProjections, - UseDebugSymbols = Options.DecompilerSettingsPanel.CurrentDecompilerSettings.UseDebugSymbols + ApplyWinRTProjections = CurrentDecompilerSettings.ApplyWindowsRuntimeProjections, + UseDebugSymbols = CurrentDecompilerSettings.UseDebugSymbols }; // Make sure Images are initialized on the UI thread. @@ -1494,7 +1503,8 @@ namespace ICSharpCode.ILSpy NavigateTo(new RequestNavigateEventArgs(newState.ViewedUri, null), recordHistory: false); return; } - var options = new DecompilationOptions() { TextViewState = newState }; + var options = MainWindow.Instance.CreateDecompilationOptions(); + options.TextViewState = newState; decompilationTask = DockWorkspace.Instance.ActiveTabPage.ShowTextViewAsync( textView => textView.DecompileAsync(this.CurrentLanguage, this.SelectedNodes, options) ); diff --git a/ILSpy/Metadata/DebugMetadataTablesTreeNode.cs b/ILSpy/Metadata/DebugMetadataTablesTreeNode.cs index 8fc5a3734..cc9f94c08 100644 --- a/ILSpy/Metadata/DebugMetadataTablesTreeNode.cs +++ b/ILSpy/Metadata/DebugMetadataTablesTreeNode.cs @@ -65,7 +65,7 @@ namespace ICSharpCode.ILSpy.Metadata if (ShowTable(TableIndex.CustomDebugInformation)) this.Children.Add(new CustomDebugInformationTableTreeNode(this.module, this.provider, isEmbedded)); - bool ShowTable(TableIndex table) => !DisplaySettingsPanel.CurrentDisplaySettings.HideEmptyMetadataTables || this.provider.GetTableRowCount(table) > 0; + bool ShowTable(TableIndex table) => !MainWindow.Instance.CurrentDisplaySettings.HideEmptyMetadataTables || this.provider.GetTableRowCount(table) > 0; } public override bool View(TabPageModel tabPage) diff --git a/ILSpy/Metadata/MetadataTablesTreeNode.cs b/ILSpy/Metadata/MetadataTablesTreeNode.cs index 6d264792d..0a05fcf65 100644 --- a/ILSpy/Metadata/MetadataTablesTreeNode.cs +++ b/ILSpy/Metadata/MetadataTablesTreeNode.cs @@ -112,7 +112,7 @@ namespace ICSharpCode.ILSpy.Metadata if (ShowTable(TableIndex.GenericParamConstraint)) this.Children.Add(new GenericParamConstraintTableTreeNode(module)); - bool ShowTable(TableIndex table) => !DisplaySettingsPanel.CurrentDisplaySettings.HideEmptyMetadataTables || module.Metadata.GetTableRowCount(table) > 0; + bool ShowTable(TableIndex table) => !MainWindow.Instance.CurrentDisplaySettings.HideEmptyMetadataTables || module.Metadata.GetTableRowCount(table) > 0; } diff --git a/ILSpy/Options/DecompilerSettingsPanel.xaml.cs b/ILSpy/Options/DecompilerSettingsPanel.xaml.cs index 1d80fe22c..b1947fc74 100644 --- a/ILSpy/Options/DecompilerSettingsPanel.xaml.cs +++ b/ILSpy/Options/DecompilerSettingsPanel.xaml.cs @@ -37,14 +37,6 @@ namespace ICSharpCode.ILSpy.Options InitializeComponent(); } - static Decompiler.DecompilerSettings currentDecompilerSettings; - - public static Decompiler.DecompilerSettings CurrentDecompilerSettings { - get { - return currentDecompilerSettings ?? (currentDecompilerSettings = LoadDecompilerSettings(ILSpySettings.Load())); - } - } - public static Decompiler.DecompilerSettings LoadDecompilerSettings(ILSpySettings settings) { XElement e = settings["DecompilerSettings"]; @@ -81,7 +73,7 @@ namespace ICSharpCode.ILSpy.Options else root.Add(section); - currentDecompilerSettings = newSettings; + MainWindow.Instance.CurrentDecompilerSettings = newSettings; MainWindow.Instance.AssemblyListManager.ApplyWinRTProjections = newSettings.ApplyWindowsRuntimeProjections; MainWindow.Instance.AssemblyListManager.UseDebugSymbols = newSettings.UseDebugSymbols; } @@ -137,8 +129,8 @@ namespace ICSharpCode.ILSpy.Options public void LoadDefaults() { - currentDecompilerSettings = new Decompiler.DecompilerSettings(); - this.DataContext = new DecompilerSettingsViewModel(currentDecompilerSettings); + MainWindow.Instance.CurrentDecompilerSettings = new Decompiler.DecompilerSettings(); + this.DataContext = new DecompilerSettingsViewModel(MainWindow.Instance.CurrentDecompilerSettings); } } } diff --git a/ILSpy/Options/DisplaySettingsPanel.xaml.cs b/ILSpy/Options/DisplaySettingsPanel.xaml.cs index 61e704060..b6b18f0f1 100644 --- a/ILSpy/Options/DisplaySettingsPanel.xaml.cs +++ b/ILSpy/Options/DisplaySettingsPanel.xaml.cs @@ -68,14 +68,6 @@ namespace ICSharpCode.ILSpy.Options this.DataContext = LoadDisplaySettings(settings); } - static DisplaySettings currentDisplaySettings; - - public static DisplaySettings CurrentDisplaySettings { - get { - return currentDisplaySettings ?? (currentDisplaySettings = LoadDisplaySettings(ILSpySettings.Load())); - } - } - static bool IsSymbolFont(FontFamily fontFamily) { foreach (var tf in fontFamily.GetTypefaces()) @@ -162,8 +154,7 @@ namespace ICSharpCode.ILSpy.Options else root.Add(section); - if (currentDisplaySettings != null) - currentDisplaySettings.CopyValues(s); + MainWindow.Instance.CurrentDisplaySettings.CopyValues(s); } private void TextBox_PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e) @@ -183,8 +174,8 @@ namespace ICSharpCode.ILSpy.Options public void LoadDefaults() { - currentDisplaySettings = new DisplaySettings(); - this.DataContext = currentDisplaySettings; + MainWindow.Instance.CurrentDisplaySettings.CopyValues(new DisplaySettings()); + this.DataContext = MainWindow.Instance.CurrentDisplaySettings; } } diff --git a/ILSpy/Search/SearchPane.cs b/ILSpy/Search/SearchPane.cs index 9416f4b76..7c58bf026 100644 --- a/ILSpy/Search/SearchPane.cs +++ b/ILSpy/Search/SearchPane.cs @@ -248,7 +248,8 @@ namespace ICSharpCode.ILSpy.Search currentSearch = null; } - resultsComparer = DisplaySettingsPanel.CurrentDisplaySettings.SortResults ? + MainWindow mainWindow = MainWindow.Instance; + resultsComparer = mainWindow.CurrentDisplaySettings.SortResults ? SearchResult.ComparerByFitness : SearchResult.ComparerByName; Results.Clear(); @@ -256,7 +257,6 @@ namespace ICSharpCode.ILSpy.Search RunningSearch startedSearch = null; if (!string.IsNullOrEmpty(searchTerm)) { - MainWindow mainWindow = MainWindow.Instance; searchProgressBar.IsIndeterminate = true; startedSearch = new RunningSearch(await mainWindow.CurrentAssemblyList.GetAllAssemblies(), searchTerm, @@ -452,7 +452,7 @@ namespace ICSharpCode.ILSpy.Search request.RegEx = regex; request.SearchResultFactory = new SearchResultFactory(language); request.TreeNodeFactory = new TreeNodeFactory(); - request.DecompilerSettings = new DecompilationOptions().DecompilerSettings; + request.DecompilerSettings = MainWindow.Instance.CurrentDecompilerSettings; return request; } diff --git a/ILSpy/SolutionWriter.cs b/ILSpy/SolutionWriter.cs index b8a2700ef..a3f412d09 100644 --- a/ILSpy/SolutionWriter.cs +++ b/ILSpy/SolutionWriter.cs @@ -212,11 +212,10 @@ namespace ICSharpCode.ILSpy using (var projectFileWriter = new StreamWriter(projectFileName)) { var projectFileOutput = new PlainTextOutput(projectFileWriter); - var options = new DecompilationOptions() { - FullDecompilation = true, - CancellationToken = ct, - SaveAsProjectDirectory = targetDirectory - }; + var options = MainWindow.Instance.CreateDecompilationOptions(); + options.FullDecompilation = true; + options.CancellationToken = ct; + options.SaveAsProjectDirectory = targetDirectory; var projectInfo = language.DecompileAssembly(loadedAssembly, projectFileOutput, options); if (projectInfo != null) diff --git a/ILSpy/TextView/DecompilerTextView.cs b/ILSpy/TextView/DecompilerTextView.cs index 8b52c1863..02c00bfda 100644 --- a/ILSpy/TextView/DecompilerTextView.cs +++ b/ILSpy/TextView/DecompilerTextView.cs @@ -110,9 +110,9 @@ namespace ICSharpCode.ILSpy.TextView textEditor.TextArea.Caret.PositionChanged += HighlightBrackets; textEditor.MouseMove += TextEditorMouseMove; textEditor.MouseLeave += TextEditorMouseLeave; - textEditor.SetBinding(Control.FontFamilyProperty, new Binding { Source = DisplaySettingsPanel.CurrentDisplaySettings, Path = new PropertyPath("SelectedFont") }); - textEditor.SetBinding(Control.FontSizeProperty, new Binding { Source = DisplaySettingsPanel.CurrentDisplaySettings, Path = new PropertyPath("SelectedFontSize") }); - textEditor.SetBinding(TextEditor.WordWrapProperty, new Binding { Source = DisplaySettingsPanel.CurrentDisplaySettings, Path = new PropertyPath("EnableWordWrap") }); + 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") }); // disable Tab editing command (useless for read-only editor); allow using tab for focus navigation instead RemoveEditCommand(EditingCommands.TabForward); @@ -122,7 +122,7 @@ namespace ICSharpCode.ILSpy.TextView textEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService); textEditor.TextArea.TextView.LineTransformers.Add(textMarkerService); textEditor.ShowLineNumbers = true; - DisplaySettingsPanel.CurrentDisplaySettings.PropertyChanged += CurrentDisplaySettings_PropertyChanged; + MainWindow.Instance.CurrentDisplaySettings.PropertyChanged += CurrentDisplaySettings_PropertyChanged; // SearchPanel SearchPanel searchPanel = SearchPanel.Install(textEditor.TextArea); @@ -190,14 +190,14 @@ namespace ICSharpCode.ILSpy.TextView { if (margin is LineNumberMargin || margin is System.Windows.Shapes.Line) { - margin.Visibility = DisplaySettingsPanel.CurrentDisplaySettings.ShowLineNumbers ? Visibility.Visible : Visibility.Collapsed; + margin.Visibility = MainWindow.Instance.CurrentDisplaySettings.ShowLineNumbers ? Visibility.Visible : Visibility.Collapsed; } } } void SetHighlightCurrentLine() { - textEditor.Options.HighlightCurrentLine = DisplaySettingsPanel.CurrentDisplaySettings.HighlightCurrentLine; + textEditor.Options.HighlightCurrentLine = MainWindow.Instance.CurrentDisplaySettings.HighlightCurrentLine; } #endregion @@ -480,7 +480,7 @@ namespace ICSharpCode.ILSpy.TextView public FlowDocumentTooltip(FlowDocument document) { TextOptions.SetTextFormattingMode(this, TextFormattingMode.Display); - double fontSize = DisplaySettingsPanel.CurrentDisplaySettings.SelectedFontSize; + double fontSize = MainWindow.Instance.CurrentDisplaySettings.SelectedFontSize; viewer = new FlowDocumentScrollViewer() { Width = document.MinPageWidth + fontSize * 5, MaxWidth = MainWindow.Instance.ActualWidth @@ -527,7 +527,7 @@ namespace ICSharpCode.ILSpy.TextView #region Highlight brackets void HighlightBrackets(object? sender, EventArgs e) { - if (DisplaySettingsPanel.CurrentDisplaySettings.HighlightMatchingBraces) + if (MainWindow.Instance.CurrentDisplaySettings.HighlightMatchingBraces) { var result = MainWindow.Instance.CurrentLanguage.BracketSearcher.SearchBracket(textEditor.Document, textEditor.CaretOffset); bracketHighlightRenderer.SetHighlight(result); @@ -734,7 +734,7 @@ namespace ICSharpCode.ILSpy.TextView { if (state != null) { - state.RestoreFoldings(textOutput.Foldings, DisplaySettingsPanel.CurrentDisplaySettings.ExpandMemberDefinitions); + state.RestoreFoldings(textOutput.Foldings, MainWindow.Instance.CurrentDisplaySettings.ExpandMemberDefinitions); textEditor.ScrollToVerticalOffset(state.VerticalOffset); textEditor.ScrollToHorizontalOffset(state.HorizontalOffset); } @@ -758,7 +758,7 @@ namespace ICSharpCode.ILSpy.TextView } currentAddress = textOutput.Address; currentTitle = textOutput.Title; - expandMemberDefinitions = DisplaySettingsPanel.CurrentDisplaySettings.ExpandMemberDefinitions; + expandMemberDefinitions = MainWindow.Instance.CurrentDisplaySettings.ExpandMemberDefinitions; } #endregion @@ -1215,7 +1215,7 @@ namespace ICSharpCode.ILSpy.TextView public void Dispose() { - DisplaySettingsPanel.CurrentDisplaySettings.PropertyChanged -= CurrentDisplaySettings_PropertyChanged; + MainWindow.Instance.CurrentDisplaySettings.PropertyChanged -= CurrentDisplaySettings_PropertyChanged; } #region Unfold diff --git a/ILSpy/TextView/DocumentationUIBuilder.cs b/ILSpy/TextView/DocumentationUIBuilder.cs index 10276289c..41cad9d61 100644 --- a/ILSpy/TextView/DocumentationUIBuilder.cs +++ b/ILSpy/TextView/DocumentationUIBuilder.cs @@ -115,7 +115,7 @@ namespace ICSharpCode.ILSpy.TextView // Paragraph sadly does not support TextWrapping.NoWrap var text = new TextBlock { FontFamily = GetCodeFont(), - FontSize = DisplaySettingsPanel.CurrentDisplaySettings.SelectedFontSize, + FontSize = MainWindow.Instance.CurrentDisplaySettings.SelectedFontSize, TextAlignment = TextAlignment.Left }; text.Inlines.AddRange(richText.CreateRuns(document)); @@ -435,7 +435,7 @@ namespace ICSharpCode.ILSpy.TextView FontFamily GetCodeFont() { - return DisplaySettingsPanel.CurrentDisplaySettings.SelectedFont; + return MainWindow.Instance.CurrentDisplaySettings.SelectedFont; } public void AddInline(Inline inline) diff --git a/ILSpy/Themes/WindowStyleManagerBehavior.cs b/ILSpy/Themes/WindowStyleManagerBehavior.cs index d85df6ff4..128e63db5 100644 --- a/ILSpy/Themes/WindowStyleManagerBehavior.cs +++ b/ILSpy/Themes/WindowStyleManagerBehavior.cs @@ -16,7 +16,7 @@ namespace ICSharpCode.ILSpy.Themes { base.OnAttached(); - DisplaySettingsPanel.CurrentDisplaySettings.PropertyChanged += DisplaySettings_PropertyChanged; + MainWindow.Instance.CurrentDisplaySettings.PropertyChanged += DisplaySettings_PropertyChanged; UpdateWindowStyle(); @@ -26,12 +26,12 @@ namespace ICSharpCode.ILSpy.Themes { base.OnDetaching(); - DisplaySettingsPanel.CurrentDisplaySettings.PropertyChanged -= DisplaySettings_PropertyChanged; + MainWindow.Instance.CurrentDisplaySettings.PropertyChanged -= DisplaySettings_PropertyChanged; } private void UpdateWindowStyle() { - if (!DisplaySettingsPanel.CurrentDisplaySettings.StyleWindowTitleBar) + if (!MainWindow.Instance.CurrentDisplaySettings.StyleWindowTitleBar) { return; } @@ -49,7 +49,7 @@ namespace ICSharpCode.ILSpy.Themes { if (e.PropertyName == nameof(DisplaySettings.StyleWindowTitleBar)) { - if (!DisplaySettingsPanel.CurrentDisplaySettings.StyleWindowTitleBar) + if (!MainWindow.Instance.CurrentDisplaySettings.StyleWindowTitleBar) { restartNotificationThrottle.Tick(); return; diff --git a/ILSpy/TreeNodes/AssemblyTreeNode.cs b/ILSpy/TreeNodes/AssemblyTreeNode.cs index 19b6b633a..d685e7a36 100644 --- a/ILSpy/TreeNodes/AssemblyTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyTreeNode.cs @@ -220,7 +220,7 @@ namespace ICSharpCode.ILSpy.TreeNodes ns.Children.Clear(); } namespaces.Clear(); - bool useNestedStructure = DisplaySettingsPanel.CurrentDisplaySettings.UseNestedNamespaceNodes; + bool useNestedStructure = MainWindow.Instance.CurrentDisplaySettings.UseNestedNamespaceNodes; foreach (var type in assembly.TopLevelTypeDefinitions.OrderBy(t => t.ReflectionName, NaturalStringComparer.Instance)) { var ns = GetOrCreateNamespaceTreeNode(type.Namespace); @@ -429,7 +429,7 @@ namespace ICSharpCode.ILSpy.TreeNodes dlg.Filter = language.Name + " project|*" + language.ProjectFileExtension + "|" + language.Name + " single file|*" + language.FileExtension + "|All files|*.*"; if (dlg.ShowDialog() == true) { - DecompilationOptions options = new DecompilationOptions(); + DecompilationOptions options = MainWindow.Instance.CreateDecompilationOptions(); options.FullDecompilation = true; if (dlg.FilterIndex == 1) { diff --git a/ILSpy/TreeNodes/ILSpyTreeNode.cs b/ILSpy/TreeNodes/ILSpyTreeNode.cs index 8bc68dabe..079db2993 100644 --- a/ILSpy/TreeNodes/ILSpyTreeNode.cs +++ b/ILSpy/TreeNodes/ILSpyTreeNode.cs @@ -188,11 +188,11 @@ namespace ICSharpCode.ILSpy.TreeNodes protected string GetSuffixString(EntityHandle handle) { - if (!DisplaySettingsPanel.CurrentDisplaySettings.ShowMetadataTokens) + if (!MainWindow.Instance.CurrentDisplaySettings.ShowMetadataTokens) return string.Empty; int token = MetadataTokens.GetToken(handle); - if (DisplaySettingsPanel.CurrentDisplaySettings.ShowMetadataTokensInBase10) + if (MainWindow.Instance.CurrentDisplaySettings.ShowMetadataTokensInBase10) return " @" + token; return " @" + token.ToString("x8"); } diff --git a/ILSpy/Views/DebugSteps.xaml.cs b/ILSpy/Views/DebugSteps.xaml.cs index dce20bafb..f359e4115 100644 --- a/ILSpy/Views/DebugSteps.xaml.cs +++ b/ILSpy/Views/DebugSteps.xaml.cs @@ -134,7 +134,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) { + new DecompilationOptions(window.CurrentLanguageVersion, window.CurrentDecompilerSettings, window.CurrentDisplaySettings) { StepLimit = step, IsDebug = isDebug, TextViewState = state as TextView.DecompilerTextViewState