From ef9aa46cecc0549fa5dbfc460b617372b8d5340f Mon Sep 17 00:00:00 2001 From: Lucas Trzesniewski Date: Mon, 20 Mar 2023 22:27:37 +0100 Subject: [PATCH 1/3] Add theme menu item --- ILSpy/Commands/ILSpyCommands.cs | 2 ++ ILSpy/Commands/SetThemeCommand.cs | 11 +++++++++++ ILSpy/MainWindow.xaml | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 ILSpy/Commands/SetThemeCommand.cs diff --git a/ILSpy/Commands/ILSpyCommands.cs b/ILSpy/Commands/ILSpyCommands.cs index aab6d6f0b..50ace9379 100644 --- a/ILSpy/Commands/ILSpyCommands.cs +++ b/ILSpy/Commands/ILSpyCommands.cs @@ -24,6 +24,7 @@ using System.Threading.Tasks; using System.Windows.Input; using ICSharpCode.ILSpy.Analyzers; +using ICSharpCode.ILSpy.Commands; namespace ICSharpCode.ILSpy { @@ -31,5 +32,6 @@ namespace ICSharpCode.ILSpy { public static readonly AnalyzeCommand Analyze = new AnalyzeCommand(); public static readonly ManageAssemblyListsCommand ManageAssemblyListsCommand = new ManageAssemblyListsCommand(); + public static readonly SetThemeCommand SetTheme = new SetThemeCommand(); } } diff --git a/ILSpy/Commands/SetThemeCommand.cs b/ILSpy/Commands/SetThemeCommand.cs new file mode 100644 index 000000000..9083300ab --- /dev/null +++ b/ILSpy/Commands/SetThemeCommand.cs @@ -0,0 +1,11 @@ +namespace ICSharpCode.ILSpy.Commands +{ + public class SetThemeCommand : SimpleCommand + { + public override void Execute(object parameter) + { + if (parameter is string theme) + MainWindow.Instance.SessionSettings.Theme = theme; + } + } +} diff --git a/ILSpy/MainWindow.xaml b/ILSpy/MainWindow.xaml index 9335d38a1..585720cfc 100644 --- a/ILSpy/MainWindow.xaml +++ b/ILSpy/MainWindow.xaml @@ -20,6 +20,7 @@ xmlns:styles="urn:TomsToolbox.Wpf.Styles" xmlns:b="http://schemas.microsoft.com/xaml/behaviors" xmlns:themes="clr-namespace:ICSharpCode.ILSpy.Themes" + xmlns:toms="urn:TomsToolbox" d:DataContext="{d:DesignInstance local:MainWindowViewModel}" > @@ -138,6 +139,23 @@ + + + + + From df4f18b32cf454d00e511e52fb348395274aea37 Mon Sep 17 00:00:00 2001 From: Lucas Trzesniewski Date: Mon, 20 Mar 2023 23:29:38 +0100 Subject: [PATCH 2/3] Add theme option in settings --- ILSpy/Options/DisplaySettingsPanel.xaml | 5 +++++ ILSpy/Options/DisplaySettingsPanel.xaml.cs | 21 ++++++++++++++++----- ILSpy/Options/DisplaySettingsViewModel.cs | 17 +++++++++++++++++ ILSpy/Properties/Resources.Designer.cs | 9 +++++++++ ILSpy/Properties/Resources.resx | 3 +++ ILSpy/SessionSettings.cs | 7 ++++++- 6 files changed, 56 insertions(+), 6 deletions(-) diff --git a/ILSpy/Options/DisplaySettingsPanel.xaml b/ILSpy/Options/DisplaySettingsPanel.xaml index f9206b829..52f5c3ab1 100644 --- a/ILSpy/Options/DisplaySettingsPanel.xaml +++ b/ILSpy/Options/DisplaySettingsPanel.xaml @@ -6,12 +6,17 @@ xmlns:system="clr-namespace:System;assembly=mscorlib" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:themes="clr-namespace:ICSharpCode.ILSpy.Themes" d:DataContext="{d:DesignInstance local:DisplaySettingsViewModel}"> + + diff --git a/ILSpy/Options/DisplaySettingsPanel.xaml.cs b/ILSpy/Options/DisplaySettingsPanel.xaml.cs index 5e6201ff1..908ed3501 100644 --- a/ILSpy/Options/DisplaySettingsPanel.xaml.cs +++ b/ILSpy/Options/DisplaySettingsPanel.xaml.cs @@ -121,6 +121,8 @@ namespace ICSharpCode.ILSpy.Options s.ShowRawOffsetsAndBytesBeforeInstruction = (bool?)e.Attribute("ShowRawOffsetsAndBytesBeforeInstruction") ?? false; s.StyleWindowTitleBar = (bool?)e.Attribute("StyleWindowTitleBar") ?? false; + s.Theme = MainWindow.Instance.SessionSettings.Theme; + return s; } @@ -150,13 +152,22 @@ namespace ICSharpCode.ILSpy.Options section.SetAttributeValue("ShowRawOffsetsAndBytesBeforeInstruction", s.ShowRawOffsetsAndBytesBeforeInstruction); section.SetAttributeValue("StyleWindowTitleBar", s.StyleWindowTitleBar); - XElement existingElement = root.Element("DisplaySettings"); - if (existingElement != null) - existingElement.ReplaceWith(section); - else - root.Add(section); + MainWindow.Instance.SessionSettings.Theme = s.Theme; + var sessionSettings = MainWindow.Instance.SessionSettings.ToXml(); MainWindow.Instance.CurrentDisplaySettings.CopyValues(s); + + Update(section); + Update(sessionSettings); + + void Update(XElement element) + { + var existingElement = root.Element(element.Name); + if (existingElement != null) + existingElement.ReplaceWith(element); + else + root.Add(element); + } } private void TextBox_PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e) diff --git a/ILSpy/Options/DisplaySettingsViewModel.cs b/ILSpy/Options/DisplaySettingsViewModel.cs index 084d295b1..15b54ebe5 100644 --- a/ILSpy/Options/DisplaySettingsViewModel.cs +++ b/ILSpy/Options/DisplaySettingsViewModel.cs @@ -20,6 +20,8 @@ using System.ComponentModel; using System.Runtime.CompilerServices; using System.Windows.Media; +using ICSharpCode.ILSpy.Themes; + namespace ICSharpCode.ILSpy.Options { /// @@ -29,6 +31,7 @@ namespace ICSharpCode.ILSpy.Options { public DisplaySettingsViewModel() { + this.theme = ThemeManager.Current.DefaultTheme; this.selectedFont = new FontFamily("Consolas"); this.selectedFontSize = 10.0 * 4 / 3; this.sortResults = true; @@ -52,6 +55,19 @@ namespace ICSharpCode.ILSpy.Options } #endregion + string theme; + + public string Theme { + get { return theme; } + set { + if (theme != value) + { + theme = value; + OnPropertyChanged(); + } + } + } + FontFamily selectedFont; public FontFamily SelectedFont { @@ -314,6 +330,7 @@ namespace ICSharpCode.ILSpy.Options public void CopyValues(DisplaySettingsViewModel s) { + this.Theme = s.Theme; this.SelectedFont = s.selectedFont; this.SelectedFontSize = s.selectedFontSize; this.ShowLineNumbers = s.showLineNumbers; diff --git a/ILSpy/Properties/Resources.Designer.cs b/ILSpy/Properties/Resources.Designer.cs index f9002b35d..94c50345b 100644 --- a/ILSpy/Properties/Resources.Designer.cs +++ b/ILSpy/Properties/Resources.Designer.cs @@ -1558,6 +1558,15 @@ namespace ICSharpCode.ILSpy.Properties { } } + /// + /// Looks up a localized string similar to Theme:. + /// + public static string DisplaySettingsPanel_Theme { + get { + return ResourceManager.GetString("DisplaySettingsPanel_Theme", resourceCulture); + } + } + /// /// Looks up a localized string similar to Download. /// diff --git a/ILSpy/Properties/Resources.resx b/ILSpy/Properties/Resources.resx index f9e949fa8..82d434c12 100644 --- a/ILSpy/Properties/Resources.resx +++ b/ILSpy/Properties/Resources.resx @@ -540,6 +540,9 @@ Are you sure you want to continue? Font: + + Theme: + Download diff --git a/ILSpy/SessionSettings.cs b/ILSpy/SessionSettings.cs index 245dd99d1..ad53d408c 100644 --- a/ILSpy/SessionSettings.cs +++ b/ILSpy/SessionSettings.cs @@ -127,7 +127,7 @@ namespace ICSharpCode.ILSpy public DockLayoutSettings DockLayout { get; private set; } - public void Save() + public XElement ToXml() { XElement doc = new XElement("SessionSettings"); doc.Add(this.FilterSettings.SaveAsXml()); @@ -161,7 +161,12 @@ namespace ICSharpCode.ILSpy dockLayoutElement.Add(DockLayout.SaveAsXml()); } doc.Add(dockLayoutElement); + return doc; + } + public void Save() + { + var doc = ToXml(); ILSpySettings.SaveSettings(doc); } From 03b3fc464200c79d031acdb38ccf1ce2b4ce3319 Mon Sep 17 00:00:00 2001 From: Lucas Trzesniewski Date: Mon, 20 Mar 2023 23:30:11 +0100 Subject: [PATCH 3/3] Remove theme combo box --- ILSpy/MainWindow.xaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ILSpy/MainWindow.xaml b/ILSpy/MainWindow.xaml index 585720cfc..0d236371f 100644 --- a/ILSpy/MainWindow.xaml +++ b/ILSpy/MainWindow.xaml @@ -220,10 +220,6 @@ IsEnabled="{Binding Workspace.ActiveTabPage.SupportsLanguageSwitching}" ItemsSource="{Binding SelectedItem.LanguageVersions, ElementName=languageComboBox, UpdateSourceTrigger=PropertyChanged}" SelectedItem="{Binding Workspace.ActiveTabPage.FilterSettings.LanguageVersion, UpdateSourceTrigger=PropertyChanged}"/> - -