-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsForm.cs
More file actions
165 lines (140 loc) · 7.3 KB
/
Copy pathSettingsForm.cs
File metadata and controls
165 lines (140 loc) · 7.3 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
using System;
using System.Runtime.InteropServices;
using Eto.Drawing;
using Eto.Forms;
namespace devtime
{
public class SettingsForm : Dialog<bool>
{
private readonly NumericStepper _dbFreqStepper;
private readonly TextBox _dbPathBox;
private readonly NumericStepper _dbExportBufStepper;
private readonly DropDown _stoppedColorDropDown;
private readonly DropDown _runningColorDropDown;
private readonly CheckBox _minimizeToTrayCheck;
private readonly DropDown _startHotkeyDropDown;
private readonly DropDown _stopHotkeyDropDown;
private readonly CheckBox _disableGuiUpdatesCheck;
private readonly CheckBox _freeMemoryCheck;
public SettingsForm()
{
Title = "Settings";
Icon = IconLoader.LoadIcon("settings.png");
Resizable = false;
Maximizable = false;
// Group 1: Database
_dbFreqStepper = new NumericStepper { MinValue = 1, MaxValue = 36000, Value = Config.DatabaseUpdateFrequency, DecimalPlaces = 0, Width = 80 };
_dbPathBox = new TextBox { Text = Config.DatabasePath, Width = 100 };
_dbExportBufStepper = new NumericStepper { MinValue = 1, MaxValue = 3600, Value = Config.DatabaseExportBufferSize, DecimalPlaces = 0, Width = 80 };
var dbLayout = new TableLayout
{
Spacing = new Size(5, 3),
Rows =
{
new TableRow(new Label { Text = "Update frequency (s):" }, new TableCell(_dbFreqStepper, false)),
new TableRow(new Label { Text = "File path:" }, new TableCell(_dbPathBox, false)),
new TableRow(new Label { Text = "Export buffer size:" }, new TableCell(_dbExportBufStepper, false))
}
};
var dbGroup = new GroupBox { Text = "Database", Content = dbLayout };
// Group 2: Taskbar/Tray
_stoppedColorDropDown = new DropDown { Width = 100 };
_runningColorDropDown = new DropDown { Width = 100 };
foreach (var val in Enum.GetValues(typeof(TaskbarColor)))
{
_stoppedColorDropDown.Items.Add(val.ToString() ?? "");
_runningColorDropDown.Items.Add(val.ToString() ?? "");
}
_stoppedColorDropDown.SelectedKey = Config.StoppedTimerColor.ToString();
_runningColorDropDown.SelectedKey = Config.RunningTimerColor.ToString();
_minimizeToTrayCheck = new CheckBox { Text = "Minimize to system tray", Checked = Config.MinimizeToTray };
var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
var trayLayout = new TableLayout { Spacing = new Size(5, 3) };
if (isWindows)
{
trayLayout.Rows.Add(new TableRow(new Label { Text = "Normal color:" }, new TableCell(_stoppedColorDropDown, false)));
trayLayout.Rows.Add(new TableRow(new Label { Text = "Running color:" }, new TableCell(_runningColorDropDown, false)));
}
trayLayout.Rows.Add(new TableRow(new TableCell(_minimizeToTrayCheck, false)));
var trayGroup = new GroupBox { Text = "Taskbar / tray", Content = trayLayout };
// Group 3: Hotkeys
_startHotkeyDropDown = new DropDown { Width = 100 };
_stopHotkeyDropDown = new DropDown { Width = 100 };
foreach (var val in Enum.GetValues(typeof(Hotkey)))
{
_startHotkeyDropDown.Items.Add(val.ToString() ?? "");
_stopHotkeyDropDown.Items.Add(val.ToString() ?? "");
}
_startHotkeyDropDown.SelectedKey = Config.StartHotkey.ToString();
_stopHotkeyDropDown.SelectedKey = Config.StopHotkey.ToString();
var hotkeyLayout = new TableLayout
{
Spacing = new Size(5, 3),
Rows =
{
new TableRow(new Label { Text = "Start timer:" }, new TableCell(_startHotkeyDropDown, false)),
new TableRow(new Label { Text = "Stop timer:" }, new TableCell(_stopHotkeyDropDown, false))
}
};
var hotkeyGroup = new GroupBox { Text = "Hotkeys", Content = hotkeyLayout };
// Group 4: Advanced
_disableGuiUpdatesCheck = new CheckBox { Text = "no GUI updates when not focused", Checked = Config.DisableDynamicGuiUpdates };
_freeMemoryCheck = new CheckBox { Text = "call the GC when the timer stops", Checked = Config.FreeMemoryWhenStopping };
var advancedLayout = new StackLayout
{
Spacing = 3,
Items = { _disableGuiUpdatesCheck, _freeMemoryCheck }
};
var advancedGroup = new GroupBox { Text = "Avanced", Content = advancedLayout };
// Grid Layout (2x2)
var grid = new TableLayout
{
Spacing = new Size(5, 5),
Rows =
{
new TableRow(new TableCell(dbGroup, false), new TableCell(trayGroup, false)),
new TableRow(new TableCell(hotkeyGroup, false), new TableCell(advancedGroup, false))
}
};
// Buttons
var okButton = new Button { Text = "OK", Width = 75, Height = 23 };
okButton.Click += (s, e) => SaveAndClose();
var cancelButton = new Button { Text = "Cancel", Width = 75, Height = 23 };
cancelButton.Click += (s, e) => Close(false);
DefaultButton = okButton;
AbortButton = cancelButton;
var buttonLayout = new StackLayout
{
Orientation = Orientation.Horizontal,
Spacing = 10,
Items = { okButton, cancelButton }
};
Content = new StackLayout
{
Padding = new Padding(5),
Spacing = 5,
HorizontalContentAlignment = HorizontalAlignment.Stretch,
Items =
{
grid,
new StackLayout { HorizontalContentAlignment = HorizontalAlignment.Right, Items = { buttonLayout } }
}
};
}
private void SaveAndClose()
{
Config.DatabaseUpdateFrequency = (uint)_dbFreqStepper.Value;
Config.DatabasePath = _dbPathBox.Text.Trim();
Config.DatabaseExportBufferSize = (uint)_dbExportBufStepper.Value;
Config.StoppedTimerColor = (TaskbarColor)Enum.Parse(typeof(TaskbarColor), _stoppedColorDropDown.SelectedKey ?? nameof(TaskbarColor.None));
Config.RunningTimerColor = (TaskbarColor)Enum.Parse(typeof(TaskbarColor), _runningColorDropDown.SelectedKey ?? nameof(TaskbarColor.Green));
Config.MinimizeToTray = _minimizeToTrayCheck.Checked ?? false;
Config.StartHotkey = (Hotkey)Enum.Parse(typeof(Hotkey), _startHotkeyDropDown.SelectedKey ?? nameof(Hotkey.None));
Config.StopHotkey = (Hotkey)Enum.Parse(typeof(Hotkey), _stopHotkeyDropDown.SelectedKey ?? nameof(Hotkey.None));
Config.DisableDynamicGuiUpdates = _disableGuiUpdatesCheck.Checked ?? false;
Config.FreeMemoryWhenStopping = _freeMemoryCheck.Checked ?? false;
Config.Save();
Close(true);
}
}
}