Skip to content

Commit d3799d0

Browse files
committed
Identify themes by name
1 parent f0295e7 commit d3799d0

12 files changed

+38
-44
lines changed

ILSpy/ILSpy.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
<Link>license.txt</Link>
6565
</EmbeddedResource>
6666
<Resource Include="Images\NuGet.png" />
67-
<Resource Include="Images\DarkMode.png" />
6867
<Resource Include="Images\ILSpy.ico" />
6968
<EmbeddedResource Include="TextView\CSharp-Mode.xshd" />
7069
<EmbeddedResource Include="TextView\ILAsm-Mode.xshd" />

ILSpy/Images/DarkMode.png

-320 Bytes
Binary file not shown.

ILSpy/MainWindow.xaml

+4-10
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@
9292
<ContentPresenter Content="{Binding Content}" />
9393
</DataTemplate>
9494

95-
<styles:InvertGrayEffect x:Key="InvertGrayEffect" />
96-
9795
<controls:CultureSelectionConverter x:Key="cultureSelectionConverter" />
9896

9997
</Window.Resources>
@@ -164,17 +162,13 @@
164162
</Style.Triggers>
165163
</Style>
166164
<Style TargetType="{x:Type Image}" x:Key="DarkModeAwareImageStyle">
165+
<Setter Property="Effect" Value="{DynamicResource {x:Static themes:ResourceKeys.ThemeAwareButtonEffect}}" />
167166
<Style.Triggers>
168167
<DataTrigger
169168
Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type ButtonBase}, AncestorLevel=1}, Path=IsEnabled}"
170169
Value="False">
171170
<Setter Property="Opacity" Value="0.30" />
172171
</DataTrigger>
173-
<DataTrigger
174-
Binding="{Binding SessionSettings.IsDarkMode}"
175-
Value="True">
176-
<Setter Property="Effect" Value="{StaticResource InvertGrayEffect}" />
177-
</DataTrigger>
178172
</Style.Triggers>
179173
</Style>
180174
</ToolBar.Resources>
@@ -209,9 +203,9 @@
209203
ItemsSource="{Binding SelectedItem.LanguageVersions, ElementName=languageComboBox, UpdateSourceTrigger=PropertyChanged}"
210204
SelectedItem="{Binding Workspace.ActiveTabPage.FilterSettings.LanguageVersion, UpdateSourceTrigger=PropertyChanged}"/>
211205
<Separator />
212-
<CheckBox IsChecked="{Binding SessionSettings.IsDarkMode}" ToolTip="{x:Static properties:Resources.DarkMode}">
213-
<Image Source="Images/DarkMode.png" Stretch="None" Style="{StaticResource DarkModeAwareImageStyle}"/>
214-
</CheckBox>
206+
<ComboBox Width="100" MaxDropDownHeight="Auto" ToolTip="{x:Static properties:Resources.Theme}"
207+
ItemsSource="{x:Static themes:ThemeManager.AllThemes}"
208+
SelectedItem="{Binding SessionSettings.Theme}"/>
215209
</ToolBar>
216210
<Border DockPanel.Dock="Top" BorderBrush="Black" BorderThickness="1" Name="updatePanel" Visibility="Collapsed">
217211
<DockPanel KeyboardNavigation.TabNavigation="Contained">

ILSpy/MainWindow.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ private void SessionSettings_PropertyChanged(object sender, PropertyChangedEvent
184184
case nameof(SessionSettings.ActiveAssemblyList):
185185
ShowAssemblyList(sessionSettings.ActiveAssemblyList);
186186
break;
187-
case nameof(SessionSettings.IsDarkMode):
187+
case nameof(SessionSettings.Theme):
188188
// update syntax highlighting and force reload (AvalonEdit does not automatically refresh on highlighting change)
189189
DecompilerTextView.RegisterHighlighting();
190190
DecompileSelectedNodes(DockWorkspace.Instance.ActiveTabPage.GetState() as DecompilerTextViewState);

ILSpy/Properties/Resources.Designer.cs

+9-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ILSpy/Properties/Resources.resx

+3-3
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,6 @@ Are you sure you want to continue?</value>
222222
<data name="DEBUGDumpPDBAsXML" xml:space="preserve">
223223
<value>DEBUG -- Dump PDB as XML</value>
224224
</data>
225-
<data name="DarkMode" xml:space="preserve">
226-
<value>Dark Mode</value>
227-
</data>
228225
<data name="DebugSteps" xml:space="preserve">
229226
<value>Debug Steps</value>
230227
</data>
@@ -907,6 +904,9 @@ Do you want to continue?</value>
907904
<data name="TabSize" xml:space="preserve">
908905
<value>Tab size:</value>
909906
</data>
907+
<data name="Theme" xml:space="preserve">
908+
<value>Theme</value>
909+
</data>
910910
<data name="ToggleFolding" xml:space="preserve">
911911
<value>Toggle All Folding</value>
912912
</data>

ILSpy/Properties/Resources.zh-Hans.resx

-3
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,6 @@
222222
<data name="DEBUGDumpPDBAsXML" xml:space="preserve">
223223
<value>调试 -- PDB 转储为 XML</value>
224224
</data>
225-
<data name="DarkMode" xml:space="preserve">
226-
<value>深色</value>
227-
</data>
228225
<data name="DebugSteps" xml:space="preserve">
229226
<value>调试步骤</value>
230227
</data>

ILSpy/SessionSettings.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public SessionSettings(ILSpySettings spySettings)
6464
this.TopPaneSplitterPosition = FromString((string)doc.Element("TopPaneSplitterPosition"), 0.3);
6565
this.BottomPaneSplitterPosition = FromString((string)doc.Element("BottomPaneSplitterPosition"), 0.3);
6666
this.SelectedSearchMode = FromString((string)doc.Element("SelectedSearchMode"), SearchMode.TypeAndMember);
67-
this.IsDarkMode = FromString((string)doc.Element(nameof(IsDarkMode)), false);
67+
this.Theme = FromString((string)doc.Element(nameof(Theme)), ThemeManager.Current.DefaultTheme);
6868
string currentCulture = (string)doc.Element(nameof(CurrentCulture));
6969
this.CurrentCulture = string.IsNullOrEmpty(currentCulture) ? null : currentCulture;
7070

@@ -81,10 +81,10 @@ void OnPropertyChanged([CallerMemberName] string propertyName = null)
8181
public FilterSettings FilterSettings { get; internal set; }
8282
public SearchMode SelectedSearchMode { get; set; }
8383

84-
public bool IsDarkMode {
85-
get => ThemeManager.Current.IsDarkMode;
84+
public string Theme {
85+
get => ThemeManager.Current.Theme;
8686
set {
87-
ThemeManager.Current.IsDarkMode = value;
87+
ThemeManager.Current.Theme = value;
8888
OnPropertyChanged();
8989
}
9090
}
@@ -149,7 +149,7 @@ public void Save()
149149
doc.Add(new XElement("TopPaneSplitterPosition", ToString(this.TopPaneSplitterPosition)));
150150
doc.Add(new XElement("BottomPaneSplitterPosition", ToString(this.BottomPaneSplitterPosition)));
151151
doc.Add(new XElement("SelectedSearchMode", ToString(this.SelectedSearchMode)));
152-
doc.Add(new XElement(nameof(IsDarkMode), ToString(this.IsDarkMode)));
152+
doc.Add(new XElement(nameof(Theme), ToString(this.Theme)));
153153
if (this.CurrentCulture != null)
154154
{
155155
doc.Add(new XElement(nameof(CurrentCulture), this.CurrentCulture));

ILSpy/TextView/DecompilerTextView.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ public static void RegisterHighlighting(
13641364
string[] extensions,
13651365
string resourceName)
13661366
{
1367-
if (ThemeManager.Current.IsDarkMode)
1367+
if (ThemeManager.Current.Theme == "Dark")
13681368
{
13691369
resourceName += "-Dark";
13701370
}

ILSpy/Themes/DarkTheme.xaml

+2
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,6 @@
6363
<Color x:Key="{x:Static themes:ResourceKeys.TextMarkerBackgroundColor}">MediumVioletRed</Color>
6464
<SolidColorBrush x:Key="{x:Static themes:ResourceKeys.LinkTextForegroundBrush}">CornflowerBlue</SolidColorBrush>
6565

66+
<styles:InvertGrayEffect x:Key="{x:Static themes:ResourceKeys.ThemeAwareButtonEffect}" />
67+
6668
</ResourceDictionary>

ILSpy/Themes/ResourceKeys.cs

+2
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,7 @@ public static class ResourceKeys
2929
public static ResourceKey LinkTextForegroundBrush = new ComponentResourceKey(typeof(ResourceKeys), "LinkTextForegroundBrush");
3030
public static ResourceKey BracketHighlightBackgroundBrush = new ComponentResourceKey(typeof(ResourceKeys), "BracketHighlightBackgroundBrush");
3131
public static ResourceKey BracketHighlightBorderPen = new ComponentResourceKey(typeof(ResourceKeys), "BracketHighlightBorderPen");
32+
33+
public static ResourceKey ThemeAwareButtonEffect = new ComponentResourceKey(typeof(ResourceKeys), nameof(ThemeAwareButtonEffect));
3234
}
3335
}

ILSpy/Themes/ThemeManager.cs

+11-10
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,35 @@
1717
// DEALINGS IN THE SOFTWARE.
1818

1919
using System;
20+
using System.Collections.Generic;
2021
using System.Windows;
2122
using System.Windows.Controls;
2223

2324
namespace ICSharpCode.ILSpy.Themes
2425
{
25-
internal class ThemeManager
26+
public class ThemeManager
2627
{
27-
private bool _isDarkMode;
28+
private static List<string> _allThemes;
29+
private string _theme;
2830
private readonly ResourceDictionary _themeDictionaryContainer = new ResourceDictionary();
2931

30-
3132
public static readonly ThemeManager Current = new ThemeManager();
3233

3334
private ThemeManager()
3435
{
3536
Application.Current.Resources.MergedDictionaries.Add(_themeDictionaryContainer);
3637
}
3738

38-
public bool IsDarkMode {
39-
get => _isDarkMode;
39+
public string DefaultTheme => "Light";
40+
public static IReadOnlyCollection<string> AllThemes => new[] { "Light", "Dark" };
41+
42+
public string Theme {
43+
get => _theme;
4044
set {
41-
_isDarkMode = value;
45+
_theme = value;
4246

4347
_themeDictionaryContainer.MergedDictionaries.Clear();
44-
45-
string theme = value ? "Dark" : "Light";
46-
47-
_themeDictionaryContainer.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri($"themes/{theme}Theme.xaml", UriKind.Relative) });
48+
_themeDictionaryContainer.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri($"themes/{value}Theme.xaml", UriKind.Relative) });
4849
}
4950
}
5051

0 commit comments

Comments
 (0)