Browse Source

Identify themes by name

pull/2906/head
Lucas Trzesniewski 2 years ago
parent
commit
d3799d0323
  1. 1
      ILSpy/ILSpy.csproj
  2. BIN
      ILSpy/Images/DarkMode.png
  3. 14
      ILSpy/MainWindow.xaml
  4. 2
      ILSpy/MainWindow.xaml.cs
  5. 19
      ILSpy/Properties/Resources.Designer.cs
  6. 6
      ILSpy/Properties/Resources.resx
  7. 3
      ILSpy/Properties/Resources.zh-Hans.resx
  8. 10
      ILSpy/SessionSettings.cs
  9. 2
      ILSpy/TextView/DecompilerTextView.cs
  10. 2
      ILSpy/Themes/DarkTheme.xaml
  11. 2
      ILSpy/Themes/ResourceKeys.cs
  12. 21
      ILSpy/Themes/ThemeManager.cs

1
ILSpy/ILSpy.csproj

@ -64,7 +64,6 @@
<Link>license.txt</Link> <Link>license.txt</Link>
</EmbeddedResource> </EmbeddedResource>
<Resource Include="Images\NuGet.png" /> <Resource Include="Images\NuGet.png" />
<Resource Include="Images\DarkMode.png" />
<Resource Include="Images\ILSpy.ico" /> <Resource Include="Images\ILSpy.ico" />
<EmbeddedResource Include="TextView\CSharp-Mode.xshd" /> <EmbeddedResource Include="TextView\CSharp-Mode.xshd" />
<EmbeddedResource Include="TextView\ILAsm-Mode.xshd" /> <EmbeddedResource Include="TextView\ILAsm-Mode.xshd" />

BIN
ILSpy/Images/DarkMode.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 320 B

14
ILSpy/MainWindow.xaml

@ -92,8 +92,6 @@
<ContentPresenter Content="{Binding Content}" /> <ContentPresenter Content="{Binding Content}" />
</DataTemplate> </DataTemplate>
<styles:InvertGrayEffect x:Key="InvertGrayEffect" />
<controls:CultureSelectionConverter x:Key="cultureSelectionConverter" /> <controls:CultureSelectionConverter x:Key="cultureSelectionConverter" />
</Window.Resources> </Window.Resources>
@ -164,17 +162,13 @@
</Style.Triggers> </Style.Triggers>
</Style> </Style>
<Style TargetType="{x:Type Image}" x:Key="DarkModeAwareImageStyle"> <Style TargetType="{x:Type Image}" x:Key="DarkModeAwareImageStyle">
<Setter Property="Effect" Value="{DynamicResource {x:Static themes:ResourceKeys.ThemeAwareButtonEffect}}" />
<Style.Triggers> <Style.Triggers>
<DataTrigger <DataTrigger
Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type ButtonBase}, AncestorLevel=1}, Path=IsEnabled}" Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type ButtonBase}, AncestorLevel=1}, Path=IsEnabled}"
Value="False"> Value="False">
<Setter Property="Opacity" Value="0.30" /> <Setter Property="Opacity" Value="0.30" />
</DataTrigger> </DataTrigger>
<DataTrigger
Binding="{Binding SessionSettings.IsDarkMode}"
Value="True">
<Setter Property="Effect" Value="{StaticResource InvertGrayEffect}" />
</DataTrigger>
</Style.Triggers> </Style.Triggers>
</Style> </Style>
</ToolBar.Resources> </ToolBar.Resources>
@ -209,9 +203,9 @@
ItemsSource="{Binding SelectedItem.LanguageVersions, ElementName=languageComboBox, UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding SelectedItem.LanguageVersions, ElementName=languageComboBox, UpdateSourceTrigger=PropertyChanged}"
SelectedItem="{Binding Workspace.ActiveTabPage.FilterSettings.LanguageVersion, UpdateSourceTrigger=PropertyChanged}"/> SelectedItem="{Binding Workspace.ActiveTabPage.FilterSettings.LanguageVersion, UpdateSourceTrigger=PropertyChanged}"/>
<Separator /> <Separator />
<CheckBox IsChecked="{Binding SessionSettings.IsDarkMode}" ToolTip="{x:Static properties:Resources.DarkMode}"> <ComboBox Width="100" MaxDropDownHeight="Auto" ToolTip="{x:Static properties:Resources.Theme}"
<Image Source="Images/DarkMode.png" Stretch="None" Style="{StaticResource DarkModeAwareImageStyle}"/> ItemsSource="{x:Static themes:ThemeManager.AllThemes}"
</CheckBox> SelectedItem="{Binding SessionSettings.Theme}"/>
</ToolBar> </ToolBar>
<Border DockPanel.Dock="Top" BorderBrush="Black" BorderThickness="1" Name="updatePanel" Visibility="Collapsed"> <Border DockPanel.Dock="Top" BorderBrush="Black" BorderThickness="1" Name="updatePanel" Visibility="Collapsed">
<DockPanel KeyboardNavigation.TabNavigation="Contained"> <DockPanel KeyboardNavigation.TabNavigation="Contained">

2
ILSpy/MainWindow.xaml.cs

@ -184,7 +184,7 @@ namespace ICSharpCode.ILSpy
case nameof(SessionSettings.ActiveAssemblyList): case nameof(SessionSettings.ActiveAssemblyList):
ShowAssemblyList(sessionSettings.ActiveAssemblyList); ShowAssemblyList(sessionSettings.ActiveAssemblyList);
break; break;
case nameof(SessionSettings.IsDarkMode): case nameof(SessionSettings.Theme):
// update syntax highlighting and force reload (AvalonEdit does not automatically refresh on highlighting change) // update syntax highlighting and force reload (AvalonEdit does not automatically refresh on highlighting change)
DecompilerTextView.RegisterHighlighting(); DecompilerTextView.RegisterHighlighting();
DecompileSelectedNodes(DockWorkspace.Instance.ActiveTabPage.GetState() as DecompilerTextViewState); DecompileSelectedNodes(DockWorkspace.Instance.ActiveTabPage.GetState() as DecompilerTextViewState);

19
ILSpy/Properties/Resources.Designer.cs generated

@ -1,7 +1,6 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// This code was generated by a tool. // This code was generated by a tool.
// Runtime Version:4.0.30319.42000
// //
// Changes to this file may cause incorrect behavior and will be lost if // Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated. // the code is regenerated.
@ -567,15 +566,6 @@ namespace ICSharpCode.ILSpy.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to Dark Mode.
/// </summary>
public static string DarkMode {
get {
return ResourceManager.GetString("DarkMode", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to DEBUG -- Decompile All. /// Looks up a localized string similar to DEBUG -- Decompile All.
/// </summary> /// </summary>
@ -2646,6 +2636,15 @@ namespace ICSharpCode.ILSpy.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to Theme.
/// </summary>
public static string Theme {
get {
return ResourceManager.GetString("Theme", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Toggle All Folding. /// Looks up a localized string similar to Toggle All Folding.
/// </summary> /// </summary>

6
ILSpy/Properties/Resources.resx

@ -222,9 +222,6 @@ Are you sure you want to continue?</value>
<data name="DEBUGDumpPDBAsXML" xml:space="preserve"> <data name="DEBUGDumpPDBAsXML" xml:space="preserve">
<value>DEBUG -- Dump PDB as XML</value> <value>DEBUG -- Dump PDB as XML</value>
</data> </data>
<data name="DarkMode" xml:space="preserve">
<value>Dark Mode</value>
</data>
<data name="DebugSteps" xml:space="preserve"> <data name="DebugSteps" xml:space="preserve">
<value>Debug Steps</value> <value>Debug Steps</value>
</data> </data>
@ -907,6 +904,9 @@ Do you want to continue?</value>
<data name="TabSize" xml:space="preserve"> <data name="TabSize" xml:space="preserve">
<value>Tab size:</value> <value>Tab size:</value>
</data> </data>
<data name="Theme" xml:space="preserve">
<value>Theme</value>
</data>
<data name="ToggleFolding" xml:space="preserve"> <data name="ToggleFolding" xml:space="preserve">
<value>Toggle All Folding</value> <value>Toggle All Folding</value>
</data> </data>

3
ILSpy/Properties/Resources.zh-Hans.resx

@ -222,9 +222,6 @@
<data name="DEBUGDumpPDBAsXML" xml:space="preserve"> <data name="DEBUGDumpPDBAsXML" xml:space="preserve">
<value>调试 -- PDB 转储为 XML</value> <value>调试 -- PDB 转储为 XML</value>
</data> </data>
<data name="DarkMode" xml:space="preserve">
<value>深色</value>
</data>
<data name="DebugSteps" xml:space="preserve"> <data name="DebugSteps" xml:space="preserve">
<value>调试步骤</value> <value>调试步骤</value>
</data> </data>

10
ILSpy/SessionSettings.cs

@ -64,7 +64,7 @@ namespace ICSharpCode.ILSpy
this.TopPaneSplitterPosition = FromString((string)doc.Element("TopPaneSplitterPosition"), 0.3); this.TopPaneSplitterPosition = FromString((string)doc.Element("TopPaneSplitterPosition"), 0.3);
this.BottomPaneSplitterPosition = FromString((string)doc.Element("BottomPaneSplitterPosition"), 0.3); this.BottomPaneSplitterPosition = FromString((string)doc.Element("BottomPaneSplitterPosition"), 0.3);
this.SelectedSearchMode = FromString((string)doc.Element("SelectedSearchMode"), SearchMode.TypeAndMember); this.SelectedSearchMode = FromString((string)doc.Element("SelectedSearchMode"), SearchMode.TypeAndMember);
this.IsDarkMode = FromString((string)doc.Element(nameof(IsDarkMode)), false); this.Theme = FromString((string)doc.Element(nameof(Theme)), ThemeManager.Current.DefaultTheme);
string currentCulture = (string)doc.Element(nameof(CurrentCulture)); string currentCulture = (string)doc.Element(nameof(CurrentCulture));
this.CurrentCulture = string.IsNullOrEmpty(currentCulture) ? null : currentCulture; this.CurrentCulture = string.IsNullOrEmpty(currentCulture) ? null : currentCulture;
@ -81,10 +81,10 @@ namespace ICSharpCode.ILSpy
public FilterSettings FilterSettings { get; internal set; } public FilterSettings FilterSettings { get; internal set; }
public SearchMode SelectedSearchMode { get; set; } public SearchMode SelectedSearchMode { get; set; }
public bool IsDarkMode { public string Theme {
get => ThemeManager.Current.IsDarkMode; get => ThemeManager.Current.Theme;
set { set {
ThemeManager.Current.IsDarkMode = value; ThemeManager.Current.Theme = value;
OnPropertyChanged(); OnPropertyChanged();
} }
} }
@ -149,7 +149,7 @@ namespace ICSharpCode.ILSpy
doc.Add(new XElement("TopPaneSplitterPosition", ToString(this.TopPaneSplitterPosition))); doc.Add(new XElement("TopPaneSplitterPosition", ToString(this.TopPaneSplitterPosition)));
doc.Add(new XElement("BottomPaneSplitterPosition", ToString(this.BottomPaneSplitterPosition))); doc.Add(new XElement("BottomPaneSplitterPosition", ToString(this.BottomPaneSplitterPosition)));
doc.Add(new XElement("SelectedSearchMode", ToString(this.SelectedSearchMode))); doc.Add(new XElement("SelectedSearchMode", ToString(this.SelectedSearchMode)));
doc.Add(new XElement(nameof(IsDarkMode), ToString(this.IsDarkMode))); doc.Add(new XElement(nameof(Theme), ToString(this.Theme)));
if (this.CurrentCulture != null) if (this.CurrentCulture != null)
{ {
doc.Add(new XElement(nameof(CurrentCulture), this.CurrentCulture)); doc.Add(new XElement(nameof(CurrentCulture), this.CurrentCulture));

2
ILSpy/TextView/DecompilerTextView.cs

@ -1364,7 +1364,7 @@ namespace ICSharpCode.ILSpy.TextView
string[] extensions, string[] extensions,
string resourceName) string resourceName)
{ {
if (ThemeManager.Current.IsDarkMode) if (ThemeManager.Current.Theme == "Dark")
{ {
resourceName += "-Dark"; resourceName += "-Dark";
} }

2
ILSpy/Themes/DarkTheme.xaml

@ -63,4 +63,6 @@
<Color x:Key="{x:Static themes:ResourceKeys.TextMarkerBackgroundColor}">MediumVioletRed</Color> <Color x:Key="{x:Static themes:ResourceKeys.TextMarkerBackgroundColor}">MediumVioletRed</Color>
<SolidColorBrush x:Key="{x:Static themes:ResourceKeys.LinkTextForegroundBrush}">CornflowerBlue</SolidColorBrush> <SolidColorBrush x:Key="{x:Static themes:ResourceKeys.LinkTextForegroundBrush}">CornflowerBlue</SolidColorBrush>
<styles:InvertGrayEffect x:Key="{x:Static themes:ResourceKeys.ThemeAwareButtonEffect}" />
</ResourceDictionary> </ResourceDictionary>

2
ILSpy/Themes/ResourceKeys.cs

@ -29,5 +29,7 @@ namespace ICSharpCode.ILSpy.Themes
public static ResourceKey LinkTextForegroundBrush = new ComponentResourceKey(typeof(ResourceKeys), "LinkTextForegroundBrush"); public static ResourceKey LinkTextForegroundBrush = new ComponentResourceKey(typeof(ResourceKeys), "LinkTextForegroundBrush");
public static ResourceKey BracketHighlightBackgroundBrush = new ComponentResourceKey(typeof(ResourceKeys), "BracketHighlightBackgroundBrush"); public static ResourceKey BracketHighlightBackgroundBrush = new ComponentResourceKey(typeof(ResourceKeys), "BracketHighlightBackgroundBrush");
public static ResourceKey BracketHighlightBorderPen = new ComponentResourceKey(typeof(ResourceKeys), "BracketHighlightBorderPen"); public static ResourceKey BracketHighlightBorderPen = new ComponentResourceKey(typeof(ResourceKeys), "BracketHighlightBorderPen");
public static ResourceKey ThemeAwareButtonEffect = new ComponentResourceKey(typeof(ResourceKeys), nameof(ThemeAwareButtonEffect));
} }
} }

21
ILSpy/Themes/ThemeManager.cs

@ -17,17 +17,18 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System; using System;
using System.Collections.Generic;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
namespace ICSharpCode.ILSpy.Themes namespace ICSharpCode.ILSpy.Themes
{ {
internal class ThemeManager public class ThemeManager
{ {
private bool _isDarkMode; private static List<string> _allThemes;
private string _theme;
private readonly ResourceDictionary _themeDictionaryContainer = new ResourceDictionary(); private readonly ResourceDictionary _themeDictionaryContainer = new ResourceDictionary();
public static readonly ThemeManager Current = new ThemeManager(); public static readonly ThemeManager Current = new ThemeManager();
private ThemeManager() private ThemeManager()
@ -35,16 +36,16 @@ namespace ICSharpCode.ILSpy.Themes
Application.Current.Resources.MergedDictionaries.Add(_themeDictionaryContainer); Application.Current.Resources.MergedDictionaries.Add(_themeDictionaryContainer);
} }
public bool IsDarkMode { public string DefaultTheme => "Light";
get => _isDarkMode; public static IReadOnlyCollection<string> AllThemes => new[] { "Light", "Dark" };
public string Theme {
get => _theme;
set { set {
_isDarkMode = value; _theme = value;
_themeDictionaryContainer.MergedDictionaries.Clear(); _themeDictionaryContainer.MergedDictionaries.Clear();
_themeDictionaryContainer.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri($"themes/{value}Theme.xaml", UriKind.Relative) });
string theme = value ? "Dark" : "Light";
_themeDictionaryContainer.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri($"themes/{theme}Theme.xaml", UriKind.Relative) });
} }
} }

Loading…
Cancel
Save