-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsWindow.xaml.cs
More file actions
195 lines (162 loc) · 7.09 KB
/
Copy pathSettingsWindow.xaml.cs
File metadata and controls
195 lines (162 loc) · 7.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using GlassNotes.ViewModels;
namespace GlassNotes;
public partial class SettingsWindow : Window
{
private readonly MainViewModel _viewModel;
private readonly MainWindow _mainWindow;
// Tab layout: maps tab name → (button, panel, underline left offset)
private readonly Dictionary<string, (Button Button, StackPanel Panel, double UnderlineLeft)> _tabs;
private string _activeTab = "General";
public SettingsWindow(MainViewModel viewModel, MainWindow mainWindow)
{
InitializeComponent();
_viewModel = viewModel;
_mainWindow = mainWindow;
_tabs = new Dictionary<string, (Button, StackPanel, double)>
{
{ "General", (TabGeneral, PanelGeneral, 0) },
{ "Colors", (TabColors, PanelColors, 80) },
{ "Font", (TabFont, PanelFont, 158) },
{ "About", (TabAbout, PanelAbout, 224) },
};
LoadSettings();
AttachEventHandlers();
SelectTab("General");
// Position settings centered over the main window, constrained to fit inside it
Loaded += (_, _) => PositionOverMainWindow();
}
private void PositionOverMainWindow()
{
// Center settings over the main window
SetCurrentValue(LeftProperty, _mainWindow.Left + (_mainWindow.ActualWidth - ActualWidth) / 2);
SetCurrentValue(TopProperty, _mainWindow.Top + (_mainWindow.ActualHeight - ActualHeight) / 2);
// Clamp so it never goes off-screen
SetCurrentValue(LeftProperty, Math.Max(0, Left));
SetCurrentValue(TopProperty, Math.Max(0, Top));
}
// ── Dragging the settings header moves THIS settings window ─────────────
private void Header_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.ButtonState == MouseButtonState.Pressed)
DragMove();
}
// ── Tab switching ────────────────────────────────────────────────────────
private void Tab_Click(object sender, RoutedEventArgs e)
{
if (sender is Button btn && btn.Tag is string tabName)
SelectTab(tabName);
}
private void SelectTab(string tabName)
{
_activeTab = tabName;
foreach (var (name, (btn, panel, left)) in _tabs)
{
bool active = name == tabName;
panel.Visibility = active ? Visibility.Visible : Visibility.Collapsed;
btn.Foreground = active
? new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(0x1A, 0x1A, 0x1A))
: new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(0x66, 0x66, 0x66));
btn.FontWeight = active ? FontWeights.Bold : FontWeights.Normal;
}
// Animate underline to the correct position
var (_, _, targetLeft) = _tabs[tabName];
TabUnderline.SetCurrentValue(MarginProperty, new Thickness(targetLeft, 0, 0, 0));
}
// ── Load saved settings into controls ───────────────────────────────────
private void LoadSettings()
{
TransparencySlider.SetCurrentValue(System.Windows.Controls.Primitives.RangeBase.ValueProperty, _viewModel.Settings.Opacity);
UpdateTransparencyLabel();
AlwaysOnTopCheckBox.SetCurrentValue(System.Windows.Controls.Primitives.ToggleButton.IsCheckedProperty, _viewModel.Settings.AlwaysOnTop);
FontSizeSlider.SetCurrentValue(System.Windows.Controls.Primitives.RangeBase.ValueProperty, _viewModel.Settings.FontSize);
UpdateFontSizeLabel();
SelectComboItem(BackgroundColorComboBox, _viewModel.Settings.BackgroundColor);
SelectComboItem(TextColorComboBox, _viewModel.Settings.TextColor);
SelectComboItem(FontFamilyComboBox, _viewModel.Settings.FontFamily);
}
private static void SelectComboItem(ComboBox box, string? value)
{
foreach (ComboBoxItem item in box.Items)
{
if (item.Tag?.ToString() == value)
{
box.SetCurrentValue(System.Windows.Controls.Primitives.Selector.SelectedItemProperty, item);
return;
}
}
}
// ── Wire up live-update event handlers ──────────────────────────────────
private void AttachEventHandlers()
{
TransparencySlider.ValueChanged += (s, e) =>
{
_viewModel.Settings.Opacity = e.NewValue;
UpdateTransparencyLabel();
// Call the correct MainWindow method that applies opacity only to the background brush
_mainWindow.UpdateOpacity(e.NewValue);
_viewModel.SaveSettings();
};
AlwaysOnTopCheckBox.Checked += (s, e) =>
{
_viewModel.Settings.AlwaysOnTop = true;
_mainWindow.SetCurrentValue(Window.TopmostProperty, true);
_viewModel.SaveSettings();
};
AlwaysOnTopCheckBox.Unchecked += (s, e) =>
{
_viewModel.Settings.AlwaysOnTop = false;
_mainWindow.SetCurrentValue(Window.TopmostProperty, false);
_viewModel.SaveSettings();
};
FontSizeSlider.ValueChanged += (s, e) =>
{
_viewModel.Settings.FontSize = e.NewValue;
UpdateFontSizeLabel();
_viewModel.SaveSettings();
};
BackgroundColorComboBox.SelectionChanged += (s, e) =>
{
if (BackgroundColorComboBox.SelectedItem is ComboBoxItem item)
{
var color = item.Tag?.ToString() ?? "Cream";
_viewModel.Settings.BackgroundColor = color;
_mainWindow.UpdateBackgroundColor(color);
_viewModel.SaveSettings();
}
};
TextColorComboBox.SelectionChanged += (s, e) =>
{
if (TextColorComboBox.SelectedItem is ComboBoxItem item)
{
var color = item.Tag?.ToString() ?? "Black";
_viewModel.Settings.TextColor = color;
_mainWindow.UpdateTextColor(color);
_viewModel.SaveSettings();
}
};
FontFamilyComboBox.SelectionChanged += (s, e) =>
{
if (FontFamilyComboBox.SelectedItem is ComboBoxItem item)
{
var font = item.Tag?.ToString() ?? "Segoe UI";
_viewModel.Settings.FontFamily = font;
_viewModel.SaveSettings();
}
};
}
private void UpdateTransparencyLabel()
{
TransparencyLabel.SetCurrentValue(TextBlock.TextProperty, $"{(int)(TransparencySlider.Value * 100)}%");
}
private void UpdateFontSizeLabel()
{
FontSizeLabel.SetCurrentValue(TextBlock.TextProperty, $"{(int)FontSizeSlider.Value}px");
}
private void CloseButton_Click(object sender, RoutedEventArgs e)
{
Close();
}
}