|
1 | | -using KeePass; |
2 | | -using KeePass.Resources; |
3 | | -using QuickSearch.Properties; |
4 | | -using System; |
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
5 | 3 | using System.Diagnostics; |
6 | 4 | using System.Drawing; |
7 | 5 | using System.Linq; |
8 | 6 | using System.Runtime.InteropServices; |
9 | 7 | using System.Windows.Forms; |
| 8 | +using KeePass; |
| 9 | +using KeePass.Resources; |
| 10 | +using QuickSearch.Properties; |
10 | 11 |
|
11 | 12 | namespace QuickSearch |
12 | 13 | { |
13 | 14 | public partial class QuickSearchControl : UserControl |
14 | 15 | { |
| 16 | + private readonly Settings _lightModeSettings = new Settings(); |
15 | 17 | public new string Text |
16 | 18 | { |
17 | 19 | get { return comboBoxSearch.Text; } |
@@ -64,11 +66,68 @@ public QuickSearchControl() |
64 | 66 | // add the ToolStripControlHost to the DropDown |
65 | 67 | toolStripDropDownSettings.Items.Add(settingsPanelHost); |
66 | 68 |
|
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) |
69 | 85 | { |
70 | 86 | groupBoxSearchIn.ForeColor = Color.LightGray; |
71 | 87 | 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 | + } |
72 | 131 | } |
73 | 132 | } |
74 | 133 |
|
|
0 commit comments