From 148dae32d5698690a990509e40dc59683e2e5ae6 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Sun, 6 Oct 2019 17:41:02 -0500 Subject: [PATCH] AlgoStudio - remove algo name from buttons, dock save/revert on bottom --- .../Trading/AlgoStudio/AlgoStudioView.xaml | 35 ++++++++---- .../Trading/AlgoStudio/AlgoStudioWindow.cs | 55 +++++-------------- 2 files changed, 36 insertions(+), 54 deletions(-) diff --git a/src/client/spark/Modules/Trading/AlgoStudio/AlgoStudioView.xaml b/src/client/spark/Modules/Trading/AlgoStudio/AlgoStudioView.xaml index 4408388a0..ab49c0af7 100644 --- a/src/client/spark/Modules/Trading/AlgoStudio/AlgoStudioView.xaml +++ b/src/client/spark/Modules/Trading/AlgoStudio/AlgoStudioView.xaml @@ -153,8 +153,13 @@ + + + + - + @@ -429,19 +434,25 @@ Margin="0,6,0,0" Padding="12,8" /> - - - - - - - + + + + + + + + diff --git a/src/client/spark/Modules/Trading/AlgoStudio/AlgoStudioWindow.cs b/src/client/spark/Modules/Trading/AlgoStudio/AlgoStudioWindow.cs index 5d2b975e4..89061ceae 100644 --- a/src/client/spark/Modules/Trading/AlgoStudio/AlgoStudioWindow.cs +++ b/src/client/spark/Modules/Trading/AlgoStudio/AlgoStudioWindow.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.Linq; using System.Reactive.Disposables; using System.Reactive.Linq; +using System.Threading.Tasks; using System.Windows; using StartupData = bts.shell.AlgoStudioWindowFactory.StartupData; @@ -65,23 +66,12 @@ namespace mbts.spark { _resources = new CompositeDisposable(); // add definition _commands.Add(new SparkCommandCommand("Add Algo", Icons.AddBoxes, _vm.add_definition_cmd)); - // clone definition - var clone_selected_definition_spark_cmd = new SparkCommandCommand(string.Empty, Icons.DocumentCopy, _vm.clone_selected_definition_cmd); - _commands.Add(clone_selected_definition_spark_cmd); - _resources.Add(_vm.subscribe_definition().OnDispatcher().Subscribe( - def => clone_selected_definition_spark_cmd.title = def == null ? $"Clone (None Selected)" : $"Clone '{def.name}'")); - // save - if (_ui_configuration.can_save_specific) { - var content_is_dirty_src = _vm.subscribe_definition().SelectManyInSeries(def => def?.subscribe_is_definition_dirty() ?? Observable.Return(false)); - _commands.Add(new ReactiveSparkCommand(_vm.subscribe_definition().OnDispatcher().Select(c => $"Save '{c?.name}'"), Icons.DiskFile, () => { - if (_vm.selected_definition is AlgoDefinitionVM d) - _vm.save_definition(d).ignore(); - }, content_is_dirty_src)); - } - // save all - var save_all_cmd = new ObservantAsyncCommand(_vm.save_all); - _commands.Add(new SparkCommandCommand("Save All", Icons.Disk, save_all_cmd)); - _resources.Add(_vm.subscribe_dirty().OnDispatcher().Subscribe(save_all_cmd)); + _commands.Add(new SparkCommandCommand("Clone Algo", Icons.DocumentCopy, _vm.clone_selected_definition_cmd)); + _commands.Add(new SparkCommandCommand("Save Algo", Icons.DiskFile, _vm.save_cmd) { + show_in_toolbar = _ui_configuration.can_save_specific + }); + _commands.Add(new SparkCommandCommand("Save All", Icons.Disk, ObservantAsyncCommand.create(_vm.save_all, out var save_all_observer))); + _resources.Add(_vm.subscribe_dirty().OnDispatcher().Subscribe(save_all_observer)); // undo/redo if (_ui_configuration.can_undo_redo) { // undo @@ -114,30 +104,11 @@ namespace mbts.spark { _resources.Add(can_redo_source.Subscribe(redo_cmd)); } // remove - var remove_spark_cmd = new ObservantSparkCommandCommand(Icons.Trash, v => $"Remove '{v?.name}'", v => v != null, value => { - if (value is AlgoDefinitionVM d) { - string prompt; MessageBoxImage icon; - if (d.key.mode == AlgoKey.Mode.Persisted) { - prompt = $"Are you sure you want to delete '{d.name}?'"; - icon = MessageBoxImage.Question; - } else { - // algo hasn't even been created yet (just an unsaved placeholder item), no need to get user confirmation in this case. - prompt = null; - icon = default; - } - if (prompt != null) { - var resp = BTSMessageBox.Show(prompt, "Algo Studio", BTSMessageBoxButtons.Yes | BTSMessageBoxButtons.No, icon); - switch (resp) { - case BTSMessageBoxButtons.Yes: break; - case BTSMessageBoxButtons.No: - default: return; - } - } - _vm.remove_definition(d).ignore(); - } - }); - _commands.Add(remove_spark_cmd); - _resources.Add(_vm.subscribe_definition().OnDispatcher().Subscribe(remove_spark_cmd)); + _commands.Add(new SparkCommandCommand("Remove Algo", Icons.Trash, ObservantAsyncCommand.create( + vm => BTSMessageBox.Confirm($"Are you sure you want to delete '{vm.name}?'", Title) ? _vm.remove_definition(vm) : Task.CompletedTask, + vm => vm != null, + out var remove_cmd_observer))); + _resources.Add(_vm.subscribe_definition().OnDispatcher().Subscribe(remove_cmd_observer)); } void _dispose_core() { @@ -146,4 +117,4 @@ namespace mbts.spark { Disposable.dispose(ref _vm); } } -} \ No newline at end of file +}