Skip to content

Commit 9a1a6d0

Browse files
Change "codebashing" text to clickable icon (AST-111733) (#280)
* Change "codebashing" text to clickable icon AST-111733 --------- Co-authored-by: cx-Margarita-LevitM <cx-margarita-levitm>
1 parent 4ff56db commit 9a1a6d0

File tree

5 files changed

+104
-6
lines changed

5 files changed

+104
-6
lines changed

ast-visual-studio-extension/CxExtension/CxWindowControl.xaml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:local="clr-namespace:ast_visual_studio_extension"
7+
xmlns:converters="clr-namespace:ast_visual_studio_extension"
78
xmlns:GenericWPF="clr-namespace:ast_visual_studio_extension.CxExtension.Utils"
89
xmlns:imaging="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.Imaging"
910
xmlns:catalog="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.ImageCatalog"
1011
xmlns:theming="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Imaging"
11-
xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0" xmlns:cxextension="clr-namespace:ast_visual_studio_extension.CxExtension" d:DataContext="{d:DesignInstance Type=cxextension:CxWindowControl}"
12+
xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0"
13+
xmlns:vs="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.15.0"
14+
xmlns:cxextension="clr-namespace:ast_visual_studio_extension.CxExtension" d:DataContext="{d:DesignInstance Type=cxextension:CxWindowControl}"
1215
local:VsTheme.UseVsTheme="True"
1316
mc:Ignorable="d"
1417
d:DesignHeight="300" d:DesignWidth="1308"
1518
Name="CxWindow">
1619

1720
<UserControl.Resources>
21+
<converters:ResourceKeyToColorConverter x:Key="ResourceKeyToColorConverter"/>
1822
<Style TargetType="{x:Type TextBlock}">
1923
<Setter Property="Foreground" Value="{Binding Foreground, ElementName=hiddenLbl}"/>
2024
</Style>
@@ -535,10 +539,22 @@
535539
<TextBlock TextWrapping="WrapWithOverflow" Grid.Column="1" x:Name="ResultTitle" FontSize="15" Margin="7,2,0,0"/>
536540
</WrapPanel>
537541

538-
<TextBlock Visibility="Hidden" x:Name="CodebashingTextBlock" Grid.Column="2" Margin="0,6,0,0">
539-
<Run>Learn more at</Run>
540-
<Run Cursor="Hand" Foreground="Orange" FontWeight="Bold" MouseUp="OnClickCodebashingLink"> >_</Run>
541-
<Run Cursor="Hand" MouseUp="OnClickCodebashingLink">codebashing</Run>
542+
<TextBlock Visibility="Visible" x:Name="CodebashingTextBlock" Grid.Column="2" Margin="0,6,0,0">
543+
<Run>Learn more at</Run>
544+
<InlineUIContainer BaselineAlignment="Center">
545+
<Image Height="35" Cursor="Hand" MouseUp="OnClickCodebashingLink">
546+
<Image.Style>
547+
<Style TargetType="Image">
548+
<Setter Property="Source" Value="Resources/CodeBashing_logoDarkTheme.png"/>
549+
<Style.Triggers>
550+
<DataTrigger Binding="{Binding Source={x:Static local:ThemeManager.Instance}, Path=IsDarkTheme}" Value="False">
551+
<Setter Property="Source" Value="Resources/CodeBashing_logoLightTheme.png"/>
552+
</DataTrigger>
553+
</Style.Triggers>
554+
</Style>
555+
</Image.Style>
556+
</Image>
557+
</InlineUIContainer>
542558
</TextBlock>
543559
</Grid>
544560

@@ -793,4 +809,4 @@
793809
</Grid>
794810

795811

796-
</UserControl>
812+
</UserControl>
23.4 KB
Loading
140 KB
Loading
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System;
2+
using System.ComponentModel;
3+
using System.Globalization;
4+
using System.Windows.Data;
5+
using System.Windows.Media;
6+
using Microsoft.VisualStudio.PlatformUI;
7+
using Microsoft.VisualStudio.Shell;
8+
9+
namespace ast_visual_studio_extension
10+
{
11+
public class ResourceKeyToColorConverter : IValueConverter
12+
{
13+
public static bool IsDarkTheme => IsDarkThemeMethod();
14+
15+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
16+
{
17+
if (value is ThemeResourceKey resourceKey)
18+
{
19+
var color = VSColorTheme.GetThemedColor(resourceKey);
20+
return Color.FromArgb(color.A, color.R, color.G, color.B);
21+
}
22+
23+
return Colors.Black;
24+
}
25+
26+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
27+
{
28+
throw new NotImplementedException();
29+
}
30+
31+
public static bool IsDarkThemeMethod()
32+
{
33+
var backgroundColor = VSColorTheme.GetThemedColor(EnvironmentColors.SystemWindowBrushKey);
34+
35+
double brightness = (0.299 * backgroundColor.R + 0.587 * backgroundColor.G + 0.114 * backgroundColor.B);
36+
37+
return brightness < 128;
38+
}
39+
}
40+
41+
public class ThemeManager : INotifyPropertyChanged
42+
{
43+
private static readonly Lazy<ThemeManager> _instance = new Lazy<ThemeManager>(() => new ThemeManager());
44+
public static ThemeManager Instance => _instance.Value;
45+
46+
private bool _isDarkTheme;
47+
48+
public event PropertyChangedEventHandler PropertyChanged;
49+
50+
private ThemeManager()
51+
{
52+
_isDarkTheme = ResourceKeyToColorConverter.IsDarkThemeMethod();
53+
54+
VSColorTheme.ThemeChanged += OnThemeChanged;
55+
}
56+
57+
public bool IsDarkTheme
58+
{
59+
get => _isDarkTheme;
60+
private set
61+
{
62+
if (_isDarkTheme != value)
63+
{
64+
_isDarkTheme = value;
65+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsDarkTheme)));
66+
}
67+
}
68+
}
69+
70+
private void OnThemeChanged(ThemeChangedEventArgs e)
71+
{
72+
IsDarkTheme = ResourceKeyToColorConverter.IsDarkThemeMethod();
73+
}
74+
}
75+
}

ast-visual-studio-extension/ast-visual-studio-extension.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
</Compile>
147147
<Compile Include="Properties\AssemblyInfo.cs" />
148148
<Compile Include="ast_visual_studio_extensionPackage.cs" />
149+
<Compile Include="ResourceKeyToColorConverter.cs" />
149150
<Compile Include="VsTheme.cs" />
150151
</ItemGroup>
151152
<ItemGroup>
@@ -198,6 +199,12 @@
198199
<Resource Include="CxExtension\Resources\critical.png">
199200
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
200201
</Resource>
202+
<Resource Include="CxExtension\Resources\CodeBashing_logoDarkTheme.png">
203+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
204+
</Resource>
205+
<Resource Include="CxExtension\Resources\CodeBashing_logoLightTheme.png">
206+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
207+
</Resource>
201208
<Resource Include="CxExtension\Resources\critical_18x22.png">
202209
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
203210
</Resource>

0 commit comments

Comments
 (0)