From 62d06180ea5a71c2ef0756d53dae00a96b77dd9e Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 30 Jan 2019 19:24:50 -0600 Subject: [PATCH] making row stay in edit mode when a change has not yet been committed but the selection has been moved off the row --- .../MiniOrderBook/MiniOrderBookView.xaml | 2 +- .../Trading/OrderBook/OrderBookColumns.cs | 2 +- .../Trading/OrderBook/OrderBookRowVM.cs | 26 ++++++++++++++--- .../TickUpDownNullableUIntCommit.xaml | 5 +++- .../TickUpDownNullableUIntCommit.xaml.cs | 28 +++++++++++++++---- 5 files changed, 51 insertions(+), 12 deletions(-) diff --git a/src/client/spark/Modules/Trading/OrderBook/MiniOrderBook/MiniOrderBookView.xaml b/src/client/spark/Modules/Trading/OrderBook/MiniOrderBook/MiniOrderBookView.xaml index ce2270938..0f67a7b83 100644 --- a/src/client/spark/Modules/Trading/OrderBook/MiniOrderBook/MiniOrderBookView.xaml +++ b/src/client/spark/Modules/Trading/OrderBook/MiniOrderBook/MiniOrderBookView.xaml @@ -62,7 +62,7 @@ - + diff --git a/src/client/spark/Modules/Trading/OrderBook/OrderBookColumns.cs b/src/client/spark/Modules/Trading/OrderBook/OrderBookColumns.cs index 60ce5ebb8..8f38130ba 100644 --- a/src/client/spark/Modules/Trading/OrderBook/OrderBookColumns.cs +++ b/src/client/spark/Modules/Trading/OrderBook/OrderBookColumns.cs @@ -718,7 +718,7 @@ namespace mbts.spark { public override FrameworkElement view_factory() { var tick_up_down = new TickUpDownNullableUIntCommit(); - tick_up_down.SetBinding(TickUpDownNullableUIntCommit.SourceValueProperty, nameof(OrderBookRowVM.quantity)); + tick_up_down.SetBinding(TickUpDownNullableUIntCommit.SourceValueProperty, nameof(OrderBookRowVM.prospective_quantity)); tick_up_down.SetBinding(TickUpDownNullableUIntCommit.OnCommitProperty, nameof(OrderBookRowVM.modify_order_quantity)); return tick_up_down; } diff --git a/src/client/spark/Modules/Trading/OrderBook/OrderBookRowVM.cs b/src/client/spark/Modules/Trading/OrderBook/OrderBookRowVM.cs index 222a4000d..6fd0cc6c1 100644 --- a/src/client/spark/Modules/Trading/OrderBook/OrderBookRowVM.cs +++ b/src/client/spark/Modules/Trading/OrderBook/OrderBookRowVM.cs @@ -20,12 +20,17 @@ namespace mbts.spark { bool _is_parent, _is_expanded, _is_selected; int _depth_level; SecurityMD? _security_md => order_tuple.security_md; - + Property _prospective_quantity; + Property _is_qty_dirty; + + public OrderBookRowVM(OrderBookVM owner, OrderRecordTuple order_tuple, bool is_expanded) { _owner = owner; this.order_tuple = order_tuple; is_visible = !is_child; _is_expanded = is_expanded; + _prospective_quantity = backing(nameof(prospective_quantity), this.quantity); + _is_qty_dirty = backing(nameof(is_qty_dirty), () => this.prospective_quantity != this.quantity, nameof(prospective_quantity), nameof(quantity)); this.invalidated += OrderBookRowVM_invalidated; } @@ -90,6 +95,17 @@ namespace mbts.spark { get => _is_selected; set => Set(ref _is_selected, value); } + public uint prospective_quantity { + get => _prospective_quantity.Value; + set => _prospective_quantity.set(value); + } + + public bool is_qty_dirty { + get => _is_qty_dirty.Value; + set => _is_qty_dirty.set(value); + } + + // Commands public ICommand toggle_command => _toggle_expanded_cmd ?? ( _toggle_expanded_cmd = new DelegateCommand(() => is_expanded = !is_expanded)); @@ -103,9 +119,9 @@ namespace mbts.spark { public ICommand modify_order_quantity => _modify_order_quantity ?? (_modify_order_quantity = new DelegateCommand( (desired_quantity) => _owner.modify_order_quantity(this, (uint)desired_quantity), - (desired_quantity) => desired_quantity != null && - this.status == OrderStatus.Working && - (uint)desired_quantity != this.quantity + (desired_quantity) => + (desired_quantity != null && this.status == OrderStatus.Working && (uint)desired_quantity != this.quantity) + || prospective_quantity != this.quantity ) ); @@ -133,6 +149,8 @@ namespace mbts.spark { // however, the order-type and security cells DO use databindings - if these cells have changed, the PropertyChanged event must be raised regardless of whether or not invalidated is raised if (old_order.order_type() != order.order_type()) RaisePropertyChanged(nameof(order_type), nameof(order_metadata)); + if (old_order.quantity() != order.quantity()) + RaisePropertyChanged(nameof(quantity)); if (!had_security && _security_md.HasValue) { RaisePropertyChanged(nameof(security), nameof(security_text)); // need to raise invalidated to refresh the price cells (the security.ContractSpec determines how they are formatted - Ticks!) diff --git a/src/client/spark/view/Controls/TickUpDown/TickUpDownNullableUIntCommit.xaml b/src/client/spark/view/Controls/TickUpDown/TickUpDownNullableUIntCommit.xaml index 700e9967f..a1aa32195 100644 --- a/src/client/spark/view/Controls/TickUpDown/TickUpDownNullableUIntCommit.xaml +++ b/src/client/spark/view/Controls/TickUpDown/TickUpDownNullableUIntCommit.xaml @@ -3,7 +3,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:local="clr-namespace:mbts.ui.controls" mc:Ignorable="d" xmlns:c="clr-namespace:mbts.ui.controls" d:DesignHeight="100" d:DesignWidth="800" x:Name="_me"> @@ -38,6 +37,7 @@ + @@ -48,6 +48,9 @@ + + + diff --git a/src/client/spark/view/Controls/TickUpDown/TickUpDownNullableUIntCommit.xaml.cs b/src/client/spark/view/Controls/TickUpDown/TickUpDownNullableUIntCommit.xaml.cs index 6a31c60d6..0a4f8e3fa 100644 --- a/src/client/spark/view/Controls/TickUpDown/TickUpDownNullableUIntCommit.xaml.cs +++ b/src/client/spark/view/Controls/TickUpDown/TickUpDownNullableUIntCommit.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -24,7 +25,8 @@ namespace mbts.ui.controls { DependencyProperty.Register("SourceValue", typeof(uint?), typeof(TickUpDownNullableUIntCommit), - new PropertyMetadata { + new FrameworkPropertyMetadata { + BindsTwoWayByDefault = true, PropertyChangedCallback = source_value_changed } ); @@ -51,10 +53,6 @@ namespace mbts.ui.controls { public TickUpDownNullableUIntCommit() { InitializeComponent(); - - var content_control = read_only_or_edit.Template.LoadContent() as FrameworkElement; - var qty = content_control.FindName("qty_ticker") as TickUpDownNullableUInt; - } //private void Commit_button_Click(object sender, RoutedEventArgs e) { @@ -66,4 +64,24 @@ namespace mbts.ui.controls { // } //} } + + class JakeTemplateConverter : IValueConverter { + public ControlTemplate NormalTemplate { get; set; } + public ControlTemplate EditableTemplate { get; set; } + + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { + if (value is mbts.spark.OrderBookRowVM vm) { + if (vm.is_qty_dirty || vm.is_selected) { + return EditableTemplate; + } + return NormalTemplate; + } + return NormalTemplate; + + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { + throw new NotImplementedException(); + } + } }