SPARK-2208 / SPARK-2239 add a 'Revert' button to discard pending edits

This commit is contained in:
John Colvin committed 2019-04-07 15:17:39 -05:00
1 parent f6aa45168f
commit c8da0fb6c7
6 files changed
+46 -12

No files matched your search

@@ -298,6 +298,8 @@ namespace mbts.spark {
void IAlgoSelector.load_algo_data(IReadOnlyDictionary<AlgoKey, AlgoData> algo_data, AlgoKey? default_algo) =>
_load_algo_data(algo_data, default_algo);
void IAlgoParamVM.revert() { }
IObservable<IAlgoVM> IAlgoSelector.subscribe_selected_algo() =>
this.observe_algo_root();
#endregion
@@ -85,6 +85,8 @@ namespace mbts.spark {
expand_all_rows_command = new DelegateCommand(_row_collection.expand_all);
var modify_selected_orders_async_cmd = new AsyncCommand(_modify_selected_orders_async, () => _selected_params_mon.all_active);
modify_selected_orders_cmd = modify_selected_orders_async_cmd;
var revert_selected_orders_cmd = new DelegateCommand(revert_selected_orders, () => _selected_params_mon.all_active);
this.revert_selected_orders_cmd = revert_selected_orders_cmd;
var send_attached_orders_async_cmd = new AsyncCommand(send_attached_orders_async, () => _selected_params_mon.all_active);
send_attached_orders_cmd = send_attached_orders_async_cmd;
cancel_attach_orders_cmd = new DelegateCommand(() => is_attaching_orders = false);
@@ -174,9 +176,15 @@ namespace mbts.spark {
void on_all_selected_orders_active_changed(bool newval) {
order_mod_vm.algo_vm.editing_permissions_mask = newval ? AlgoEditingPermissions.AllowEditValues : AlgoEditingPermissions.None;
modify_selected_orders_async_cmd.RaiseCanExecuteChanged();
revert_selected_orders_cmd.RaiseCanExecuteChanged();
send_attached_orders_async_cmd.RaiseCanExecuteChanged();
}
void revert_selected_orders() {
foreach (var p in order_mod_vm.algo_vm.algo_root?.enumerate_all_params().empty_if_null())
p.revert();
}
async Task send_attached_orders_async() {
is_attaching_orders = false;
try {
@@ -266,6 +274,7 @@ namespace mbts.spark {
public ICommand collapse_all_rows_command { get; }
public ICommand expand_all_rows_command { get; }
public ICommand modify_selected_orders_cmd { get; }
public ICommand revert_selected_orders_cmd { get; }
public ICommand send_attached_orders_cmd { get; }
public ICommand cancel_attach_orders_cmd { get; }
public ICommand begin_attach_command { get; }
@@ -489,7 +489,7 @@
<CommandBinding Command="{x:Static usp:OrderParamsPanel.SetPriceCommand}" Executed="{x:Static usp:OrderParamsPanel.SetPriceExecuted}"/>
</usp:OrderParamsPanel.CommandBindings>
</usp:OrderParamsPanel>
<StackPanel Grid.Row="1" HorizontalAlignment="Right" Margin="0,8,0,0">
<StackPanel Grid.Row="1" HorizontalAlignment="Right" Margin="0,8,0,0" Orientation="Horizontal">
<Button x:Name="modify_orders_button" Command="{Binding modify_selected_orders_cmd}" ToolTip="Modify selected orders with the parameters above.">
<TextBlock>
<TextBlock.Style>
@@ -504,7 +504,12 @@
</TextBlock.Style>
</TextBlock>
</Button>
<!--TODO: Add Revert Button-->
<Button Command="{Binding revert_selected_orders_cmd}" ToolTip="Revert modifications to selected orders." Style="{StaticResource {x:Static c:DialogSkirt.DialogSkirtButtonStyleKey}}">
<Button.Margin>
<Thickness Left="{StaticResource DialogSkirtButtonPadding.Left}"/>
</Button.Margin>
Revert
</Button>
</StackPanel>
</Grid>
</Border>
@@ -9,6 +9,7 @@ using mbts.utils;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Threading.Tasks;
@@ -60,6 +61,7 @@ namespace mbts.spark {
bool is_enabled { get; set; }
bool is_dirty { get; }
AlgoParamPermissions permissions { get; set; }
void revert();
}
interface IAlgoParamVM<T> : IAlgoParamVM {
@@ -112,5 +114,8 @@ namespace mbts.spark {
return ObservableAutoWrapper.connect_item_hooks(selector.algos, vm =>
ObservableAutoWrapper.connect_item_hooks(vm.child_algo_selectors, s => load_algo_data_recursive(s, algo_data, default_algo)));
}
public static IEnumerable<IAlgoParamVM> enumerate_all_params(this IAlgoVM vm) =>
vm == null ? Enumerable.Empty<IAlgoParamVM>() : vm.algo_params.Concat(vm.child_algo_selectors.SelectMany(s => enumerate_all_params(s.selected_algo)));
}
}
}
@@ -931,6 +931,8 @@ namespace mbts.spark {
IReadOnlyObservableCollection<IAlgoParamVM> IAlgoParamVM.child_params => RXCollection.ReadOnly.Empty<IAlgoParamVM>();
// changing child algos is not allowed, so an algo selector is never dirty
bool IAlgoParamVM.is_dirty => false;
void IAlgoParamVM.revert() { }
#endregion
public IObservable<IAlgoVM> subscribe_selected_algo() {
@@ -1010,10 +1012,8 @@ namespace mbts.spark {
public T value {
get => _value;
set {
if (_set_value(value) && (is_dirty == _comparer.Equals(value, _committed_value))) {
is_dirty = !is_dirty;
RaisePropertyChanged(nameof(is_dirty));
}
if (_set_value(value) && (is_dirty == _comparer.Equals(value, _committed_value)))
_toggle_is_dirty();
}
}
public IReadOnlyObservableCollection<IAlgoParamVM> child_params { get; set; }
@@ -1022,6 +1022,14 @@ namespace mbts.spark {
public bool is_dirty { get; private set; }
object IAlgoParamVM.value { get => value; set => this.value = (T)value; }
public void revert() {
if (is_dirty) {
_value = _committed_value;
RaisePropertyChanged(nameof(value));
_toggle_is_dirty();
}
}
public IObservable<T> subscribe_value() {
return Observable.Create<T>(o => {
o.OnNext(_value);
@@ -1034,10 +1042,8 @@ namespace mbts.spark {
internal void mark_committed() {
_committed_value = _value;
if (is_dirty) {
is_dirty = false;
RaisePropertyChanged(nameof(is_dirty));
}
if (is_dirty)
_toggle_is_dirty();
}
bool _set_value(T new_value) {
@@ -1050,6 +1056,11 @@ namespace mbts.spark {
}
return false;
}
void _toggle_is_dirty() {
is_dirty = !is_dirty;
RaisePropertyChanged(nameof(is_dirty));
}
}
#endregion
}
@@ -12,7 +12,9 @@
<sys:Double x:Key="DialogSkirtPadding.Top">12</sys:Double>
<sys:Double x:Key="DialogSkirtPadding.Right">12</sys:Double>
<Thickness x:Key="DialogSkirtPadding" Left="{StaticResource DialogSkirtPadding.Left}" Top="{StaticResource DialogSkirtPadding.Top}" Right="{StaticResource DialogSkirtPadding.Right}" Bottom="10"/>
<Thickness x:Key="DialogSkirtButtonMargin" Left="4" Top="0" Right="4" Bottom="0"/>
<sys:Double x:Key="DialogSkirtButtonPadding.Left">4</sys:Double>
<sys:Double x:Key="DialogSkirtButtonPadding.Right">4</sys:Double>
<Thickness x:Key="DialogSkirtButtonMargin" Left="{StaticResource DialogSkirtButtonPadding.Left}" Top="0" Right="{StaticResource DialogSkirtButtonPadding.Right}" Bottom="0"/>
<Style x:Key="{x:Static c:DialogSkirt.DialogSkirtButtonStyleKey}" TargetType="Button" BasedOn="{StaticResource CommonButton}">
<Setter Property="Content" Value="{Binding name}"/>
<Setter Property="IsCancel" Value="{Binding is_cancel}"/>