Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 2ea88d6

Browse files
committed
Load a fixed (dark) theme at design time and whatever VS has at runtime
1 parent 808e859 commit 2ea88d6

18 files changed

+220
-137
lines changed

src/DesignTimeStyleHelper/App.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<ResourceDictionary.MergedDictionaries>
99
<ResourceDictionary Source="/GitHub.UI;component/SharedDictionary.xaml" />
1010
<ResourceDictionary Source="/GitHub.UI.Reactive;component/SharedDictionary.xaml" />
11+
<ResourceDictionary Source="/GitHub.VisualStudio;component/SharedDictionary.xaml" />
1112
</ResourceDictionary.MergedDictionaries>
1213
</ResourceDictionary>
1314
</Application.Resources>

src/GitHub.VisualStudio/Base/TeamExplorerNavigationItemBase.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,9 @@ public override async void Invalidate()
4343

4444
void OnThemeChanged()
4545
{
46-
try
47-
{
48-
var theme = Colors.DetectTheme();
49-
var dark = theme == "Dark";
50-
Icon = SharedResources.GetDrawingForIcon(octicon, dark ? Colors.DarkThemeNavigationItem : Colors.LightThemeNavigationItem, theme);
51-
}
52-
catch (ArgumentNullException)
53-
{
54-
// This throws in the unit test runner.
55-
}
46+
var theme = Colors.DetectTheme();
47+
var dark = theme == "Dark";
48+
Icon = SharedResources.GetDrawingForIcon(octicon, dark ? Colors.DarkThemeNavigationItem : Colors.LightThemeNavigationItem, theme);
5649
}
5750

5851
void UpdateRepo(ISimpleRepositoryModel repo)

src/GitHub.VisualStudio/GitHub.VisualStudio.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,10 @@
376376
<Generator>MSBuild:Compile</Generator>
377377
<SubType>Designer</SubType>
378378
</Page>
379+
<Page Include="Styles\ThemeDesignTime.xaml">
380+
<Generator>MSBuild:Compile</Generator>
381+
<SubType>Designer</SubType>
382+
</Page>
379383
<Page Include="Styles\ThemeLight.xaml">
380384
<Generator>MSBuild:Compile</Generator>
381385
<SubType>Designer</SubType>
@@ -387,6 +391,10 @@
387391
<Page Include="SharedDictionary.xaml">
388392
<Generator>MSBuild:Compile</Generator>
389393
</Page>
394+
<Page Include="Styles\VsBrush.xaml">
395+
<Generator>MSBuild:Compile</Generator>
396+
<SubType>Designer</SubType>
397+
</Page>
390398
<Page Include="UI\Views\Controls\ActionLinkButton.xaml">
391399
<SubType>Designer</SubType>
392400
<Generator>MSBuild:Compile</Generator>

src/GitHub.VisualStudio/Helpers/Colors.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,25 @@ public static Color ToColor(this System.Drawing.Color color)
3434

3535
public static string DetectTheme()
3636
{
37-
var color = VSColorTheme.GetThemedColor(EnvironmentColors.AccentMediumColorKey);
38-
var cc = color.ToColor();
39-
if (cc == AccentMediumBlueTheme)
40-
return "Blue";
41-
if (cc == AccentMediumLightTheme)
42-
return "Light";
43-
if (cc == AccentMediumDarkTheme)
37+
try
38+
{
39+
var color = VSColorTheme.GetThemedColor(EnvironmentColors.AccentMediumColorKey);
40+
var cc = color.ToColor();
41+
if (cc == AccentMediumBlueTheme)
42+
return "Blue";
43+
if (cc == AccentMediumLightTheme)
44+
return "Light";
45+
if (cc == AccentMediumDarkTheme)
46+
return "Dark";
47+
var brightness = color.GetBrightness();
48+
var dark = brightness > 0.5f;
49+
return dark ? "Dark" : "Light";
50+
}
51+
// this throws in design time and when running outside of VS
52+
catch (ArgumentNullException)
53+
{
4454
return "Dark";
45-
var brightness = color.GetBrightness();
46-
var dark = brightness > 0.5f;
47-
return dark ? "Dark" : "Light";
55+
}
4856
}
4957
}
5058
}

src/GitHub.VisualStudio/Helpers/SharedDictionaryManager.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.IO;
77
using System.Linq;
88
using Microsoft.VisualStudio.PlatformUI;
9+
using System.ComponentModel;
910

1011
namespace GitHub.VisualStudio.Helpers
1112
{
@@ -57,28 +58,31 @@ static Assembly LoadAssemblyFromRunDir(object sender, ResolveEventArgs e)
5758
return null;
5859
}
5960

60-
#region ResourceDictionaryImplementation
61+
#region ResourceDictionaryImplementation
62+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
63+
string currentTheme;
64+
65+
#if !DEBUG
6166
static readonly Dictionary<Uri, ResourceDictionary> resourceDicts = new Dictionary<Uri, ResourceDictionary>();
6267
static string baseThemeUri = "pack://application:,,,/GitHub.VisualStudio;component/Styles/";
6368

6469
Uri sourceUri;
65-
string currentTheme;
6670
bool themed = false;
6771
public new Uri Source
6872
{
6973
get { return sourceUri; }
7074
set
7175
{
72-
if (value.ToString() == "Theme.xaml")
76+
if (value.ToString() == "pack://application:,,,/GitHub.VisualStudio;component/Styles/ThemeDesignTime.xaml")
7377
{
74-
if (!themed)
78+
else if (!themed)
7579
{
7680
themed = true;
7781
VSColorTheme.ThemeChanged += OnThemeChange;
7882
}
7983
value = new Uri(baseThemeUri + "Theme" + currentTheme + ".xaml");
8084
}
81-
85+
8286
sourceUri = value;
8387
ResourceDictionary ret;
8488
if (resourceDicts.TryGetValue(value, out ret))
@@ -104,6 +108,7 @@ void OnThemeChange(ThemeChangedEventArgs e)
104108
currentTheme = Colors.DetectTheme();
105109
Source = uri;
106110
}
111+
#endif
107112
#endregion
108113
}
109114
}

src/GitHub.VisualStudio/SharedDictionary.xaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<ResourceDictionary
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options">
4+
xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
5+
xmlns:cache="clr-namespace:GitHub.VisualStudio.Helpers">
56

67
<ResourceDictionary.MergedDictionaries>
7-
<ResourceDictionary Source="pack://application:,,,/GitHub.VisualStudio;component/UI/Views/Controls/ActionLinkButton.xaml" />
8+
<cache:SharedDictionaryManager Source="pack://application:,,,/GitHub.VisualStudio;component/Styles/ThemeDesignTime.xaml"/>
9+
<cache:SharedDictionaryManager Source="pack://application:,,,/GitHub.VisualStudio;component/UI/Views/Controls/ActionLinkButton.xaml" />
810
</ResourceDictionary.MergedDictionaries>
911

1012
<Style x:Key="VSStyledButton" BasedOn="{StaticResource VsButtonStyleKey}" TargetType="{x:Type Button}" />
@@ -23,8 +25,8 @@
2325
<DrawingBrush.Drawing>
2426
<DrawingGroup>
2527
<DrawingGroup.Children>
26-
<GeometryDrawing Brush="{DynamicResource VsBrush.ControlLinkText}" Geometry="F1 M 9,11 L 7,11 9,9 4,9 4,7 9,7 7,5 9,5 12,8 Z" />
27-
<GeometryDrawing Brush="{DynamicResource VsBrush.ControlLinkText}" Geometry="F1 M 7.9741,1.0698 C 4.1461,1.0698 1.0441,4.1728 1.0441,7.9998 1.0441,11.8268 4.1461,14.9298 7.9741,14.9298 11.8011,14.9298 14.9041,11.8268 14.9041,7.9998 14.9041,4.1728 11.8011,1.0698 7.9741,1.0698 M 7.9741,2.0598 C 11.2501,2.0598 13.9151,4.7248 13.9151,7.9998 13.9151,11.2758 11.2501,13.9408 7.9741,13.9408 4.6991,13.9408 2.0341,11.2758 2.0341,7.9998 2.0341,4.7248 4.6991,2.0598 7.9741,2.0598 " />
28+
<GeometryDrawing Brush="{DynamicResource GitHubActionLinkItemBrush}" Geometry="F1 M 9,11 L 7,11 9,9 4,9 4,7 9,7 7,5 9,5 12,8 Z" />
29+
<GeometryDrawing Brush="{DynamicResource GitHubActionLinkItemBrush}" Geometry="F1 M 7.9741,1.0698 C 4.1461,1.0698 1.0441,4.1728 1.0441,7.9998 1.0441,11.8268 4.1461,14.9298 7.9741,14.9298 11.8011,14.9298 14.9041,11.8268 14.9041,7.9998 14.9041,4.1728 11.8011,1.0698 7.9741,1.0698 M 7.9741,2.0598 C 11.2501,2.0598 13.9151,4.7248 13.9151,7.9998 13.9151,11.2758 11.2501,13.9408 7.9741,13.9408 4.6991,13.9408 2.0341,11.2758 2.0341,7.9998 2.0341,4.7248 4.6991,2.0598 7.9741,2.0598 " />
2830
</DrawingGroup.Children>
2931
</DrawingGroup>
3032
</DrawingBrush.Drawing>

src/GitHub.VisualStudio/Styles/ThemeBlue.xaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,20 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options">
55

6+
<ResourceDictionary.MergedDictionaries>
7+
<ResourceDictionary Source="pack://application:,,,/GitHub.VisualStudio;component/Styles/VsBrush.xaml" />
8+
</ResourceDictionary.MergedDictionaries>
9+
610
<Color x:Key="GitHubContextMenuIconColor">#424242</Color>
711
<SolidColorBrush x:Key="GitHubContextMenuIconBrush" Color="{StaticResource GitHubContextMenuIconColor}" PresentationOptions:Freeze="true" />
812

13+
<Color x:Key="GitHubActionLinkItemColor">#FF0E70C0</Color>
14+
<SolidColorBrush x:Key="GitHubActionLinkItemBrush" Color="{StaticResource GitHubActionLinkItemColor}" PresentationOptions:Freeze="true" />
15+
16+
<Color x:Key="GitHubHeaderSeparatorColor">#FFCFD6E5</Color>
17+
<SolidColorBrush x:Key="GitHubHeaderSeparatorBrush" Color="{StaticResource GitHubHeaderSeparatorColor}" PresentationOptions:Freeze="true" />
18+
19+
<Color x:Key="GitHubPaneTitleColor">#FF1B293E</Color>
20+
<SolidColorBrush x:Key="GitHubPaneTitleBrush" Color="{StaticResource GitHubPaneTitleColor}" />
21+
922
</ResourceDictionary>

src/GitHub.VisualStudio/Styles/ThemeDark.xaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,20 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options">
55

6+
<ResourceDictionary.MergedDictionaries>
7+
<ResourceDictionary Source="pack://application:,,,/GitHub.VisualStudio;component/Styles/VsBrush.xaml" />
8+
</ResourceDictionary.MergedDictionaries>
9+
610
<Color x:Key="GitHubContextMenuIconColor">#424242</Color>
711
<SolidColorBrush x:Key="GitHubContextMenuIconBrush" Color="{StaticResource GitHubContextMenuIconColor}" PresentationOptions:Freeze="true" />
812

13+
<Color x:Key="GitHubActionLinkItemColor">#FF0097FB</Color>
14+
<SolidColorBrush x:Key="GitHubActionLinkItemBrush" Color="{StaticResource GitHubActionLinkItemColor}" PresentationOptions:Freeze="true" />
15+
16+
<Color x:Key="GitHubHeaderSeparatorColor">#FF2D2D30</Color>
17+
<SolidColorBrush x:Key="GitHubHeaderSeparatorBrush" Color="{StaticResource GitHubHeaderSeparatorColor}" PresentationOptions:Freeze="true" />
18+
19+
<Color x:Key="GitHubPaneTitleColor">#FFFFFFFF</Color>
20+
<SolidColorBrush x:Key="GitHubPaneTitleBrush" Color="{StaticResource GitHubPaneTitleColor}" />
21+
922
</ResourceDictionary>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<ResourceDictionary
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options">
5+
6+
<ResourceDictionary.MergedDictionaries>
7+
<ResourceDictionary Source="pack://application:,,,/GitHub.VisualStudio;component/Styles/ThemeDark.xaml" />
8+
</ResourceDictionary.MergedDictionaries>
9+
10+
<!-- Design time colors taken from the VS dark theme -->
11+
<SolidColorBrush x:Key="GitHubVsToolWindowText" Color="#FFFFFFFF" />
12+
<SolidColorBrush x:Key="GitHubVsToolWindowBackground" Color="#FF252526" />
13+
<SolidColorBrush x:Key="GitHubVsGrayText" Color="#FF999999" />
14+
<SolidColorBrush x:Key="GitHubVsCommandBarHover" Color="#FF3E3E40" />
15+
<SolidColorBrush x:Key="GitHubVsCommandBarSelectedBorder" Color="#FF3399FF" />
16+
<SolidColorBrush x:Key="GitHubVsSearchBoxBackground" Color="#FF333337" />
17+
<SolidColorBrush x:Key="GitHubVsWindowText" Color="#FFF1F1F1" />
18+
</ResourceDictionary>

src/GitHub.VisualStudio/Styles/ThemeLight.xaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,20 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options">
55

6+
<ResourceDictionary.MergedDictionaries>
7+
<ResourceDictionary Source="pack://application:,,,/GitHub.VisualStudio;component/Styles/VsBrush.xaml" />
8+
</ResourceDictionary.MergedDictionaries>
9+
610
<Color x:Key="GitHubContextMenuIconColor">#424242</Color>
711
<SolidColorBrush x:Key="GitHubContextMenuIconBrush" Color="{StaticResource GitHubContextMenuIconColor}" PresentationOptions:Freeze="true" />
812

13+
<Color x:Key="GitHubActionLinkItemColor">#FF0E70C0</Color>
14+
<SolidColorBrush x:Key="GitHubActionLinkItemBrush" Color="{StaticResource GitHubActionLinkItemColor}" PresentationOptions:Freeze="true" />
15+
16+
<Color x:Key="GitHubHeaderSeparatorColor">#FFEEEEF2</Color>
17+
<SolidColorBrush x:Key="GitHubHeaderSeparatorBrush" Color="{StaticResource GitHubHeaderSeparatorColor}" PresentationOptions:Freeze="true" />
18+
19+
<Color x:Key="GitHubPaneTitleColor">#FF1B293E</Color>
20+
<SolidColorBrush x:Key="GitHubPaneTitleBrush" Color="{StaticResource GitHubPaneTitleColor}" />
21+
922
</ResourceDictionary>

0 commit comments

Comments
 (0)