From 0ae61d3e8240e82786bf55e25ae75a6bcb2ed7ff Mon Sep 17 00:00:00 2001 From: John Colvin Date: Wed, 13 Nov 2019 21:05:51 -0600 Subject: [PATCH] fix mview sorting (use new ColumnSortManager) --- .../Modules/Market/MarketView/MarketViewVM.cs | 20 ++++++------------- .../Market/MarketView/MarketViewWindow.cs | 20 ++++++++++++++----- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs b/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs index c2499198d..e097d706a 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs @@ -54,7 +54,7 @@ namespace mbts.spark { readonly Property _current_row; readonly DeferrableActionWrapper _refresh_filter; Func _filter; - IReadOnlyList<(Columns key, ListSortDirection direction)> _sorting_hierarchy; + IComparer _comparer; Color _selection_highlight; /// @@ -72,7 +72,6 @@ namespace mbts.spark { _bus = bus; _orders_model = orders_model; security_filter = new RegexFilterVM(r => r.security.ToString(), nameof(Row.security)); - comparer = DIYGridSortHelper.build_comparer(sorting_hierarchy, get_column_comparer, Columns.Security); // rows _wrapped_rows = _rows.WrapSelector(r => r.security_md, s => { var r = new Row(_bus, s, _orders_model); @@ -346,18 +345,6 @@ namespace mbts.spark { internal IBus bus => _bus; internal OrdersModel orders_model => _orders_model; - public IReadOnlyList<(Columns key, ListSortDirection direction)> sorting_hierarchy { - get => _sorting_hierarchy ?? (_sorting_hierarchy = Array.Empty<(Columns, ListSortDirection)>()); - set { - _sorting_hierarchy = value; - comparer = DIYGridSortHelper.build_comparer(value, get_column_comparer, Columns.SecurityKey); - DIYGridSortHelper.reset_sorting(columns, value); - _rows_view.CustomSort = comparer.to_non_generic(); - } - } - - public IComparer comparer { get; private set; } - public IDataGridColumnPersistentFilter security_filter { get; } public IDataGridColumnPersistentFilter bid_price_filter { get; } = new DoubleMinMax(r => r.bid_price, nameof(Row.bid_price)); public IDataGridColumnPersistentFilter bid_merged_size_filter { get; } = new UIntMinMax(r => r.bid_merged_size, nameof(Row.bid_merged_size)); @@ -426,6 +413,11 @@ namespace mbts.spark { Comparer.Default.wrap(selector); } + public IComparer comparer { + get => _comparer; + set => _rows_view.CustomSort = (_comparer = value)?.to_non_generic(); + } + public (FillsVM vm, string context, string title, Color fg) fills_params(IEnumerable securities, Columns column) { var (title_desc, fg) = _fills_title(column); var state = StartupData.DefaultAuxiliaryFills; diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewWindow.cs b/src/client/spark/Modules/Market/MarketView/MarketViewWindow.cs index 7743df201..c1807d4a1 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewWindow.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewWindow.cs @@ -10,6 +10,7 @@ using bts.view; using mbts.persist; using mbts.ui; +using mbts.ui.controls; using mbts.ui.settings; using mbts.ui.spark; using mbts.ui.utility; @@ -18,6 +19,7 @@ using mbts.utils; using System; using System.Collections.Generic; using System.Collections.Specialized; +using System.ComponentModel; using System.Linq; using System.Reactive.Disposables; using System.Reactive.Linq; @@ -37,6 +39,8 @@ namespace mbts.spark { readonly OrdersModel _orders_model; readonly AllowOnce _init_guard = new AllowOnce("MarketView"); readonly IWindowSettingsManager _settings_manager; + + List _current_sorting_criteria; MarketViewVM _vm; MarketViewView _view; MarketViewWindowFactory.StartupData _state; @@ -70,10 +74,7 @@ namespace mbts.spark { _state.security_criteria, _vm.get_filter_states(), _settings_manager.instance_settings, - _vm.sorting_hierarchy.Select(tup => new SortingCriteria(tup.key.ToString(), tup.direction == System.ComponentModel.ListSortDirection.Ascending)) - .ToList()) { - menu_display = _menu_display_vm.safe_create() - }; + _current_sorting_criteria); public override double MinWidth => MarketViewWindowFactory.StartupData.DefaultGridSettings.columns.Where(c => c.is_visible).Sum(gcs => gcs.width) + SPARK_MENU_COLLAPSED_WIDTH @@ -118,7 +119,11 @@ namespace mbts.spark { .Table(SecurityMD.key_fn) .Where(t => t.has_changes()) .OnDispatcher()); + var sort_man = new ColumnSortManager(_vm.columns, MarketViewView.Columns.Security.ToString()); + _current_sorting_criteria = _state.sorting_criterion.ToList(); + sort_man.SortingCriteria = _state.sorting_criterion; _vm.load_filters(_state.filters); + _vm.comparer = sort_man.BuildComparer(MarketViewVM.get_column_comparer); _view = new MarketViewView { DataContext = _vm }; _view._grid.Sorting += on_grid_sorting; _grid_settings_manager = new SimpleGridSettingsManager(_vm.columns, _col_settings_flags, _vm.rows); @@ -226,8 +231,13 @@ namespace mbts.spark { show_ticket_cmd.RaiseCanExecuteChanged(); } - void on_grid_sorting(object sender, ui.controls.DIYGridSortingEventArgs e) => + void on_grid_sorting(object sender, ui.controls.DIYGridSortingEventArgs e) { _sorted_selected_security_criteria_backing = null; + sort_man.OnColumnClick(e.Column, KeyboardExtensions.IsShiftDown()); + _vm.comparer = sort_man.BuildComparer(MarketViewVM.get_column_comparer); + _current_sorting_criteria = sort_man.SortingCriteria.ToList(); + e.Handled = true; + } } protected override void OnParentViewCreated(SparkWindowView parent_view) =>