Skip to content

Commit 9924e07

Browse files
authored
Merge pull request #8 from lucasriechelmann/main
Theme Color to match VS Theme
2 parents c71495c + d2a6613 commit 9924e07

File tree

11 files changed

+39
-82
lines changed

11 files changed

+39
-82
lines changed

src/SQLScriptsExplorer.Addin/Commands/ToolWindow/MainToolWindowControl.xaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
xmlns:Controls="clr-namespace:SQLScriptsExplorer.Addin.Controls"
66
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
77
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
xmlns:toolkit="clr-namespace:Community.VisualStudio.Toolkit;assembly=Community.VisualStudio.Toolkit"
89
xmlns:vsshell="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0"
910
x:Name="MyToolWindow"
1011
d:DesignHeight="300"
1112
d:DesignWidth="300"
12-
Background="{DynamicResource {x:Static vsshell:VsBrushes.WindowKey}}"
13-
Foreground="{DynamicResource {x:Static vsshell:VsBrushes.WindowTextKey}}"
13+
toolkit:Themes.UseVsTheme="True"
1414
mc:Ignorable="d">
1515
<Grid Margin="0,0,0,0">
1616
<Grid.RowDefinitions>
@@ -21,10 +21,12 @@
2121
<StackPanel>
2222
<ToolBarTray
2323
x:Name="mainToolBarTray"
24+
Background="{Binding Path=Background, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
2425
DockPanel.Dock="Top"
2526
IsLocked="True">
2627
<ToolBar
2728
x:Name="mainToolBar"
29+
Background="{Binding Path=Background, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
2830
BorderThickness="0"
2931
Loaded="ToolBar_Loaded">
3032
<Button Click="btnFormatSelection_Click" ToolTip="Format Selection">

src/SQLScriptsExplorer.Addin/Commands/ToolWindow/MainToolWindowControl.xaml.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public MainToolWindowControl()
4848
searchTimer.Tick += SearchTimer_Tick;
4949

5050
RefreshTreeView();
51-
SetTheme();
5251
}
5352

5453
private void btnFormatSelection_Click(object sender, RoutedEventArgs e)
@@ -84,7 +83,6 @@ private void btnSettings_Click(object sender, RoutedEventArgs e)
8483
if (frmSettingsResult == System.Windows.Forms.DialogResult.OK)
8584
{
8685
RefreshTreeView();
87-
SetTheme();
8886
}
8987
}
9088

@@ -236,26 +234,6 @@ private void FileExplorerSearchResults_TreeNodeRenamed(object sender, System.Eve
236234
}
237235

238236
#region UI
239-
void SetTheme()
240-
{
241-
bool isLightTheme = settingsRepository.Theme == Theme.Light;
242-
SolidColorBrush darkBackground = new SolidColorBrush(Color.FromRgb(31, 31, 31));
243-
SolidColorBrush lightBackground = new SolidColorBrush(Color.FromRgb(238, 245, 253));
244-
SolidColorBrush lightBackground2 = new SolidColorBrush(Color.FromRgb(255, 255, 255));
245-
SolidColorBrush darkForeground = new SolidColorBrush(Color.FromRgb(219, 219, 250));
246-
SolidColorBrush lightForeground = new SolidColorBrush(Color.FromRgb(0, 0, 0));
247-
mainToolBarTray.Background = isLightTheme ? lightBackground : darkBackground;
248-
mainToolBar.Background = isLightTheme ? lightBackground : darkBackground;
249-
txtSearch.Background = isLightTheme ? lightBackground2 : darkBackground;
250-
txtSearch.Foreground = isLightTheme ? lightForeground : darkForeground;
251-
lblSearch.Foreground = isLightTheme ? lightForeground : darkForeground;
252-
FileExplorerAll.SetThemeColor(
253-
isLightTheme ? lightBackground2 : darkBackground,
254-
isLightTheme ? lightForeground : darkForeground);
255-
FileExplorerSearchResults.SetThemeColor(
256-
isLightTheme ? lightBackground2 : darkBackground,
257-
isLightTheme ? lightForeground : darkForeground);
258-
}
259237
private void ToolBar_Loaded(object sender, RoutedEventArgs e)
260238
{
261239
ToolBar toolBar = sender as ToolBar;

src/SQLScriptsExplorer.Addin/Controls/FileExplorerTreeView.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
xmlns:domain="clr-namespace:SQLScriptsExplorer.Addin.Models"
88
xmlns:local="clr-namespace:SQLScriptsExplorer.Addin.Controls"
99
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
10+
xmlns:toolkit="clr-namespace:Community.VisualStudio.Toolkit;assembly=Community.VisualStudio.Toolkit"
1011
d:DesignHeight="450"
1112
d:DesignWidth="800"
13+
toolkit:Themes.UseVsTheme="True"
1214
mc:Ignorable="d">
1315
<!--<UserControl.Resources>
1416
<converter:SortableConverter x:Key="sortableConverter" />
@@ -200,7 +202,6 @@
200202
<Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
201203
<Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
202204
<Setter Property="Padding" Value="1,0,0,0" />
203-
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type TreeView}}, Path=Foreground}" />
204205
<Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisual}" />
205206
<Setter Property="Template">
206207
<Setter.Value>

src/SQLScriptsExplorer.Addin/Controls/FileExplorerTreeView.xaml.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,5 @@ private void txtRename_LostFocus(object sender, RoutedEventArgs e)
489489
MessageBox.Show(ex.Message);
490490
}
491491
}
492-
public void SetThemeColor(SolidColorBrush background, SolidColorBrush foreground)
493-
{
494-
TreeViewMain.Background = background;
495-
TreeViewMain.Foreground = foreground;
496-
}
497492
}
498493
}

src/SQLScriptsExplorer.Addin/Controls/HighlightTextBlock.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
using System;
1+
using Microsoft.VisualStudio.PlatformUI;
2+
using System;
23
using System.Windows;
34
using System.Windows.Controls;
45
using System.Windows.Documents;
56
using System.Windows.Media;
7+
using DrawingColor = System.Drawing.Color;
68

79
namespace SQLScriptsExplorer.Addin.Controls
810
{
911
public class HighlightTextBlock : TextBlock
1012
{
13+
public HighlightTextBlock()
14+
{
15+
ApplyThemeColors();
16+
VSColorTheme.ThemeChanged += VSColorTheme_Changed;
17+
}
1118
#region Properties
1219

1320
public new string Text
@@ -60,11 +67,32 @@ private static void UpdateHighlighting(DependencyObject d, DependencyPropertyCha
6067
}
6168

6269
#endregion
63-
70+
#region Theme
71+
void ApplyThemeColors()
72+
{
73+
DrawingColor foreground = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowTextColorKey);
74+
DrawingColor background = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowBackgroundColorKey);
75+
Foreground = new SolidColorBrush(Color.FromArgb(foreground.A, foreground.R, foreground.G, foreground.B));
76+
Background = new SolidColorBrush(Color.FromArgb(background.A, background.R, background.G, background.B));
77+
}
78+
void VSColorTheme_Changed(ThemeChangedEventArgs e)
79+
{
80+
ApplyThemeColors();
81+
}
82+
protected override void OnVisualParentChanged(DependencyObject oldParent)
83+
{
84+
base.OnVisualParentChanged(oldParent);
85+
if(VisualParent == null)
86+
{
87+
VSColorTheme.ThemeChanged -= VSColorTheme_Changed;
88+
}
89+
}
90+
#endregion
6491
#region Members
6592

6693
private static void ApplyHighlight(HighlightTextBlock tb)
6794
{
95+
6896
string highlightPhrase = tb.HighlightPhrase;
6997
string text = tb.Text;
7098

src/SQLScriptsExplorer.Addin/Models/Enums/Theme.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/SQLScriptsExplorer.Addin/Repository/Interfaces/ISettingsRepository.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public interface ISettingsRepository
1212
bool ExpandMappedFoldersOnLoad { get; set; }
1313
bool ShowExecuteFileButton { get; set; }
1414
bool ConfirmScriptExecution { get; set; }
15-
Theme Theme { get; set; }
1615

1716
ScriptFileDoubleClickBehaviour ScriptFileDoubleClickBehaviour { get; set; }
1817

src/SQLScriptsExplorer.Addin/Repository/SettingsRepository.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public class SettingsRepository : ISettingsRepository
1717
private const string SHOW_EXECUTEFILE_BUTTON = "ShowExecuteFileButton";
1818
private const string CONFIRM_SCRIPT_EXECUTION = "ConfirmScriptExecution";
1919
private const string SCRIPT_FILE_DOUBLE_CLICK_BEHAVIOUR = "ScriptFileDoubleClickBehaviour";
20-
private const string THEME = "Theme";
2120

2221
public List<FolderMapping> FolderMapping { get; set; }
2322

@@ -30,7 +29,6 @@ public class SettingsRepository : ISettingsRepository
3029
public bool ShowExecuteFileButton { get; set; }
3130

3231
public bool ConfirmScriptExecution { get; set; }
33-
public Theme Theme { get; set; }
3432

3533
public ScriptFileDoubleClickBehaviour ScriptFileDoubleClickBehaviour { get; set; }
3634

@@ -57,7 +55,6 @@ public void Save()
5755
RegistryManager.SaveRegisterValue(SHOW_EXECUTEFILE_BUTTON, ShowExecuteFileButton.ToString());
5856
RegistryManager.SaveRegisterValue(CONFIRM_SCRIPT_EXECUTION, ConfirmScriptExecution.ToString());
5957
RegistryManager.SaveRegisterValue(SCRIPT_FILE_DOUBLE_CLICK_BEHAVIOUR, $"{(int)ScriptFileDoubleClickBehaviour}");
60-
RegistryManager.SaveRegisterValue(THEME, ((int)Theme).ToString());
6158
}
6259

6360
private void LoadFolderMapping()
@@ -135,13 +132,6 @@ private void LoadGenericSettings()
135132
{
136133
AllowedFileTypes = "*.sql";
137134
}
138-
139-
// Theme
140-
var themeValue = RegistryManager.GetRegisterValue(THEME);
141-
if (string.IsNullOrEmpty(themeValue))
142-
Theme = Theme.Light;
143-
else
144-
Theme = (Theme)int.Parse(themeValue);
145135
}
146136
}
147137
}

src/SQLScriptsExplorer.Addin/SQLScriptsExplorer.Addin.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
</Compile>
6363
<Compile Include="Infrastructure\Helpers\PathHelper.cs" />
6464
<Compile Include="Models\Enums\ScriptFileDoubleClickBehaviour.cs" />
65-
<Compile Include="Models\Enums\Theme.cs" />
6665
<Compile Include="Repository\Interfaces\ISettingsRepository.cs" />
6766
<Compile Include="Repository\SettingsRepository.cs" />
6867
<Compile Include="Styling\Converter\SortableConverter.cs" />
@@ -130,6 +129,9 @@
130129
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="16.9.1050" />
131130
</ItemGroup>-->
132131
<ItemGroup>
132+
<PackageReference Include="Community.VisualStudio.Toolkit.17">
133+
<Version>17.0.533</Version>
134+
</PackageReference>
133135
<PackageReference Include="Microsoft.SqlServer.TransactSql.ScriptDom">
134136
<Version>170.64.0</Version>
135137
</PackageReference>

src/SQLScriptsExplorer.Addin/frmSettings.Designer.cs

Lines changed: 0 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)