From 31392df28d71c328b36d956e8161c598a4dbfbf1 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 5 Dec 2017 18:43:35 -0600 Subject: [PATCH] Contract Picker Model - OK and Cancel buttons behave as one would expect --- .../spark/Daemons/SecurityPickerDaemon.cs | 10 ++++++++-- .../ContractPicker/ContractPickerModel.cs | 17 +++++++++++++++++ .../ContractPicker/ContractPickerView.xaml | 6 +++--- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/client/spark/Daemons/SecurityPickerDaemon.cs b/src/client/spark/Daemons/SecurityPickerDaemon.cs index c485acf0e..ef045523b 100644 --- a/src/client/spark/Daemons/SecurityPickerDaemon.cs +++ b/src/client/spark/Daemons/SecurityPickerDaemon.cs @@ -35,7 +35,10 @@ namespace bts { SizeToContent = SizeToContent.WidthAndHeight }; picker.CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, (sender, e) => picker.Close())); - picker.Closing += (_,__) => _bus.post(next, vm.result); + vm.close_action = () => { + picker.Close(); + _bus.post(next, vm.result); + }; picker.Show(); } @@ -49,7 +52,10 @@ namespace bts { SizeToContent = SizeToContent.WidthAndHeight }; picker.CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, (sender, e) => picker.Close())); - picker.Closing += (_, __) => _bus.post(next, vm.result_criteria); + vm.close_action = () => { + picker.Close(); + _bus.post(next, vm.result_criteria); + }; picker.Show(); } diff --git a/src/client/spark/mspark/ContractPicker/ContractPickerModel.cs b/src/client/spark/mspark/ContractPicker/ContractPickerModel.cs index 0a8e9accc..7ec18ecb0 100644 --- a/src/client/spark/mspark/ContractPicker/ContractPickerModel.cs +++ b/src/client/spark/mspark/ContractPicker/ContractPickerModel.cs @@ -49,13 +49,26 @@ namespace mbts.spark { security_keys = selected_securities }); criteria_input_name = string.Empty; + ok_button_command.TryRaiseCanExecuteChanged(); }); remove_criteria_command = new DelegateCommand(_ => { security_criteria.Remove(selected_security_criteria_clause); + ok_button_command.TryRaiseCanExecuteChanged(); }); + ok_button_command = new DelegateCommand( + execute: _ => { close_action?.Invoke(); }, + can_execute: _ => { + if (!is_edit_mode) { + return (selected_securities.Count > 0); + } else { + return (security_criteria.Count > 0); + } + } + ); + } @@ -124,6 +137,7 @@ namespace mbts.spark { internal void security_selection_changed(IEnumerable secs) { selected_securities = secs.Select(s => s.Id).ToList(); + ok_button_command.TryRaiseCanExecuteChanged(); _compose_criteria_clause_name(); // _security_in_criteria is our fun to be returned to our callers @@ -172,6 +186,7 @@ namespace mbts.spark { public ICommand add_criteria_command { get; } public ICommand remove_criteria_command { get; } + public ICommand ok_button_command { get; } public ObservableCollection security_criteria { get; } = new ObservableCollection(); private SecurityCriteriaClause _selected_security_criteria_clause = new SecurityCriteriaClause(); @@ -193,6 +208,8 @@ namespace mbts.spark { } } + public Action close_action { get; set; } + public bool is_edit_mode { get; set; } private SecurityCriteria _search_criteria; diff --git a/src/client/spark/mspark/ContractPicker/ContractPickerView.xaml b/src/client/spark/mspark/ContractPicker/ContractPickerView.xaml index 1d04633a6..b09ddc656 100644 --- a/src/client/spark/mspark/ContractPicker/ContractPickerView.xaml +++ b/src/client/spark/mspark/ContractPicker/ContractPickerView.xaml @@ -18,7 +18,7 @@ - + @@ -34,8 +34,8 @@ - - + +