Skip to content

Commit e61583c

Browse files
committed
Refactor custom duration input to hours and minutes fields
Replaces single minutes input with separate hours and minutes fields, updates validation and UI accordingly, and improves error handling and theming.
1 parent e888074 commit e61583c

2 files changed

Lines changed: 109 additions & 27 deletions

File tree

Forms/SettingsForm.Designer.cs

Lines changed: 79 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Forms/SettingsForm.cs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ protected override void UpdateTheme() {
6565
OnIconLbl.ForeColor = ForeColor;
6666
CustomDurationLBL.ForeColor = ForeColor;
6767
tooltipFormatLBL.ForeColor = ForeColor;
68+
hoursLabel.ForeColor = ForeColor;
69+
minutesLabel.ForeColor = ForeColor;
6870

6971
// Update main icon based on theme - use light colored icons for dark mode
7072
pictureBox1.Image = IsDarkMode ? Resources.cup_coffee_icon_96 : Resources.Caffeine_Black_96;
@@ -238,25 +240,44 @@ private async void StartupChkBox_CheckedChanged(object sender, EventArgs e) {
238240
}
239241

240242
private void addCustomDurationBTN_Click(object sender, EventArgs e) {
241-
bool didParse = int.TryParse(CustomDurationTXBX.Text, out int newDuration);
243+
bool hoursParsed = int.TryParse(hoursTextBox.Text, out int hours);
244+
bool minutesParsed = int.TryParse(minutesTextBox.Text, out int minutes);
242245

243-
if (didParse == false)
246+
if (!hoursParsed || !minutesParsed)
244247
return;
245248

246-
if ( newDuration < 0) {
247-
CustomDurationTXBX.Text = "";
249+
if (hours < 0 || minutes < 0) {
248250
MessageBox.Show(
249-
"Enter a positive number.",
251+
"Enter positive numbers.",
252+
"Caffeinated",
253+
MessageBoxButtons.OK
254+
);
255+
return;
256+
}
257+
258+
if (minutes >= 60) {
259+
MessageBox.Show(
260+
"Minutes must be less than 60.",
261+
"Caffeinated",
262+
MessageBoxButtons.OK
263+
);
264+
return;
265+
}
266+
267+
int newDuration = hours * 60 + minutes;
268+
269+
if (newDuration == 0) {
270+
MessageBox.Show(
271+
"Duration must be greater than 0.",
250272
"Caffeinated",
251273
MessageBoxButtons.OK
252274
);
253275
return;
254276
}
255277

256278
if (appSettings.Durations.Contains(newDuration)) {
257-
CustomDurationTXBX.Text = "";
258279
MessageBox.Show(
259-
$"{newDuration} is already a duration.",
280+
$"{newDuration} minutes is already a duration.",
260281
"Caffeinated",
261282
MessageBoxButtons.OK
262283
);
@@ -275,7 +296,8 @@ private void addCustomDurationBTN_Click(object sender, EventArgs e) {
275296
}
276297
appSettings.Durations.Add(newDuration);
277298

278-
CustomDurationTXBX.Text = "";
299+
hoursTextBox.Text = "0";
300+
minutesTextBox.Text = "0";
279301
}
280302

281303
private void defaultRDBTN_Click(object sender, EventArgs e) {

0 commit comments

Comments
 (0)