From dcaae15e28e8d9a3944d80fa3d79e9efa7fe6023 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 12 Dec 2018 09:23:45 -0600 Subject: [PATCH] SPARK-1917 - resizable order entry panel --- .../spark/view/Spark/Ladder/LadderSettings.cs | 17 +++++++++---- .../view/Spark/Ladder/LadderSettingsVM.cs | 10 +++++++- .../spark/view/Spark/Ladder/LadderVM.cs | 14 +++++++++-- .../spark/view/Spark/Ladder/LadderView.xaml | 24 +++++++++++-------- 4 files changed, 48 insertions(+), 17 deletions(-) diff --git a/src/client/spark/view/Spark/Ladder/LadderSettings.cs b/src/client/spark/view/Spark/Ladder/LadderSettings.cs index 543cec882..547b910c1 100644 --- a/src/client/spark/view/Spark/Ladder/LadderSettings.cs +++ b/src/client/spark/view/Spark/Ladder/LadderSettings.cs @@ -180,6 +180,8 @@ namespace mbts.spark { // Settings are liable to change in the near future, so an internal IEqualityComparer simply won't do as it risks becoming out of date. [ProtoContract] class LadderSettings : IEquatable { + const double _default_order_entry_panel_width = 110.0; + // Default proto constructor // Added this so that when clients upgrade to a version with new settings, // the default values are applied correctly; thx to John for this tip @@ -199,6 +201,7 @@ namespace mbts.spark { cancel_sells_visible = true; cancel_all_visible = true; auto_clear_visible = true; + order_entry_panel_initial_width = _default_order_entry_panel_width; } public static LadderSettings Default { @@ -253,7 +256,8 @@ namespace mbts.spark { cancel_buys_visible = true, cancel_sells_visible = true, cancel_all_visible = true, - auto_clear_visible = true + auto_clear_visible = true, + order_entry_panel_initial_width = _default_order_entry_panel_width }; } } @@ -346,7 +350,10 @@ namespace mbts.spark { public bool cancel_all_visible { get; set; } [ProtoMember(41), DefaultValue(true)] public bool auto_clear_visible { get; set; } - + // + [ProtoMember(42), DefaultValue(_default_order_entry_panel_width)] + public double order_entry_panel_initial_width { get; set; } + public bool Equals(LadderSettings other) => other != null && @@ -387,7 +394,8 @@ namespace mbts.spark { cancel_buys_visible == other.cancel_buys_visible && cancel_sells_visible == other.cancel_sells_visible && cancel_all_visible == other.cancel_all_visible && - auto_clear_visible == other.auto_clear_visible + auto_clear_visible == other.auto_clear_visible && + order_entry_panel_initial_width == other.order_entry_panel_initial_width ; public override bool Equals(object obj) => Equals(obj as LadderSettings); @@ -431,7 +439,8 @@ namespace mbts.spark { cancel_buys_visible.GetHashCode(), cancel_sells_visible.GetHashCode(), cancel_all_visible.GetHashCode(), - auto_clear_visible.GetHashCode() + auto_clear_visible.GetHashCode(), + order_entry_panel_initial_width.GetHashCode() ); } diff --git a/src/client/spark/view/Spark/Ladder/LadderSettingsVM.cs b/src/client/spark/view/Spark/Ladder/LadderSettingsVM.cs index 91c79599b..9b20bdddb 100644 --- a/src/client/spark/view/Spark/Ladder/LadderSettingsVM.cs +++ b/src/client/spark/view/Spark/Ladder/LadderSettingsVM.cs @@ -16,6 +16,7 @@ namespace mbts.spark { class LadderSettingsVM : ViewModelBase, IWindowSettingsVM, ITemplateSelectorKey { readonly Property _badge_style; readonly Property _alternate_order_size; + readonly double _order_entry_panel_width; readonly DelegateProperty _row_height; LadderSettings _current; LadderColumnSettingsVM @@ -50,13 +51,15 @@ namespace mbts.spark { _cancel_all_visibility = new OrderEntryPanelItemVisibilityVM("Cancel All"); - public LadderSettingsVM(bool is_synthetic) { + public LadderSettingsVM(bool is_synthetic, double left_panel_width) { this.is_synthetic = is_synthetic; size_presets = new ObservableEditableCollection>(_create_size_preset_vm); size_presets.CollectionChanged += (s, e) => RaisePropertyChanged(nameof(size_presets_text)); _badge_style = backing(nameof(badge_style)); _badge_style.Changed += _badge_style_Changed; _alternate_order_size = backing(nameof(alternate_order_size)); + _order_entry_panel_width = left_panel_width; + // be sure to initialize backings before this measure_row_height call _row_height = backing(nameof(row_height), () => LadderRender.measure_row_height(get_result())); _orders.font_size_changed += on_font_size_changed; _bid.font_size_changed += on_font_size_changed; @@ -180,6 +183,10 @@ namespace mbts.spark { _cancel_buys_visibility.show = settings.cancel_buys_visible; _cancel_sells_visibility.show = settings.cancel_sells_visible; _cancel_all_visibility.show = settings.cancel_all_visible; + // do not read the order entry panel width here from settings + // because it could have changed from the UI + // there might be a better way of doing this, like how + // does the widths of the ladder grid column pull this off? } public LadderSettings get_result() { @@ -216,6 +223,7 @@ namespace mbts.spark { clone.cancel_buys_visible = _cancel_buys_visibility.show; clone.cancel_sells_visible = _cancel_sells_visibility.show; clone.cancel_all_visible = _cancel_all_visibility.show; + clone.order_entry_panel_initial_width = _order_entry_panel_width; return clone; } diff --git a/src/client/spark/view/Spark/Ladder/LadderVM.cs b/src/client/spark/view/Spark/Ladder/LadderVM.cs index 658d29336..3945933f0 100644 --- a/src/client/spark/view/Spark/Ladder/LadderVM.cs +++ b/src/client/spark/view/Spark/Ladder/LadderVM.cs @@ -24,6 +24,7 @@ namespace mbts.spark { readonly IBus _bus; readonly LadderModel _model; + readonly Property _left_panel_width; readonly Property _high, _low, _change, _open, _settlement, _position; readonly Property _volume; readonly Property _auto_clear, _show_day, _show_high, _show_low, _show_open, _show_settle, _show_volume, _show_account, @@ -83,6 +84,7 @@ namespace mbts.spark { backing(name, settings_manager.subscribe_current().OnDispatcher(), get_bool); // + _left_panel_width = backing(nameof(left_panel_width), settings_manager.subscribe_current().OnDispatcher().Select(s => s.order_entry_panel_initial_width)); position_click_command = new DelegateCommand(() => size_calculator.value = DoubleHelper.safe_convert_to_uint(Math.Abs(position))); send_order_command = new DelegateCommand<(double price, Side? side, bool size_from_alternate)>(send_order); cancel_command = new AsyncCommand(_model.cancel_orders, true); @@ -91,8 +93,8 @@ namespace mbts.spark { settings_command = new DialogCommand(() => { var vm = new WindowSettingsDialogVM( settings_manager, s => s.ladder, UserSettings.FileExtensions.LADDER, - s => { - var svm = new LadderSettingsVM(security.ContractCase == Security.ContractOneofCase.Synthetic); + s => { + var svm = new LadderSettingsVM(security.ContractCase == Security.ContractOneofCase.Synthetic, left_panel_width); svm.load(s); return svm; }); @@ -272,6 +274,7 @@ namespace mbts.spark { public bool show_cancel_buys { get => _show_cancel_buys.Value; set => _show_cancel_buys.set(value); } public bool show_cancel_sells { get => _show_cancel_sells.Value; set => _show_cancel_sells.set(value); } public bool show_cancel_all { get => _show_cancel_all.Value; set => _show_cancel_all.set(value); } + public double left_panel_width { get => _left_panel_width.Value; set => _left_panel_width.set(value); } internal LadderModel model => _model; internal IObservable settings => _settings_manager.subscribe_current(); @@ -281,6 +284,13 @@ namespace mbts.spark { return null; var settings_clone = SparkUtils.clone_proto(_settings_manager.instance_settings); settings_clone.default_order_type = order_properties_vm.selected_order_type?.order_type ?? settings_clone.default_order_type; + + // the user would need to have set some kind of customization in the + // main settings form first for instance settings to have been saved at some point. + // After which, it's possible they will adjust the panel width without explicitly + // going into the settings form again. + // Right now I will save this change ... + settings_clone.order_entry_panel_initial_width = left_panel_width; return settings_clone; } diff --git a/src/client/spark/view/Spark/Ladder/LadderView.xaml b/src/client/spark/view/Spark/Ladder/LadderView.xaml index 7822984e5..026507abf 100644 --- a/src/client/spark/view/Spark/Ladder/LadderView.xaml +++ b/src/client/spark/view/Spark/Ladder/LadderView.xaml @@ -27,6 +27,7 @@ + - + @@ -304,7 +304,7 @@ - - - - - - + +