Browse Source

Add theme option in settings

pull/2931/head
Lucas Trzesniewski 2 years ago
parent
commit
df4f18b32c
  1. 5
      ILSpy/Options/DisplaySettingsPanel.xaml
  2. 21
      ILSpy/Options/DisplaySettingsPanel.xaml.cs
  3. 17
      ILSpy/Options/DisplaySettingsViewModel.cs
  4. 9
      ILSpy/Properties/Resources.Designer.cs
  5. 3
      ILSpy/Properties/Resources.resx
  6. 7
      ILSpy/SessionSettings.cs

5
ILSpy/Options/DisplaySettingsPanel.xaml

@ -6,12 +6,17 @@ @@ -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}">
<UserControl.Resources>
<local:FontSizeConverter x:Key="fontSizeConv" />
</UserControl.Resources>
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<StackPanel Orientation="Vertical">
<DockPanel>
<Label DockPanel.Dock="Left" Content="{x:Static properties:Resources.DisplaySettingsPanel_Theme}" />
<ComboBox ItemsSource="{x:Static themes:ThemeManager.AllThemes}" SelectedItem="{Binding Theme}" VerticalContentAlignment="Center" Margin="0,0,8,0" />
</DockPanel>
<GroupBox Header="{x:Static properties:Resources.Font}">
<Grid>
<Grid.ColumnDefinitions>

21
ILSpy/Options/DisplaySettingsPanel.xaml.cs

@ -121,6 +121,8 @@ namespace ICSharpCode.ILSpy.Options @@ -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 @@ -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)

17
ILSpy/Options/DisplaySettingsViewModel.cs

@ -20,6 +20,8 @@ using System.ComponentModel; @@ -20,6 +20,8 @@ using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Media;
using ICSharpCode.ILSpy.Themes;
namespace ICSharpCode.ILSpy.Options
{
/// <summary>
@ -29,6 +31,7 @@ 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 @@ -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 @@ -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;

9
ILSpy/Properties/Resources.Designer.cs generated

@ -1558,6 +1558,15 @@ namespace ICSharpCode.ILSpy.Properties { @@ -1558,6 +1558,15 @@ namespace ICSharpCode.ILSpy.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Theme:.
/// </summary>
public static string DisplaySettingsPanel_Theme {
get {
return ResourceManager.GetString("DisplaySettingsPanel_Theme", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Download.
/// </summary>

3
ILSpy/Properties/Resources.resx

@ -540,6 +540,9 @@ Are you sure you want to continue?</value> @@ -540,6 +540,9 @@ Are you sure you want to continue?</value>
<data name="DisplaySettingsPanel_Font" xml:space="preserve">
<value>Font:</value>
</data>
<data name="DisplaySettingsPanel_Theme" xml:space="preserve">
<value>Theme:</value>
</data>
<data name="Download" xml:space="preserve">
<value>Download</value>
</data>

7
ILSpy/SessionSettings.cs

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

Loading…
Cancel
Save