Skip to content

Theme Color to match VS Theme #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
xmlns:Controls="clr-namespace:SQLScriptsExplorer.Addin.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:toolkit="clr-namespace:Community.VisualStudio.Toolkit;assembly=Community.VisualStudio.Toolkit"
xmlns:vsshell="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0"
x:Name="MyToolWindow"
d:DesignHeight="300"
d:DesignWidth="300"
Background="{DynamicResource {x:Static vsshell:VsBrushes.WindowKey}}"
Foreground="{DynamicResource {x:Static vsshell:VsBrushes.WindowTextKey}}"
toolkit:Themes.UseVsTheme="True"
mc:Ignorable="d">
<Grid Margin="0,0,0,0">
<Grid.RowDefinitions>
Expand All @@ -21,10 +21,12 @@
<StackPanel>
<ToolBarTray
x:Name="mainToolBarTray"
Background="{Binding Path=Background, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
DockPanel.Dock="Top"
IsLocked="True">
<ToolBar
x:Name="mainToolBar"
Background="{Binding Path=Background, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
BorderThickness="0"
Loaded="ToolBar_Loaded">
<Button Click="btnFormatSelection_Click" ToolTip="Format Selection">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public MainToolWindowControl()
searchTimer.Tick += SearchTimer_Tick;

RefreshTreeView();
SetTheme();
}

private void btnFormatSelection_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -84,7 +83,6 @@ private void btnSettings_Click(object sender, RoutedEventArgs e)
if (frmSettingsResult == System.Windows.Forms.DialogResult.OK)
{
RefreshTreeView();
SetTheme();
}
}

Expand Down Expand Up @@ -236,26 +234,6 @@ private void FileExplorerSearchResults_TreeNodeRenamed(object sender, System.Eve
}

#region UI
void SetTheme()
{
bool isLightTheme = settingsRepository.Theme == Theme.Light;
SolidColorBrush darkBackground = new SolidColorBrush(Color.FromRgb(31, 31, 31));
SolidColorBrush lightBackground = new SolidColorBrush(Color.FromRgb(238, 245, 253));
SolidColorBrush lightBackground2 = new SolidColorBrush(Color.FromRgb(255, 255, 255));
SolidColorBrush darkForeground = new SolidColorBrush(Color.FromRgb(219, 219, 250));
SolidColorBrush lightForeground = new SolidColorBrush(Color.FromRgb(0, 0, 0));
mainToolBarTray.Background = isLightTheme ? lightBackground : darkBackground;
mainToolBar.Background = isLightTheme ? lightBackground : darkBackground;
txtSearch.Background = isLightTheme ? lightBackground2 : darkBackground;
txtSearch.Foreground = isLightTheme ? lightForeground : darkForeground;
lblSearch.Foreground = isLightTheme ? lightForeground : darkForeground;
FileExplorerAll.SetThemeColor(
isLightTheme ? lightBackground2 : darkBackground,
isLightTheme ? lightForeground : darkForeground);
FileExplorerSearchResults.SetThemeColor(
isLightTheme ? lightBackground2 : darkBackground,
isLightTheme ? lightForeground : darkForeground);
}
private void ToolBar_Loaded(object sender, RoutedEventArgs e)
{
ToolBar toolBar = sender as ToolBar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
xmlns:domain="clr-namespace:SQLScriptsExplorer.Addin.Models"
xmlns:local="clr-namespace:SQLScriptsExplorer.Addin.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:toolkit="clr-namespace:Community.VisualStudio.Toolkit;assembly=Community.VisualStudio.Toolkit"
d:DesignHeight="450"
d:DesignWidth="800"
toolkit:Themes.UseVsTheme="True"
mc:Ignorable="d">
<!--<UserControl.Resources>
<converter:SortableConverter x:Key="sortableConverter" />
Expand Down Expand Up @@ -200,7 +202,6 @@
<Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
<Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
<Setter Property="Padding" Value="1,0,0,0" />
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type TreeView}}, Path=Foreground}" />
<Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisual}" />
<Setter Property="Template">
<Setter.Value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,5 @@ private void txtRename_LostFocus(object sender, RoutedEventArgs e)
MessageBox.Show(ex.Message);
}
}
public void SetThemeColor(SolidColorBrush background, SolidColorBrush foreground)
{
TreeViewMain.Background = background;
TreeViewMain.Foreground = foreground;
}
}
}
32 changes: 30 additions & 2 deletions src/SQLScriptsExplorer.Addin/Controls/HighlightTextBlock.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
using System;
using Microsoft.VisualStudio.PlatformUI;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using DrawingColor = System.Drawing.Color;

namespace SQLScriptsExplorer.Addin.Controls
{
public class HighlightTextBlock : TextBlock
{
public HighlightTextBlock()
{
ApplyThemeColors();
VSColorTheme.ThemeChanged += VSColorTheme_Changed;
}
#region Properties

public new string Text
Expand Down Expand Up @@ -60,11 +67,32 @@ private static void UpdateHighlighting(DependencyObject d, DependencyPropertyCha
}

#endregion

#region Theme
void ApplyThemeColors()
{
DrawingColor foreground = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowTextColorKey);
DrawingColor background = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowBackgroundColorKey);
Foreground = new SolidColorBrush(Color.FromArgb(foreground.A, foreground.R, foreground.G, foreground.B));
Background = new SolidColorBrush(Color.FromArgb(background.A, background.R, background.G, background.B));
}
void VSColorTheme_Changed(ThemeChangedEventArgs e)
{
ApplyThemeColors();
}
protected override void OnVisualParentChanged(DependencyObject oldParent)
{
base.OnVisualParentChanged(oldParent);
if(VisualParent == null)
{
VSColorTheme.ThemeChanged -= VSColorTheme_Changed;
}
}
#endregion
#region Members

private static void ApplyHighlight(HighlightTextBlock tb)
{

string highlightPhrase = tb.HighlightPhrase;
string text = tb.Text;

Expand Down
8 changes: 0 additions & 8 deletions src/SQLScriptsExplorer.Addin/Models/Enums/Theme.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public interface ISettingsRepository
bool ExpandMappedFoldersOnLoad { get; set; }
bool ShowExecuteFileButton { get; set; }
bool ConfirmScriptExecution { get; set; }
Theme Theme { get; set; }

ScriptFileDoubleClickBehaviour ScriptFileDoubleClickBehaviour { get; set; }

Expand Down
10 changes: 0 additions & 10 deletions src/SQLScriptsExplorer.Addin/Repository/SettingsRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class SettingsRepository : ISettingsRepository
private const string SHOW_EXECUTEFILE_BUTTON = "ShowExecuteFileButton";
private const string CONFIRM_SCRIPT_EXECUTION = "ConfirmScriptExecution";
private const string SCRIPT_FILE_DOUBLE_CLICK_BEHAVIOUR = "ScriptFileDoubleClickBehaviour";
private const string THEME = "Theme";

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

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

public bool ConfirmScriptExecution { get; set; }
public Theme Theme { get; set; }

public ScriptFileDoubleClickBehaviour ScriptFileDoubleClickBehaviour { get; set; }

Expand All @@ -57,7 +55,6 @@ public void Save()
RegistryManager.SaveRegisterValue(SHOW_EXECUTEFILE_BUTTON, ShowExecuteFileButton.ToString());
RegistryManager.SaveRegisterValue(CONFIRM_SCRIPT_EXECUTION, ConfirmScriptExecution.ToString());
RegistryManager.SaveRegisterValue(SCRIPT_FILE_DOUBLE_CLICK_BEHAVIOUR, $"{(int)ScriptFileDoubleClickBehaviour}");
RegistryManager.SaveRegisterValue(THEME, ((int)Theme).ToString());
}

private void LoadFolderMapping()
Expand Down Expand Up @@ -135,13 +132,6 @@ private void LoadGenericSettings()
{
AllowedFileTypes = "*.sql";
}

// Theme
var themeValue = RegistryManager.GetRegisterValue(THEME);
if (string.IsNullOrEmpty(themeValue))
Theme = Theme.Light;
else
Theme = (Theme)int.Parse(themeValue);
}
}
}
4 changes: 3 additions & 1 deletion src/SQLScriptsExplorer.Addin/SQLScriptsExplorer.Addin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
</Compile>
<Compile Include="Infrastructure\Helpers\PathHelper.cs" />
<Compile Include="Models\Enums\ScriptFileDoubleClickBehaviour.cs" />
<Compile Include="Models\Enums\Theme.cs" />
<Compile Include="Repository\Interfaces\ISettingsRepository.cs" />
<Compile Include="Repository\SettingsRepository.cs" />
<Compile Include="Styling\Converter\SortableConverter.cs" />
Expand Down Expand Up @@ -130,6 +129,9 @@
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="16.9.1050" />
</ItemGroup>-->
<ItemGroup>
<PackageReference Include="Community.VisualStudio.Toolkit.17">
<Version>17.0.533</Version>
</PackageReference>
<PackageReference Include="Microsoft.SqlServer.TransactSql.ScriptDom">
<Version>170.64.0</Version>
</PackageReference>
Expand Down
27 changes: 0 additions & 27 deletions src/SQLScriptsExplorer.Addin/frmSettings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions src/SQLScriptsExplorer.Addin/frmSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public frmSettings()
// General
cboParserVersion.SelectedItem = settingsRepository.SQLParserVersion;
txtAllowedFileTypes.Text = settingsRepository.AllowedFileTypes;
cboTheme.SelectedIndex = settingsRepository.Theme == Theme.Light ? 0 : 1;
}

private void btnSave_Click(object sender, System.EventArgs e)
Expand All @@ -61,8 +60,6 @@ private void btnSave_Click(object sender, System.EventArgs e)
// General
settingsRepository.SQLParserVersion = cboParserVersion.SelectedItem.ToString();
settingsRepository.AllowedFileTypes = txtAllowedFileTypes.Text;
settingsRepository.Theme = cboTheme.SelectedItem.ToString() == Theme.Light.ToString() ?
Theme.Light : Theme.Dark;

settingsRepository.Save();

Expand Down