Skip to content

Commit

Permalink
Add dialog to edit timeout duration
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Spreitzer committed Jun 23, 2019
1 parent 8410c99 commit c91b7f2
Show file tree
Hide file tree
Showing 9 changed files with 552 additions and 45 deletions.
196 changes: 196 additions & 0 deletions src/NoDoz/FormDurationEdit.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions src/NoDoz/FormDurationEdit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Windows.Forms;
using NodaTime;

namespace NoDoz
{
public partial class FormDurationEdit : Form
{
public FormDurationEdit()
{
InitializeComponent();
}

public Duration? Timeout { get; private set; }

private void buttonCancel_Click(object sender, EventArgs e) => DialogResult = DialogResult.Cancel;

private void buttonDone_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;

if (!checkBoxIndefinite.Checked)
Timeout = Duration.FromTimeSpan(new TimeSpan((int)numericUpDownHours.Value, (int)numericUpDownMinutes.Value, (int)numericUpDownSeconds.Value));
}

private void numericUpDownHours_Enter(object sender, EventArgs e) => numericUpDownHours.Select(0, 10);

private void numericUpDownMinutes_Enter(object sender, EventArgs e) => numericUpDownMinutes.Select(0, 10);

private void numericUpDownSeconds_Enter(object sender, EventArgs e) => numericUpDownSeconds.Select(0, 10);

private void checkBoxIndefinite_CheckedChanged(object sender, EventArgs e)
{
numericUpDownHours.Enabled = !checkBoxIndefinite.Checked;
numericUpDownMinutes.Enabled = !checkBoxIndefinite.Checked;
numericUpDownSeconds.Enabled = !checkBoxIndefinite.Checked;
}

private void FormDurationEdit_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
DialogResult = DialogResult.Cancel;
e.Handled = true;
e.SuppressKeyPress = true;
}
}
}
}
Loading

0 comments on commit c91b7f2

Please sign in to comment.