Skip to content

Commit 68fcd37

Browse files
authored
Merge pull request #7 from lucasriechelmann/main
Added light and dark theme options in the settings
2 parents d3547ca + 95a5f57 commit 68fcd37

File tree

10 files changed

+306
-145
lines changed

10 files changed

+306
-145
lines changed

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

Lines changed: 80 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,118 @@
11
<UserControl
2-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6-
xmlns:vsshell="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0"
7-
xmlns:Controls="clr-namespace:SQLScriptsExplorer.Addin.Controls" x:Class="SQLScriptsExplorer.Addin.Commands.ToolWindow.MainToolWindowControl"
8-
Background="{DynamicResource {x:Static vsshell:VsBrushes.WindowKey}}"
9-
Foreground="{DynamicResource {x:Static vsshell:VsBrushes.WindowTextKey}}"
10-
mc:Ignorable="d"
11-
d:DesignHeight="300" d:DesignWidth="300"
12-
x:Name="MyToolWindow">
2+
x:Class="SQLScriptsExplorer.Addin.Commands.ToolWindow.MainToolWindowControl"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:Controls="clr-namespace:SQLScriptsExplorer.Addin.Controls"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
xmlns:vsshell="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0"
9+
x:Name="MyToolWindow"
10+
d:DesignHeight="300"
11+
d:DesignWidth="300"
12+
Background="{DynamicResource {x:Static vsshell:VsBrushes.WindowKey}}"
13+
Foreground="{DynamicResource {x:Static vsshell:VsBrushes.WindowTextKey}}"
14+
mc:Ignorable="d">
1315
<Grid Margin="0,0,0,0">
14-
15-
<DockPanel>
16+
<Grid.RowDefinitions>
17+
<RowDefinition Height="Auto" />
18+
<RowDefinition Height="*" />
19+
</Grid.RowDefinitions>
20+
<DockPanel Grid.Row="0">
1621
<StackPanel>
17-
<ToolBarTray DockPanel.Dock="Top" IsLocked="True">
18-
<ToolBar Loaded="ToolBar_Loaded" BorderThickness="0">
22+
<ToolBarTray
23+
x:Name="mainToolBarTray"
24+
DockPanel.Dock="Top"
25+
IsLocked="True">
26+
<ToolBar
27+
x:Name="mainToolBar"
28+
BorderThickness="0"
29+
Loaded="ToolBar_Loaded">
1930
<Button Click="btnFormatSelection_Click" ToolTip="Format Selection">
2031
<StackPanel>
21-
<Image Source="../../Resources/Images/FormatScript.png" Width="16" />
32+
<Image Width="16" Source="../../Resources/Images/FormatScript.png" />
2233
</StackPanel>
2334
</Button>
2435

2536
<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" />
2637

2738
<Button Click="btnExpandAll_Click" ToolTip="Expand All">
2839
<StackPanel>
29-
<Image Source="../../Resources/Images/ExpandAll.png" Width="16" />
40+
<Image Width="16" Source="../../Resources/Images/ExpandAll.png" />
3041
</StackPanel>
3142
</Button>
32-
43+
3344
<Button Click="btnCollapseAll_Click" ToolTip="Collapse All">
3445
<StackPanel>
35-
<Image Source="../../Resources/Images/CollapseAll.png" Width="16" />
46+
<Image Width="16" Source="../../Resources/Images/CollapseAll.png" />
3647
</StackPanel>
3748
</Button>
3849

3950
<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" />
4051

4152
<Button Click="btnRefresh_Click" ToolTip="Refresh">
4253
<StackPanel>
43-
<Image Source="../../Resources/Images/Refresh.png" Width="16"/>
54+
<Image Width="16" Source="../../Resources/Images/Refresh.png" />
4455
</StackPanel>
4556
</Button>
4657
<Button Click="btnSettings_Click" ToolTip="Settings">
4758
<StackPanel>
48-
<Image Source="../../Resources/Images/Settings.png" Width="16"/>
59+
<Image Width="16" Source="../../Resources/Images/Settings.png" />
4960
</StackPanel>
5061
</Button>
5162
</ToolBar>
5263
</ToolBarTray>
53-
<TextBox x:Name="txtSearch" Height="21" Padding="3,2,3,2" KeyUp="txtSearch_KeyUp" />
54-
<TextBlock IsHitTestVisible="False" Text="Search SQL Scripts Explorer..." VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,-23,0,0" Padding="6,2,0,0" Foreground="DarkGray">
55-
<TextBlock.Style>
56-
<Style TargetType="{x:Type TextBlock}">
57-
<Setter Property="Visibility" Value="Collapsed"/>
58-
<Style.Triggers>
59-
<DataTrigger Binding="{Binding Text, ElementName=txtSearch}" Value="">
60-
<Setter Property="Visibility" Value="Visible"/>
61-
</DataTrigger>
62-
</Style.Triggers>
63-
</Style>
64-
</TextBlock.Style>
65-
</TextBlock>
64+
<Grid>
65+
<Grid.ColumnDefinitions>
66+
<ColumnDefinition Width="*" />
67+
</Grid.ColumnDefinitions>
68+
<TextBox
69+
x:Name="txtSearch"
70+
Grid.Column="0"
71+
Height="21"
72+
Padding="3,2,3,2"
73+
KeyUp="txtSearch_KeyUp" />
74+
<TextBlock
75+
x:Name="lblSearch"
76+
Grid.Column="0"
77+
Margin="5,0,0,0"
78+
HorizontalAlignment="Left"
79+
VerticalAlignment="Center"
80+
Background="Transparent"
81+
IsHitTestVisible="False"
82+
Text="Search SQL Scripts Explorer...">
83+
<TextBlock.Style>
84+
<Style TargetType="{x:Type TextBlock}">
85+
<Setter Property="Visibility" Value="Collapsed" />
86+
<Style.Triggers>
87+
<DataTrigger Binding="{Binding Text, ElementName=txtSearch}" Value="">
88+
<Setter Property="Visibility" Value="Visible" />
89+
</DataTrigger>
90+
</Style.Triggers>
91+
</Style>
92+
</TextBlock.Style>
93+
</TextBlock>
94+
</Grid>
6695
</StackPanel>
6796
</DockPanel>
6897

69-
<Controls:FileExplorerTreeView x:Name="FileExplorerAll" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,48,0,0"/>
70-
<Controls:FileExplorerTreeView x:Name="FileExplorerSearchResults" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,48,0,0" Visibility="Collapsed"
71-
TreeNodeAdded="FileExplorerSearchResults_TreeNodeAdded"
72-
TreeNodeDeleted="FileExplorerSearchResults_TreeNodeDeleted"
73-
TreeNodeRenamed="FileExplorerSearchResults_TreeNodeRenamed"/>
74-
75-
<StackPanel Orientation="Vertical" Margin="0,150,0,0">
76-
<!--<StackPanel Orientation="Horizontal">-->
77-
<!--</StackPanel>-->
78-
</StackPanel>
98+
<Controls:FileExplorerTreeView
99+
x:Name="FileExplorerAll"
100+
Grid.Row="1"
101+
Margin="0,0,0,0"
102+
HorizontalAlignment="Stretch"
103+
VerticalAlignment="Stretch" />
104+
<Controls:FileExplorerTreeView
105+
x:Name="FileExplorerSearchResults"
106+
Grid.Row="1"
107+
Margin="0,0,0,0"
108+
HorizontalAlignment="Stretch"
109+
VerticalAlignment="Stretch"
110+
TreeNodeAdded="FileExplorerSearchResults_TreeNodeAdded"
111+
TreeNodeDeleted="FileExplorerSearchResults_TreeNodeDeleted"
112+
TreeNodeRenamed="FileExplorerSearchResults_TreeNodeRenamed"
113+
Visibility="Collapsed" />
79114

80-
<!-- Info on double click: https://stackoverflow.com/questions/4295897/wpf-double-click-treeviewitem-child-node -->
115+
<!-- Info on double click: https://stackoverflow.com/questions/4295897/wpf-double-click-treeviewitem-child-node -->
81116

82117

83118

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
using SQLScriptsExplorer.Addin.Infrastructure;
22
using SQLScriptsExplorer.Addin.Infrastructure.Helpers;
33
using SQLScriptsExplorer.Addin.Models;
4+
using SQLScriptsExplorer.Addin.Models.Enums;
45
using SQLScriptsExplorer.Addin.Repository;
56
using SQLScriptsExplorer.Addin.Repository.Interfaces;
67
using System;
78
using System.Linq;
89
using System.Windows;
910
using System.Windows.Controls;
1011
using System.Windows.Input;
12+
using System.Windows.Media;
1113
using System.Windows.Threading;
1214

1315
namespace SQLScriptsExplorer.Addin.Commands.ToolWindow
@@ -46,6 +48,7 @@ public MainToolWindowControl()
4648
searchTimer.Tick += SearchTimer_Tick;
4749

4850
RefreshTreeView();
51+
SetTheme();
4952
}
5053

5154
private void btnFormatSelection_Click(object sender, RoutedEventArgs e)
@@ -81,6 +84,7 @@ private void btnSettings_Click(object sender, RoutedEventArgs e)
8184
if (frmSettingsResult == System.Windows.Forms.DialogResult.OK)
8285
{
8386
RefreshTreeView();
87+
SetTheme();
8488
}
8589
}
8690

@@ -232,7 +236,26 @@ private void FileExplorerSearchResults_TreeNodeRenamed(object sender, System.Eve
232236
}
233237

234238
#region UI
235-
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+
}
236259
private void ToolBar_Loaded(object sender, RoutedEventArgs e)
237260
{
238261
ToolBar toolBar = sender as ToolBar;

0 commit comments

Comments
 (0)