refactor: Use ToggleCommand/SparkMenuItemToggleModel in slide win
This commit is contained in:
1 parent
526daa9647
commit
8fa2a925cd
4 files changed
+45
-33
No files matched your search
@@ -140,7 +140,7 @@ namespace mbts.spark {
|
||||
DataContext = vm
|
||||
};
|
||||
WindowUtilities.connect_vm(win, vm);
|
||||
vm.commit_cmd.executed += commit;
|
||||
vm.ok_cmd.executed += commit;
|
||||
win.move_to_mouse(-100, -200);
|
||||
win.Show();
|
||||
|
||||
|
||||
@@ -30,7 +30,8 @@ namespace mbts.analytics {
|
||||
var (greeks, price_display) = grid_vm.result;
|
||||
return (greeks, price_display, configuration_vm.result);
|
||||
});
|
||||
commit_cmd = new(_ => !grid_vm.HasErrors && !configuration_vm.HasErrors);
|
||||
apply_cmd = new(_ => can_commit());
|
||||
ok_cmd = new(_ => can_commit());
|
||||
_dispose = Disposable.Create(
|
||||
volsurfaces_src.Subscribe(volsurfaces => {
|
||||
configuration_vm.vol_surface_selector.update_items(
|
||||
@@ -42,14 +43,19 @@ namespace mbts.analytics {
|
||||
grid_vm.observe_result().Subscribe(_ => _result.refresh()),
|
||||
configuration_vm.observe_result().Subscribe(_ => _result.refresh()));
|
||||
|
||||
void on_errors_changed(object sender, DataErrorsChangedEventArgs e) =>
|
||||
commit_cmd.RaiseCanExecuteChanged();
|
||||
bool can_commit() => !grid_vm.HasErrors && !configuration_vm.HasErrors ;
|
||||
|
||||
void on_errors_changed(object sender, DataErrorsChangedEventArgs e) {
|
||||
apply_cmd.RaiseCanExecuteChanged();
|
||||
ok_cmd.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public SlideReportGridSettingsVM grid_vm { get; } = new();
|
||||
public SlideReportConfigurationVM configuration_vm { get; } = new();
|
||||
public (GreekDisplay[], PriceDisplayFactors, ReportImmutable) result => _result.Value;
|
||||
|
||||
public EventCommand<(GreekDisplay[], PriceDisplayFactors, ReportImmutable)> commit_cmd { get; } = new();
|
||||
public EventCommand<(GreekDisplay[], PriceDisplayFactors, ReportImmutable)> apply_cmd { get; }
|
||||
public EventCommand<(GreekDisplay[], PriceDisplayFactors, ReportImmutable)> ok_cmd { get; }
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,6 @@ namespace mbts.analytics {
|
||||
readonly SlideDataModel _model;
|
||||
readonly GreekDisplayModel _greeks_display_model = new();
|
||||
readonly Property<SlideViewFormat> _view_format;
|
||||
readonly Property<bool> _use_candidate_values;
|
||||
|
||||
PriceDisplayFactors _price_display = new();
|
||||
SlideFullData _data = SlideFullData.empty();
|
||||
@@ -46,11 +45,14 @@ namespace mbts.analytics {
|
||||
|
||||
public SlideReportVM(SlideReportSettings startup_data, IBus bus) {
|
||||
_view_format = backing<SlideViewFormat>(nameof(view_format));
|
||||
_use_candidate_values = backing<bool>(nameof(use_candidate_values));
|
||||
show_upper_status_bar = startup_data.show_upper_status_bar;
|
||||
|
||||
var resources = new DisposableCombo(included_exps.Subscribe((s, e) => _set_ui_overrides()));
|
||||
_model = new SlideDataModel(startup_data.id, bus);
|
||||
resources += toggle_use_candidate_values_cmd.subscribe(_ => {
|
||||
_set_ui_overrides();
|
||||
RaisePropertyChanged(nameof(use_candidate_values));
|
||||
});
|
||||
resources += toggle_show_upper_status_bar_cmd.bind(this, nameof(show_upper_status_bar));
|
||||
resources += ObservableAutoWrapper.connect(_handles, columns, mk_col);
|
||||
resources += _view_format.Subscribe(_ => _sync_grid());
|
||||
@@ -112,7 +114,11 @@ namespace mbts.analytics {
|
||||
var win = new SlideReportSettingsDialog {
|
||||
DataContext = vm
|
||||
};
|
||||
vm.SubscribeDisposed(vm.commit_cmd.subscribe_executed(commit));
|
||||
vm.SubscribeDisposed(vm.ok_cmd.subscribe_executed(res => {
|
||||
commit(res);
|
||||
WindowUtilities.force_close(win);
|
||||
}));
|
||||
vm.SubscribeDisposed(vm.apply_cmd.subscribe_executed(commit));
|
||||
return win;
|
||||
|
||||
void commit((GreekDisplay[], PriceDisplayFactors, ReportImmutable) result) {
|
||||
@@ -142,12 +148,16 @@ namespace mbts.analytics {
|
||||
public ObservableCollection<SlideGridRow> sum_rows { get; } = new();
|
||||
public ObservableCollection<SecurityExpiration> expirations { get; } = new();
|
||||
public ObservableCollection<SecurityExpiration> included_exps { get; } = new();
|
||||
|
||||
public SlideViewFormat view_format {
|
||||
get => _view_format.Value;
|
||||
set => _view_format.set_new(value);
|
||||
get => show_expanded_view ? SlideViewFormat.Expanded : SlideViewFormat.Collapsed;
|
||||
set => show_expanded_view = value == SlideViewFormat.Expanded;
|
||||
}
|
||||
|
||||
public bool show_expanded_view {
|
||||
get => toggle_show_expanded_cmd.is_selected;
|
||||
set => toggle_show_expanded_cmd.is_selected = value;
|
||||
}
|
||||
public IObservable<SlideViewFormat> view_format_observable =>
|
||||
_view_format.observe_current(true);
|
||||
|
||||
public bool show_upper_status_bar {
|
||||
get => toggle_show_upper_status_bar_cmd.is_selected;
|
||||
@@ -205,15 +215,9 @@ namespace mbts.analytics {
|
||||
}
|
||||
|
||||
public bool use_candidate_values {
|
||||
get => _use_candidate_values.Value;
|
||||
set {
|
||||
if (_use_candidate_values.set_new(value)) {
|
||||
_set_ui_overrides();
|
||||
}
|
||||
}
|
||||
get => toggle_use_candidate_values_cmd.is_selected;
|
||||
set => toggle_use_candidate_values_cmd.is_selected = value;
|
||||
}
|
||||
public IObservable<bool> use_candidate_values_observable =>
|
||||
_use_candidate_values.observe_current(true);
|
||||
|
||||
public bool position_overrides_active => _data.ui_override?.is_positition_overridden ?? false;
|
||||
public bool scenario_overrides_active => _data.ui_override?.is_value_overridden ?? false;
|
||||
@@ -232,6 +236,8 @@ namespace mbts.analytics {
|
||||
public ICommand compute => new Command(_model.calculate);
|
||||
public ICommand time_shift_value_tick_up => new Command(() => time_shift += 0.25);
|
||||
public ICommand time_shift_value_tick_down => new Command(() => time_shift -= 0.25);
|
||||
public IToggleCommand toggle_use_candidate_values_cmd { get; } = new ToggleCommand();
|
||||
public IToggleCommand toggle_show_expanded_cmd { get; } = new ToggleCommand();
|
||||
public IToggleCommand toggle_show_upper_status_bar_cmd { get; } = new ToggleCommand();
|
||||
public IDialogCommand launch_settings_editor_cmd { get; }
|
||||
|
||||
|
||||
@@ -85,22 +85,22 @@ namespace mbts.analytics {
|
||||
DataContext = _vm
|
||||
};
|
||||
|
||||
SparkCommandCommand mk_toggle_use_canidate_vol_cmd() {
|
||||
var cmd = new Command(() => _vm.use_candidate_values = !_vm.use_candidate_values);
|
||||
var spark_cmd = new SparkCommandCommand("Use Candidate Vol", null, cmd);
|
||||
_vm.SubscribeDisposed(_vm.use_candidate_values_observable.Subscribe(
|
||||
ucv => spark_cmd.icon = ucv ? Icons.candidate_checked : Icons.candidate_unchecked));
|
||||
SparkMenuItemToggleModel mk_toggle_use_canidate_vol_cmd() {
|
||||
var spark_cmd = new SparkMenuItemToggleModel(
|
||||
"Use Candidate Vol", cmd: _vm.toggle_use_candidate_values_cmd);
|
||||
_vm.SubscribeDisposed(_vm.toggle_use_candidate_values_cmd.subscribe(
|
||||
ucv => spark_cmd.icon = ucv ? Icons.candidate_checked : Icons.candidate_unchecked,
|
||||
true));
|
||||
return spark_cmd;
|
||||
}
|
||||
|
||||
SparkCommandCommand mk_toggle_expanded_cmd() {
|
||||
var cmd = new Command(() => _vm.view_format = _vm.view_format.toggle());
|
||||
var spark_cmd = new SparkCommandCommand(null, null, cmd);
|
||||
_vm.SubscribeDisposed(_vm.view_format_observable.Subscribe(
|
||||
vf => (spark_cmd.title, spark_cmd.icon) = vf switch {
|
||||
SlideViewFormat.Collapsed => ("Expand", Icons.ChevronDown),
|
||||
_ => ("Collapse", Icons.ChevronRight),
|
||||
}));
|
||||
SparkMenuItemToggleModel mk_toggle_expanded_cmd() {
|
||||
var spark_cmd = new SparkMenuItemToggleModel(
|
||||
null, null, cmd: _vm.toggle_show_expanded_cmd);
|
||||
_vm.SubscribeDisposed(_vm.toggle_show_expanded_cmd.subscribe(
|
||||
v => (spark_cmd.title, spark_cmd.icon) = v ?
|
||||
("Expand", Icons.ChevronDown) : ("Collapse", Icons.ChevronRight),
|
||||
true));
|
||||
return spark_cmd;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user