Browse Source

Move more settings-related items from MainWindow to SettingsService

pull/3266/head
tom-englert 9 months ago committed by Siegfried Pammer
parent
commit
74f4758d89
  1. 1
      ICSharpCode.ILSpyX/AssemblyListManager.cs
  2. 3
      ILSpy.ReadyToRun/ReadyToRunLanguage.cs
  3. 3
      ILSpy/App.xaml.cs
  4. 33
      ILSpy/ExtensionMethods.cs
  5. 3
      ILSpy/Languages/CSharpILMixedLanguage.cs
  6. 7
      ILSpy/Languages/CSharpLanguage.cs
  7. 3
      ILSpy/Languages/ILLanguage.cs
  8. 63
      ILSpy/MainWindow.xaml.cs
  9. 3
      ILSpy/Metadata/DebugMetadataTablesTreeNode.cs
  10. 3
      ILSpy/Metadata/MetadataTablesTreeNode.cs
  11. 11
      ILSpy/Options/DecompilerSettingsPanel.xaml.cs
  12. 10
      ILSpy/Options/DisplaySettingsPanel.xaml.cs
  13. 4
      ILSpy/Search/SearchPane.cs
  14. 22
      ILSpy/TextView/DecompilerTextView.cs
  15. 5
      ILSpy/TextView/DocumentationUIBuilder.cs
  16. 9
      ILSpy/Themes/WindowStyleManagerBehavior.cs
  17. 3
      ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs
  18. 5
      ILSpy/TreeNodes/AssemblyTreeNode.cs
  19. 4
      ILSpy/TreeNodes/ILSpyTreeNode.cs
  20. 26
      ILSpy/Util/SettingsService.cs
  21. 2
      ILSpy/ViewModels/ManageAssemblyListsViewModel.cs
  22. 2
      ILSpy/ViewModels/SearchPaneModel.cs
  23. 2
      ILSpy/Views/DebugSteps.xaml.cs

1
ICSharpCode.ILSpyX/AssemblyListManager.cs

@ -56,6 +56,7 @@ namespace ICSharpCode.ILSpyX @@ -56,6 +56,7 @@ namespace ICSharpCode.ILSpyX
}
public bool ApplyWinRTProjections { get; set; }
public bool UseDebugSymbols { get; set; }
public ObservableCollection<string> AssemblyLists { get; } = new ObservableCollection<string>();

3
ILSpy.ReadyToRun/ReadyToRunLanguage.cs

@ -33,6 +33,7 @@ using ICSharpCode.Decompiler; @@ -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 @@ -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

3
ILSpy/App.xaml.cs

@ -201,7 +201,8 @@ namespace ICSharpCode.ILSpy @@ -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);

33
ILSpy/ExtensionMethods.cs

@ -20,12 +20,14 @@ @@ -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 @@ -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 @@ -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<App.ExceptionData> 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;
}
}
}

3
ILSpy/Languages/CSharpILMixedLanguage.cs

@ -34,6 +34,7 @@ using ICSharpCode.Decompiler.Disassembler; @@ -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 @@ -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,

7
ILSpy/Languages/CSharpLanguage.cs

@ -41,6 +41,7 @@ using ICSharpCode.Decompiler.TypeSystem; @@ -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 @@ -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 @@ -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 @@ -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;

3
ILSpy/Languages/ILLanguage.cs

@ -30,6 +30,7 @@ using ICSharpCode.Decompiler.Solution; @@ -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 @@ -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,

63
ILSpy/MainWindow.xaml.cs

@ -83,8 +83,6 @@ namespace ICSharpCode.ILSpy @@ -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 @@ -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<DecompilationProgress>;
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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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

3
ILSpy/Metadata/DebugMetadataTablesTreeNode.cs

@ -21,6 +21,7 @@ using System.Reflection.Metadata.Ecma335; @@ -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 @@ -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)

3
ILSpy/Metadata/MetadataTablesTreeNode.cs

@ -23,6 +23,7 @@ using System.Reflection.Metadata.Ecma335; @@ -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 @@ -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)
{

11
ILSpy/Options/DecompilerSettingsPanel.xaml.cs

@ -19,6 +19,7 @@ @@ -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 @@ -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);
}
}
}

10
ILSpy/Options/DisplaySettingsPanel.xaml.cs

@ -99,7 +99,7 @@ namespace ICSharpCode.ILSpy.Options @@ -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 @@ -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 @@ -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 @@ -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;
}
}

4
ILSpy/Search/SearchPane.cs

@ -243,7 +243,7 @@ namespace ICSharpCode.ILSpy.Search @@ -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 @@ -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;
}

22
ILSpy/TextView/DecompilerTextView.cs

@ -113,9 +113,9 @@ namespace ICSharpCode.ILSpy.TextView @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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

5
ILSpy/TextView/DocumentationUIBuilder.cs

@ -37,6 +37,7 @@ using ICSharpCode.Decompiler.Documentation; @@ -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 @@ -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 @@ -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)

9
ILSpy/Themes/WindowStyleManagerBehavior.cs

@ -24,6 +24,7 @@ using System.Windows.Interop; @@ -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 @@ -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 @@ -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 @@ -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 @@ -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;

3
ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs

@ -26,6 +26,7 @@ using ICSharpCode.Decompiler; @@ -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 @@ -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)
{

5
ILSpy/TreeNodes/AssemblyTreeNode.cs

@ -33,6 +33,7 @@ using ICSharpCode.Decompiler.TypeSystem; @@ -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 @@ -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 @@ -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);

4
ILSpy/TreeNodes/ILSpyTreeNode.cs

@ -158,11 +158,11 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -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");
}

26
ILSpy/Util/SettingsService.cs

@ -1,20 +1,34 @@ @@ -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; }
}
}

2
ILSpy/ViewModels/ManageAssemblyListsViewModel.cs

@ -39,7 +39,7 @@ namespace ICSharpCode.ILSpy.ViewModels @@ -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);

2
ILSpy/ViewModels/SearchPaneModel.cs

@ -33,7 +33,7 @@ namespace ICSharpCode.ILSpy.ViewModels @@ -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;
}

2
ILSpy/Views/DebugSteps.xaml.cs

@ -124,7 +124,7 @@ namespace ICSharpCode.ILSpy @@ -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

Loading…
Cancel
Save