SPARK-1863 Fills Time Filter

This commit is contained in:
John Colvin committed 2018-11-02 14:26:34 -05:00
1 parent 38e0d40364
commit 717391afb3
5 files changed
+54 -19

No files matched your search

@@ -20,6 +20,7 @@
Content="Apply"
CommandParameter="{TemplateBinding ApplyCommandParameter}"
Command="{TemplateBinding ApplyCommand}"
CommandTarget="{TemplateBinding ApplyCommandTarget}"
IsDefault="True"
Focusable="False"
Style="{StaticResource CommonButton}"
@@ -24,6 +24,11 @@ namespace mbts.ui.spark {
public object ApplyCommandParameter { get => GetValue(ApplyCommandParameterProperty); set => SetValue(ApplyCommandParameterProperty, value); }
#endregion
#region ApplyCommandTarget
public static readonly DependencyProperty ApplyCommandTargetProperty = WPFHelper.create_dp<IInputElement, FilterContentControl>(nameof(ApplyCommandTarget));
public IInputElement ApplyCommandTarget { get => GetValue(ApplyCommandTargetProperty) as IInputElement; set => SetValue(ApplyCommandTargetProperty, value); }
#endregion
#region ClearCommand
public static readonly DependencyProperty ClearCommandProperty = DependencyProperty.Register(
nameof(ClearCommand), typeof(ICommand), typeof(FilterContentControl));
@@ -106,6 +106,7 @@
<usp:FilterContentControl
ApplyCommandParameter="{Binding}"
ApplyCommand="{x:Static c:DataGridFilterProperties.CommitCommand}"
ApplyCommandTarget="{Binding ElementName=Filter}"
ClearCommandParameter="{Binding}"
ClearCommand="{x:Static c:DataGridFilterProperties.ClearCommand}"
>
@@ -115,6 +116,9 @@
Begin="{Binding begin}"
End="{Binding end}"
>
<c:TimeFilterControl.CommandBindings>
<CommandBinding Command="{x:Static c:DataGridFilterProperties.CommitCommand}" Executed="{x:Static c:TimeFilterControl.CommitExecuted}"/>
</c:TimeFilterControl.CommandBindings>
<u:Behavior.BindingUpdateGroups>
<u:BindingUpdateGroupCollection>
<u:BindingUpdateGroup Source="{Binding DataContext, Source={u:DirectReference Filter}}" Target="{Binding Source={u:DirectReference Filter}}">
@@ -7,6 +7,7 @@ using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
namespace mbts.ui.controls {
@@ -14,6 +15,18 @@ namespace mbts.ui.controls {
/// Interaction logic for TimeFilterControl.xaml
/// </summary>
public class TimeFilterControl : Control {
public static readonly ExecutedRoutedEventHandler CommitExecuted = (s, e) => {
if (s is TimeFilterControl tfc) {
tfc.get_template_child<DateTimePicker>(_begin_dtp_name)?.flush_pending_changes();
tfc.get_template_child<DateTimePicker>(_end_dtp_name)?.flush_pending_changes();
(e.Parameter as IDataGridColumnFilter)?.apply.TryExecuteIfCan(null);
e.Handled = true;
}
};
const string
_begin_dtp_name = "PART_Begin_DateTimePicker",
_end_dtp_name = "PART_End_DateTimePicker";
static TimeFilterControl() =>
DefaultStyleKeyProperty.OverrideMetadata(typeof(TimeFilterControl), new FrameworkPropertyMetadata(typeof(TimeFilterControl)));
@@ -54,8 +67,8 @@ namespace mbts.ui.controls {
readonly ChildProperty<DateTimePicker> _begin_picker, _end_picker;
public TimeFilterErrorAdorner(TimeFilterControl view) : base(view) {
_begin_picker = child_property<DateTimePicker>("PART_Begin_DateTimePicker");
_end_picker = child_property<DateTimePicker>("PART_End_DateTimePicker");
_begin_picker = child_property<DateTimePicker>(_begin_dtp_name);
_end_picker = child_property<DateTimePicker>(_end_dtp_name);
}
protected override void OnRender(DrawingContext drawing_context) {
@@ -18,6 +18,11 @@ namespace mbts.ui.controls {
public static readonly RoutedCommand TickTimeComponentCommand = new RoutedCommand();
DTPController _controller;
TextBox
_month_text,
_day_text,
_year_text,
_time_text;
bool _suspend_notify_vm;
static DateTimePicker() =>
@@ -34,18 +39,25 @@ namespace mbts.ui.controls {
IList<IDisposable> _hooks = new List<IDisposable>();
public void flush_pending_changes() {
_month_text?.GetBindingExpression(TextBox.TextProperty)?.UpdateSource();
_day_text?.GetBindingExpression(TextBox.TextProperty)?.UpdateSource();
_year_text?.GetBindingExpression(TextBox.TextProperty)?.UpdateSource();
_time_text?.GetBindingExpression(TextBox.TextProperty)?.UpdateSource();
}
public override void OnApplyTemplate() {
var month = this.assert_template_child<TickUpDown>("PART_month_tick");
var month_text = this.assert_template_child<TextBox>("PART_month_text");
_month_text = this.assert_template_child<TextBox>("PART_month_text");
var day = this.assert_template_child<TickUpDown>("PART_day_tick");
var day_text = this.assert_template_child<TextBox>("PART_day_text");
_day_text = this.assert_template_child<TextBox>("PART_day_text");
var year = this.assert_template_child<TickUpDown>("PART_year_tick");
var year_text = this.assert_template_child<TextBox>("PART_year_text");
_year_text = this.assert_template_child<TextBox>("PART_year_text");
var time = this.assert_template_child<TickUpDown>("PART_time_tick");
var time_text = this.assert_template_child<TextBox>("PART_time_text");
_time_text = this.assert_template_child<TextBox>("PART_time_text");
if (_controller != null) _controller.PropertyChanged -= _vm_PropertyChanged;
_controller = new DTPController(time_text);
_controller = new DTPController(_time_text);
_controller.result = TimeTuple;
_controller.PropertyChanged += _vm_PropertyChanged;
time.CommandBindings.Add(new CommandBinding(TickTimeComponentCommand, (s, e) => {
@@ -58,9 +70,9 @@ namespace mbts.ui.controls {
time.TickDownParameter = -1;
time.TickUpAltParameter = 60;
time.TickDownAltParameter = -60;
time_text.SetBinding(TextBox.TextProperty, new Binding("time_text") { Source = _controller, ValidatesOnExceptions = true });
_hooks.Add(time_text.SubscribePreviewTextInput((s, e) => {
string preview = time_text.PeekText(e);
_time_text.SetBinding(TextBox.TextProperty, new Binding("time_text") { Source = _controller, ValidatesOnExceptions = true });
_hooks.Add(_time_text.SubscribePreviewTextInput((s, e) => {
string preview = _time_text.PeekText(e);
if (RegexFilters.Time.StandardTimeOptionalSeconds.IsMatch(preview)) {
_controller.use_military_time = false;
} else if (RegexFilters.Time.MilitaryTimeOptionalSeconds.IsMatch(preview)) {
@@ -73,25 +85,25 @@ namespace mbts.ui.controls {
month.SetBinding(TickUpDown.TickCommandProperty, new Binding("tick_month") { Source = _controller });
month.TickUpParameter = 1;
month.TickDownParameter = -1;
month_text.SetBinding(TextBox.TextProperty, new Binding("month_text") { Source = _controller });
_hooks.Add(month_text.SubscribePreviewTextInput((s, e) =>
e.Handled = !RegexFilters.Time.MonthAbbrev.IsMatch(month_text.PeekText(e))
_month_text.SetBinding(TextBox.TextProperty, new Binding("month_text") { Source = _controller });
_hooks.Add(_month_text.SubscribePreviewTextInput((s, e) =>
e.Handled = !RegexFilters.Time.MonthAbbrev.IsMatch(_month_text.PeekText(e))
));
day.SetBinding(TickUpDown.TickCommandProperty, new Binding("tick_day") { Source = _controller });
day.TickUpParameter = 1;
day.TickDownParameter = -1;
day_text.SetBinding(TextBox.TextProperty, new Binding("day_text") { Source = _controller });
_hooks.Add(day_text.SubscribePreviewTextInput((s, e) =>
e.Handled = !RegexFilters.Time.DaysInMonth.IsMatch(day_text.PeekText(e))
_day_text.SetBinding(TextBox.TextProperty, new Binding("day_text") { Source = _controller });
_hooks.Add(_day_text.SubscribePreviewTextInput((s, e) =>
e.Handled = !RegexFilters.Time.DaysInMonth.IsMatch(_day_text.PeekText(e))
));
year.SetBinding(TickUpDown.TickCommandProperty, new Binding("tick_year") { Source = _controller });
year.TickUpParameter = 1;
year.TickDownParameter = -1;
year_text.SetBinding(TextBox.TextProperty, new Binding("year_text") { Source = _controller });
_hooks.Add(year_text.SubscribePreviewTextInput((s, e) =>
e.Handled = !RegexFilters.Time.Year.IsMatch(year_text.PeekText(e))
_year_text.SetBinding(TextBox.TextProperty, new Binding("year_text") { Source = _controller });
_hooks.Add(_year_text.SubscribePreviewTextInput((s, e) =>
e.Handled = !RegexFilters.Time.Year.IsMatch(_year_text.PeekText(e))
));
}