diff --git a/src/client/spark/AW2/ViewModel/Grid/VolSurfaceSimplifiedGridVM.cs b/src/client/spark/AW2/ViewModel/Grid/VolSurfaceSimplifiedGridVM.cs index ed8985076..705a94fc7 100644 --- a/src/client/spark/AW2/ViewModel/Grid/VolSurfaceSimplifiedGridVM.cs +++ b/src/client/spark/AW2/ViewModel/Grid/VolSurfaceSimplifiedGridVM.cs @@ -178,25 +178,11 @@ namespace mbts.spark.VolSurface { public ObservableCollection rows { get; } = new(); public ObservableCollection visible_rows { get; } = new(); - public bool any_masters_selected { get { return selected_rows.Any(r => !r.expiration.is_slave); } } + public bool any_masters_selected => + selected_rows.select_display_exp().where_master().Any(); - public IEnumerable selected_rows { - get { - return visible_rows - .OfType() - .Where(r => r.is_selected); - } - } - - IEnumerable typed_visible_rows => visible_rows.Cast(); - IEnumerable selected_expirations => selected_rows.Select(r => r.expiration); - IEnumerable master_expirations => model.get_active_grid().get_ordered_expirations().Where(e => !e.is_slave); - IEnumerable all_expirations => model.get_active_grid().get_ordered_expirations(); - - public ICommand main_settings_command { get { return _parent.main_settings_command; } } - public ICommand advanced_settings_command { get { return _parent.advanced_settings_command; } } - public ICommand graph_settings_command { get { return _parent.vol_curve_vm.settings_command; } } - public ICommand grid_settings_command { get { return _parent.grid_settings_command; } } + public IEnumerable selected_rows => + visible_rows.where_selected(); public IEnumerable super_headers => // There are no superheaders over frozen columns (currently) @@ -213,6 +199,9 @@ namespace mbts.spark.VolSurface { _on_grid_updated(); } + public IEnumerable get_hidden_expirations() => + rows.select_exp().Except(visible_rows.select_exp()); + internal void signal_selection_changed() { var e = on_selection_changed; if (e != null) { @@ -222,30 +211,32 @@ namespace mbts.spark.VolSurface { } internal void shift_selection(VolSurfaceDisplayGridTextInputColumn column) => - _launch_shift_editor(column, shift => _shift(column, selected_expirations, shift)); + _launch_shift_editor(column, shift => _shift(column, selected_rows.select_display_exp(), shift)); internal void shift_masters(VolSurfaceDisplayGridTextInputColumn column) => - _launch_shift_editor(column, shift => _shift(column, master_expirations, shift)); + _launch_shift_editor(column, shift => _shift(column, _expirations.where_master(), shift)); internal void shift_all(VolSurfaceDisplayGridTextInputColumn column) => - _launch_shift_editor(column, shift => _shift(column, all_expirations, shift)); + _launch_shift_editor(column, shift => _shift(column, _expirations, shift)); internal void clear(VolSurfaceDisplayGridColumn col, GridColumnSet where) { switch (where) { case GridColumnSet.Column: - foreach (VolSurfaceDisplayGridExpiration exp in selected_expirations) { + foreach (var exp in selected_rows.select_display_exp()) { _clear(exp, col); } _commit(); break; case GridColumnSet.Group: - foreach (VolSurfaceDisplayGridExpiration exp in selected_expirations) { - foreach (var c in _internal_columns.Where(c => c.group == col.group)) _clear(exp, c); + foreach (var exp in selected_rows.select_display_exp()) { + foreach (var c in _internal_columns.Where(c => c.group == col.group)) { + _clear(exp, c); + } } _commit(); break; case GridColumnSet.All: - foreach (VolSurfaceDisplayGridExpiration exp in selected_expirations) { + foreach (var exp in selected_rows.select_display_exp()) { foreach (var c in _internal_columns) _clear(exp, c); } _commit(); @@ -257,19 +248,19 @@ namespace mbts.spark.VolSurface { internal void copy_to_selection(VolSurfaceDisplayGridExpiration exp, VolSurfaceDisplayGridColumn column, GridColumnSet set) { if (column is VolSurfaceDisplayGridTextColumn input_col) { - _replicate(exp, selected_expirations.Except(new[] { exp }), _get_columns(input_col, set)); + _replicate(exp, selected_rows.select_display_exp().Except(exp), _get_columns(input_col, set)); } } internal void copy_to_masters(VolSurfaceDisplayGridExpiration exp, VolSurfaceDisplayGridColumn column, GridColumnSet set) { if (column is VolSurfaceDisplayGridTextColumn input_col) { - _replicate(exp, master_expirations.Except(new[] { exp }), _get_columns(input_col, set)); + _replicate(exp, _expirations.where_master().Except(exp), _get_columns(input_col, set)); } } internal void copy_to_all(VolSurfaceDisplayGridExpiration exp, VolSurfaceDisplayGridColumn column, GridColumnSet set) { if (column is VolSurfaceDisplayGridTextColumn input_col) { - _replicate(exp, all_expirations.Except(new[] { exp }), _get_columns(input_col, set)); + _replicate(exp, _expirations.Except(exp), _get_columns(input_col, set)); } } @@ -390,10 +381,5 @@ namespace mbts.spark.VolSurface { void _commit() => model.set_candidate_grid(current_grid); - - public List get_hidden_expirations() { - var visible_exps = new HashSet(typed_visible_rows.Select(rc => rc.expiration)); - return rows.Where(r => !visible_exps.Contains(r.expiration)).Select(r => r.expiration.ToVSExp()).ToList(); - } } } diff --git a/src/client/spark/AW2/VolSurfaceExtensions.cs b/src/client/spark/AW2/VolSurfaceExtensions.cs index 8d04cbbc7..cebc3146c 100644 --- a/src/client/spark/AW2/VolSurfaceExtensions.cs +++ b/src/client/spark/AW2/VolSurfaceExtensions.cs @@ -1,8 +1,9 @@ - -namespace mbts.spark { +namespace mbts.spark { using bts.api; using bts.api.analytics; + using mbts.analytics; + using mbts.spark.VolSurface; using mbts.ui.controls; using System.Collections.Generic; @@ -66,5 +67,17 @@ namespace mbts.spark { VolSurfaceGraphSeriesType.ImpliedVolCalls => true, _ => false, }; + + public static IEnumerable select_exp(this IEnumerable rows) => + rows.Select(r => r.expiration.ToVSExp()); + + public static IEnumerable select_display_exp(this IEnumerable rows) => + rows.Select(r => r.expiration); + + public static IEnumerable where_master(this IEnumerable rows) => + rows.Where(r => !r.is_slave); + + public static IEnumerable where_slave(this IEnumerable rows) => + rows.Where(r => !r.is_slave); } } diff --git a/src/client/spark/view/Utility/ISelectable.cs b/src/client/spark/view/Utility/ISelectable.cs index cfde501f1..6aa8250d1 100644 --- a/src/client/spark/view/Utility/ISelectable.cs +++ b/src/client/spark/view/Utility/ISelectable.cs @@ -1,8 +1,15 @@ using System; +using System.Collections.Generic; +using System.Linq; namespace mbts.ui { public interface ISelectable { event Action is_selected_changed; bool is_selected { get; set; } } + + static class ISelectableExtensions { + public static IEnumerable where_selected(this IEnumerable source) where T : ISelectable => + source.Where(s => s.is_selected); + } }