Skip to content

Commit

Permalink
Interval/display times are now saved on pressing enter
Browse files Browse the repository at this point in the history
  • Loading branch information
ZsoltGajdacs committed Feb 5, 2019
1 parent d70b4db commit aed17ca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
4 changes: 2 additions & 2 deletions BlinkReminder/Windows/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@
</Grid.ColumnDefinitions>

<Label x:Name="shortIntervalLabel" Content="Interval of short break (s): " Grid.Column="1" Grid.Row="1"/>
<TextBox x:Name="shortIntervalText" Text="{Binding ShortIntervalTime, Mode=TwoWay}" Grid.Column="2" Grid.Row="1" Background="#FFF8F8F8" PreviewTextInput="TimesTextBox_PreviewTextInput" LostFocus="ShortIntervalText_LostFocus"/>
<TextBox x:Name="shortIntervalText" Text="{Binding ShortIntervalTime, Mode=TwoWay, NotifyOnSourceUpdated=True}" Grid.Column="2" Grid.Row="1" Background="#FFF8F8F8" KeyUp="SaveOnEnter" PreviewTextInput="TimesTextBox_PreviewTextInput" SourceUpdated="ShortIntervalText_SourceUpdated"/>
<Label x:Name="shortIntervalMinuteLabel" Content="{Binding ShortIntervalTimeFormatted, Mode=OneWay}" Grid.Column="3" Grid.Row="1"/>

<Label x:Name="shortDispLabel" Content="Length of short break (s): " Grid.Column="1" Grid.Row="3"/>
<TextBox x:Name="shortDispText" Text="{Binding ShortDisplayTime, Mode=TwoWay}" Grid.Column="2" Grid.Row="3" Background="#FFF8F8F8" KeyUp="TimesTextBox_KeyUp" PreviewTextInput="TimesTextBox_PreviewTextInput"/>
<Label x:Name="shortDispMinuteLabel" Content="{Binding ShortDisplayTimeFormatted, Mode=OneWay}" Grid.Column="3" Grid.Row="3"/>

<Label x:Name="longIntervalLabel" Content="Interval of long break (s): " Grid.Column="1" Grid.Row="5"/>
<TextBox x:Name="longIntervalText" Text="{Binding LongIntervalTime, Mode=TwoWay}" Grid.Column="2" Grid.Row="5" Background="#FFF8F8F8" PreviewTextInput="TimesTextBox_PreviewTextInput" LostFocus="LongIntervalText_LostFocus"/>
<TextBox x:Name="longIntervalText" Text="{Binding LongIntervalTime, Mode=TwoWay, NotifyOnSourceUpdated=True}" Grid.Column="2" Grid.Row="5" Background="#FFF8F8F8" KeyUp="SaveOnEnter" PreviewTextInput="TimesTextBox_PreviewTextInput" SourceUpdated="LongIntervalText_SourceUpdated"/>
<Label x:Name="longIntervalMinuteLabel" Content="{Binding LongIntervalTimeFormatted, Mode=OneWay}" Grid.Column="3" Grid.Row="5"/>

<Label x:Name="longDispLabel" Content="Length of long break (s): " Grid.Column="1" Grid.Row="7"/>
Expand Down
24 changes: 22 additions & 2 deletions BlinkReminder/Windows/SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,31 @@ private void TimesTextBox_KeyUp(object sender, KeyEventArgs e)
textBox.Text = null;
tooltipHandler.ShowTooltipOnTextBox(ref textBox, "Can't have 0 seconds!");
}

SaveOnEnter(sender, e);
}

/// <summary>
/// Saves the textbox's value on Enter
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SaveOnEnter(object sender, KeyEventArgs e)
{
TextBox textBox = sender as TextBox;
if (e.Key == Key.Enter)
{
BindingExpression textBindingExpr = textBox.GetBindingExpression(TextBox.TextProperty);

if (textBindingExpr == null) return;

textBindingExpr.UpdateSource();
}
}
#endregion

#region Timer disable support
private void ShortIntervalText_LostFocus(object sender, RoutedEventArgs e)
private void ShortIntervalText_SourceUpdated(object sender, DataTransferEventArgs e)
{
if (shortIntervalText.Text.Equals("0"))
{
Expand All @@ -202,7 +222,7 @@ private void ShortIntervalText_LostFocus(object sender, RoutedEventArgs e)
}
}

private void LongIntervalText_LostFocus(object sender, RoutedEventArgs e)
private void LongIntervalText_SourceUpdated(object sender, DataTransferEventArgs e)
{
if (longIntervalText.Text.Equals("0"))
{
Expand Down

0 comments on commit aed17ca

Please sign in to comment.