From 6ea217b674b5dfe75da01a0b30ba0a6f8080bcab Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 29 Jun 2021 15:17:03 -0400 Subject: [PATCH] fix: ContractPicker syncs selected sec/md w/ selected key --- .../Spark/ContractPicker/ContractPickerPopup.xaml.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/client/spark/view/Spark/ContractPicker/ContractPickerPopup.xaml.cs b/src/client/spark/view/Spark/ContractPicker/ContractPickerPopup.xaml.cs index 28e76b6c6..977580cc8 100644 --- a/src/client/spark/view/Spark/ContractPicker/ContractPickerPopup.xaml.cs +++ b/src/client/spark/view/Spark/ContractPicker/ContractPickerPopup.xaml.cs @@ -23,11 +23,13 @@ namespace mbts.ui.controls { readonly PropertyUpdateGate _selection_sync_gate = new PropertyUpdateGate(); IReadOnlyDictionary _cached_security_map = DictionaryHelper.empty(); + // The security key of the most recently changed property among + // SelectedSecurity, SelectedSecurityMD, and SelectedSecurityKey + uint? _last_selected_sec_key = null; ContractPickerPopupController _controller; bool _allow_empty, _is_lazy; public ContractPickerPopup() { - SetCurrentValue(SecurityMapProperty, new Dictionary(0)); var sec_map_source = Observable.Create>(o => { try_notify(); _security_map_changed += on_security_map_changed; @@ -50,6 +52,9 @@ namespace mbts.ui.controls { } }); _controller = new ContractPickerPopupController(this, new ContractPickerModel(sec_map_source, true, null)); + // This has to be set after _controller is initialized (because it causes a call to the IsEditMode getter, + // which assumes _controller is non-null) + SetCurrentValue(SecurityMapProperty, new Dictionary(0)); InitializeComponent(); DataContextChanged += (s, e) => { // - unhooking from oldval must co-incide with hooking to newval. @@ -91,6 +96,8 @@ namespace mbts.ui.controls { FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, (o, v) => { o._cached_security_map = v; + o._selection_sync_gate.try_update(() => o._sync_selection_props( + o.SelectedSecurityMD, o.SelectedSecurity, o.SelectedSecurityKey, o._last_selected_sec_key)); o._security_map_changed?.Invoke(v); }, (o, v) => v ?? new Dictionary()); @@ -125,6 +132,7 @@ namespace mbts.ui.controls { } void _sync_selection_props(SecurityMD? curr_sec_md, SecurityImmutable? curr_sec, uint? curr_sec_key, uint? target_sec_key) { + _last_selected_sec_key = target_sec_key; if (curr_sec_key != target_sec_key) { SetCurrentValue(SelectedSecurityKeyProperty, target_sec_key); }