Skip to content

Commit 437b193

Browse files
committed
add default colors for dark theme with KeeTheme
1 parent defd513 commit 437b193

1 file changed

Lines changed: 65 additions & 6 deletions

File tree

QuickSearch/QuickSearchControl.cs

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
using KeePass;
2-
using KeePass.Resources;
3-
using QuickSearch.Properties;
4-
using System;
1+
using System;
2+
using System.Collections.Generic;
53
using System.Diagnostics;
64
using System.Drawing;
75
using System.Linq;
86
using System.Runtime.InteropServices;
97
using System.Windows.Forms;
8+
using KeePass;
9+
using KeePass.Resources;
10+
using QuickSearch.Properties;
1011

1112
namespace QuickSearch
1213
{
1314
public partial class QuickSearchControl : UserControl
1415
{
16+
private readonly Settings _lightModeSettings = new Settings();
1517
public new string Text
1618
{
1719
get { return comboBoxSearch.Text; }
@@ -64,11 +66,68 @@ public QuickSearchControl()
6466
// add the ToolStripControlHost to the DropDown
6567
toolStripDropDownSettings.Items.Add(settingsPanelHost);
6668

67-
var isDarkThemeEnabled = Program.Config.CustomConfig.GetString("KeeTheme.Enabled");
68-
if (isDarkThemeEnabled != null && isDarkThemeEnabled.Equals("true", StringComparison.OrdinalIgnoreCase))
69+
var isDarkThemeEnabled = string.Equals(Program.Config.CustomConfig.GetString("KeeTheme.Enabled"), "true", StringComparison.OrdinalIgnoreCase);
70+
ApplyThemeColors(isDarkThemeEnabled);
71+
}
72+
73+
private void ApplyThemeColors(bool enableDarkMode)
74+
{
75+
var darkColors = new Dictionary<string, Color>
76+
{
77+
{ "BackColorSuccess", Color.FromArgb(17, 54, 31) },
78+
{ "BackColorSearching", Color.FromArgb(61, 52, 0) },
79+
{ "BackColorOnError", Color.FromArgb(89, 0, 0) },
80+
{ "BackColorNormalUnFocused", Color.FromArgb(57, 60, 62) },
81+
{ "BackColorNormalFocused", Color.FromArgb(72, 76, 78) }
82+
};
83+
84+
if (enableDarkMode)
6985
{
7086
groupBoxSearchIn.ForeColor = Color.LightGray;
7187
groupBoxOptions.ForeColor = Color.LightGray;
88+
bool isUsingLightDefaults = true;
89+
foreach (var kvp in darkColors)
90+
{
91+
var currentValue = (Color)typeof(Settings).GetProperty(kvp.Key).GetValue(Settings.Default, null);
92+
var defaultValue = (Color)typeof(Settings).GetProperty(kvp.Key).GetValue(_lightModeSettings, null);
93+
if (currentValue.ToArgb() != defaultValue.ToArgb())
94+
{
95+
isUsingLightDefaults = false;
96+
break;
97+
}
98+
}
99+
100+
if (isUsingLightDefaults)
101+
{
102+
foreach (var kvp in darkColors)
103+
{
104+
typeof(Settings).GetProperty(kvp.Key).SetValue(Settings.Default, kvp.Value, null);
105+
}
106+
}
107+
}
108+
else
109+
{
110+
bool isUsingDarkDefaults = true;
111+
foreach (var kvp in darkColors)
112+
{
113+
var currentValue = (Color)typeof(Settings).GetProperty(kvp.Key).GetValue(Settings.Default, null);
114+
if (currentValue.ToArgb() != kvp.Value.ToArgb())
115+
{
116+
isUsingDarkDefaults = false;
117+
break;
118+
}
119+
}
120+
121+
if (isUsingDarkDefaults)
122+
{
123+
foreach (var prop in typeof(Settings).GetProperties())
124+
{
125+
if (prop.PropertyType == typeof(Color))
126+
{
127+
prop.SetValue(Settings.Default, prop.GetValue(_lightModeSettings, null), null);
128+
}
129+
}
130+
}
72131
}
73132
}
74133

0 commit comments

Comments
 (0)