SparkCommand needs a CanExecuteChanged event handler

This commit is contained in:
Eric Harding committed 2017-12-18 11:50:03 -05:00
1 parent 71413f6543
commit 079d6f125f
2 files changed
+37 -27

No files matched your search

@@ -41,10 +41,33 @@ namespace mbts.spark {
ITag<SecurityCriteria> _updated_security_criteria_tag = new SparkTags.SparkTag<SecurityCriteria>("TimeAndSales Callback");
_criteria_callback_command = SparkCommand.create("Update Time and Sales", SparkCommands.ShowTimeAndSales.icon, _updated_security_criteria_tag);
_subscriptions = Disposable.Create(
_bus.subscribe(_updated_security_criteria_tag).ObserveOnDispatcher().Subscribe(update_criteria),
_bus.subscribe(SparkTags.SecuritiesTag).Subscribe(md => _md = md));
Commands = new SparkCommand[] {
SparkCommand.create("Update Securities", Icons.Admin, SparkTags.ShowAndEditPickMultiple, () => (_criteria_callback_command, _state.security_criteria)),
// Ladder
SparkCommands.ShowLadder.complete(() => current_security.Value).conditional(() => current_security.HasValue),
SparkCommands.ShowLinkedLadder.complete(observe_security),
// OrderTicket
SparkCommands.ShowOrderTicket.complete(() => current_security.Value).conditional(() => current_security.HasValue),
SparkCommands.ShowLinkedOrderTicket.complete(/*todo*/),
// MarketView
SparkCommands.ShowMarketView.complete(() => new SecurityCriteria(selected_securities())).conditional(() => current_security.HasValue),
// SpreadMatrix ??
// SyntheticCreate
// SyntheticStrategy
SparkCommands.ShowSyntheticSpreads,
// ModifyOrder - await orders
// CancelOrdersRoot ?
// CancelBuyOrders
SparkCommands.CancelBuyOrders,
// CancelSellOrders
SparkCommands.CancelSellOrders,
// CancelOrders
SparkCommands.CancelOrders
};
}
public async Task initialize(TimeAndSalesStartupData state) {
@@ -89,35 +112,14 @@ namespace mbts.spark {
return _vm.selected_security.Select(s => _md[s.Id]);
}
public override IEnumerable<SparkCommand> Commands => new SparkCommand[] {
SparkCommand.create("Update Securities", Icons.Admin, SparkTags.ShowAndEditPickMultiple, () => (_criteria_callback_command, _state.security_criteria)),
// Ladder
SparkCommands.ShowLadder.complete(() => current_security.Value).conditional(() => current_security.HasValue),
SparkCommands.ShowLinkedLadder.complete(observe_security),
// OrderTicket
SparkCommands.ShowOrderTicket.complete(() => current_security.Value).conditional(() => current_security.HasValue),
SparkCommands.ShowLinkedOrderTicket.complete(/*todo*/),
// MarketView
SparkCommands.ShowMarketView.complete(() => new SecurityCriteria(selected_securities())).conditional(() => current_security.HasValue),
// SpreadMatrix ??
// SyntheticCreate
// SyntheticStrategy
SparkCommands.ShowSyntheticSpreads,
// ModifyOrder - await orders
// CancelOrdersRoot ?
// CancelBuyOrders
SparkCommands.CancelBuyOrders,
// CancelSellOrders
SparkCommands.CancelSellOrders,
// CancelOrders
SparkCommands.CancelOrders
};
public override IEnumerable<SparkCommand> Commands { get; }
List<SortingCriteria> get_sorting_critera() {
return _vm.rows_view.SortDescriptions.Select(sd => new SortingCriteria(sd)).ToList();
}
public override TimeAndSalesStartupData SaveState { get {
public override TimeAndSalesStartupData SaveState {
get {
_state = new TimeAndSalesStartupData(
_state.security_criteria,
get_sorting_critera());
+10 -2
View File
@@ -23,6 +23,10 @@ namespace bts.spark {
public abstract void execute(IBus bus);
public virtual bool canExecute() { return true; }
public virtual void raiseCanExecuteChanged() {
CanExecuteChanged?.Invoke(this, null);
}
public event EventHandler CanExecuteChanged;
public static PartialCommand<T> create<T>(string title, ImageSource icon, ITag<T> tag) {
return new PartialCommand<T>(title, icon, tag);
@@ -97,6 +101,11 @@ namespace bts.spark {
public override bool canExecute() {
return _can_execute?.Invoke() ?? base.canExecute();
}
public override void raiseCanExecuteChanged() {
if (_can_execute != null) {
base.raiseCanExecuteChanged();
}
}
public SparkCommand<T> conditional(Func<bool> can_execute) {
return new SparkCommand<T>(title, icon, tag, _get_parameter, can_execute);
@@ -130,8 +139,7 @@ namespace bts.spark {
public string title => _cmd.title;
public ImageSource icon => _cmd.icon;
public ICommand command => this;
event EventHandler ICommand.CanExecuteChanged { add {} remove {} }
event EventHandler ICommand.CanExecuteChanged { add { _cmd.CanExecuteChanged += value; } remove { _cmd.CanExecuteChanged -= value; } }
bool ICommand.CanExecute(object parameter) => _cmd.canExecute();
async void ICommand.Execute(object parameter) {