From 1dbba9713dde8588ee2522854eb8de2a5b8b06ca Mon Sep 17 00:00:00 2001 From: John Colvin Date: Thu, 14 Feb 2019 15:01:37 -0600 Subject: [PATCH] ladder - hook up algotoolbar button visibility to ui.proto config --- .../Trading/AlgoStudio/AlgoStudioWindow.cs | 8 +- .../AlgoStudio/Model/IAlgoStudioModel.cs | 6 +- .../Modules/Trading/LadderWindowFactory.cs | 6 +- .../spark/Orders/OrderPropertiesEditorVM.cs | 4 +- .../Controls/Order/AlgoTemplateToolBar.xaml | 51 +++-- .../Order/AlgoTemplateToolBar.xaml.cs | 186 ++++++++++++------ .../Order/OrderDetailsPopupControl.xaml | 10 +- src/lib/config/protos/UI.proto | 6 +- 8 files changed, 167 insertions(+), 110 deletions(-) diff --git a/src/client/spark/Modules/Trading/AlgoStudio/AlgoStudioWindow.cs b/src/client/spark/Modules/Trading/AlgoStudio/AlgoStudioWindow.cs index 8a3152a30..c860668f8 100644 --- a/src/client/spark/Modules/Trading/AlgoStudio/AlgoStudioWindow.cs +++ b/src/client/spark/Modules/Trading/AlgoStudio/AlgoStudioWindow.cs @@ -16,9 +16,11 @@ namespace mbts.spark { internal class AlgoStudioWindow : SparkWindow, IShellWindow { public const string NAME = "Algo Studio", - CanModifyDefinitionNameKey = nameof(CanModifyDefinitionNameKey), - CanModifyDefinitionValuesKey = nameof(CanModifyDefinitionValuesKey), - TemplatesEnabledKey = nameof(TemplatesEnabledKey); + TemplatesEnabledKey = nameof(TemplatesEnabledKey), + ShowAlgoToolBarSaveDefinitionKey = nameof(ShowAlgoToolBarSaveDefinitionKey), + ShowAlgoToolBarRenameDefinitionKey = nameof(ShowAlgoToolBarRenameDefinitionKey), + ShowAlgoToolBarRevertDefinitionKey = nameof(ShowAlgoToolBarRevertDefinitionKey), + ShowAlgoToolBarUndoRedoDefinitionKey = nameof(ShowAlgoToolBarUndoRedoDefinitionKey); const double DEFAULT_CONTENT_WIDTH = 550.2, diff --git a/src/client/spark/Modules/Trading/AlgoStudio/Model/IAlgoStudioModel.cs b/src/client/spark/Modules/Trading/AlgoStudio/Model/IAlgoStudioModel.cs index 7761e61ba..0a73516b0 100644 --- a/src/client/spark/Modules/Trading/AlgoStudio/Model/IAlgoStudioModel.cs +++ b/src/client/spark/Modules/Trading/AlgoStudio/Model/IAlgoStudioModel.cs @@ -42,8 +42,10 @@ namespace mbts.spark { public static IReadOnlyDictionary get_dynamic_resources(bts.config.AlgoStudioOptions ui_configuration) => new Dictionary { - { AlgoStudioWindow.CanModifyDefinitionNameKey, ui_configuration.can_modify_definition_name }, - { AlgoStudioWindow.CanModifyDefinitionValuesKey, ui_configuration.can_modify_definition_values }, + { AlgoStudioWindow.ShowAlgoToolBarRenameDefinitionKey, ui_configuration.can_modify_definition_name && ui_configuration.show_algo_toolbar_rename }, + { AlgoStudioWindow.ShowAlgoToolBarSaveDefinitionKey, ui_configuration.can_modify_definition_values && ui_configuration.show_algo_toolbar_save }, + { AlgoStudioWindow.ShowAlgoToolBarRevertDefinitionKey, ui_configuration.show_algo_toolbar_revert }, + { AlgoStudioWindow.ShowAlgoToolBarUndoRedoDefinitionKey, ui_configuration.show_algo_toolbar_undo_redo }, { AlgoStudioWindow.TemplatesEnabledKey, get_templates_enabled(ui_configuration) } }; } diff --git a/src/client/spark/Modules/Trading/LadderWindowFactory.cs b/src/client/spark/Modules/Trading/LadderWindowFactory.cs index bbff4e5c0..0cf81e9e1 100644 --- a/src/client/spark/Modules/Trading/LadderWindowFactory.cs +++ b/src/client/spark/Modules/Trading/LadderWindowFactory.cs @@ -65,8 +65,6 @@ namespace bts.shell { init.use_defaults |= state_settings == null; var vm = new LadderVM(_bus, model, settings_manager, init); vm.order_properties_vm.open_algo_popup_on_select = _ladder_conf.open_algo_popup_on_select; - vm.order_properties_vm.show_algo_popup_undo_redo_buttons = _ladder_conf.show_algo_popup_undo_redo_buttons; - vm.order_properties_vm.show_revert_definition_button = _ladder_conf.show_revert_definition_button; var lv = new LadderView(vm); foreach (var kv in AlgoStudioModelUtils.get_dynamic_resources(vm.model.order_gateway.algo_model.ui_configuration)) lv.Resources[kv.Key] = kv.Value; @@ -141,14 +139,12 @@ namespace bts.shell { readonly struct LadderConfig { public readonly uint max_open_ladders; - public readonly bool ladders_on_threads, open_algo_popup_on_select, show_algo_popup_undo_redo_buttons, show_revert_definition_button; + public readonly bool ladders_on_threads, open_algo_popup_on_select; public readonly TimeSpan security_timeout; public LadderConfig(bts.config.LadderKnobs knobs, bool ladders_on_threads) { max_open_ladders = knobs.max_open_ladders; open_algo_popup_on_select = knobs.open_algo_popup_on_select; - show_algo_popup_undo_redo_buttons = knobs.show_algo_popup_undo_redo_buttons; - show_revert_definition_button = knobs.show_revert_definition_button; security_timeout = TimeSpan.FromSeconds(Math.Max(15, knobs.security_timeout_secs)); this.ladders_on_threads = ladders_on_threads; } diff --git a/src/client/spark/Orders/OrderPropertiesEditorVM.cs b/src/client/spark/Orders/OrderPropertiesEditorVM.cs index dec47a311..6699924a5 100644 --- a/src/client/spark/Orders/OrderPropertiesEditorVM.cs +++ b/src/client/spark/Orders/OrderPropertiesEditorVM.cs @@ -65,7 +65,7 @@ namespace mbts.spark { IReadOnlyDictionary _algo_metadata = DictionaryHelper.empty(); IReadOnlyDictionary _favorite_algos_index = DictionaryHelper.empty(); int _favorite_algos_column_count; - bool _open_algo_popup_on_select, _show_algo_popup_undo_redo_buttons, _show_revert_definition_button; + bool _open_algo_popup_on_select; public OrderPropertiesEditorVM(OrdersModel model, IObservable security_md_source, IObservable order_properties) { _model = model; @@ -317,8 +317,6 @@ namespace mbts.spark { } } public bool open_algo_popup_on_select { get => _open_algo_popup_on_select; set => Set(ref _open_algo_popup_on_select, value); } - public bool show_algo_popup_undo_redo_buttons { get => _show_algo_popup_undo_redo_buttons; set => Set(ref _show_algo_popup_undo_redo_buttons, value); } - public bool show_revert_definition_button { get => _show_revert_definition_button; set => Set(ref _show_revert_definition_button, value); } // commands public ICommand save_definition_cmd { get; } public ICommand save_template_cmd { get; } diff --git a/src/client/spark/view/Controls/Order/AlgoTemplateToolBar.xaml b/src/client/spark/view/Controls/Order/AlgoTemplateToolBar.xaml index 2402ad02e..ea5f8bebe 100644 --- a/src/client/spark/view/Controls/Order/AlgoTemplateToolBar.xaml +++ b/src/client/spark/view/Controls/Order/AlgoTemplateToolBar.xaml @@ -21,6 +21,7 @@ - - - + + + @@ -47,9 +48,9 @@ - - - + + + @@ -57,9 +58,9 @@ - - - + + + @@ -67,25 +68,19 @@ - - - + + + - - - - - - - - - + + + @@ -93,9 +88,9 @@ - - - + + + @@ -103,9 +98,9 @@ - - - + + + @@ -300,7 +295,7 @@ - + DefaultStyleKeyProperty.OverrideMetadata(typeof(AlgoTemplateToolBar), new FrameworkPropertyMetadata(typeof(AlgoTemplateToolBar))); + readonly VisualStateModel _vsm = new VisualStateModel(); + + public AlgoTemplateToolBar() { + StateManager.SetVisualStateCollection(this, _vsm.states); + VisualStateNames.apply_all(this); + } + #region ShowTemplatesDropDown public static readonly DependencyProperty ShowTemplatesDropDownProperty = WPFHelper.create_dp( nameof(ShowTemplatesDropDown), - (o, v) => VisualStates.goto_templates_dropdown_state(o)); + (o, v) => { + string dropdown_state, rename_state; + if (v) { + dropdown_state = VisualStateNames.TemplatesDropDown.Active; + rename_state = VisualStateNames.RenameTemplate.Active; + } else { + dropdown_state = VisualStateNames.TemplatesDropDown.Inactive; + rename_state = VisualStateNames.RenameTemplate.Inactive; + } + o._vsm.set_state(VisualStateNames.TemplatesDropDown.GroupName, dropdown_state); + o._vsm.set_state(VisualStateNames.RenameTemplate.GroupName, rename_state); + }, + coerce_require_persisted); + public bool ShowTemplatesDropDown { get => (bool)GetValue(ShowTemplatesDropDownProperty); set => SetValue(ShowTemplatesDropDownProperty, value); } #endregion @@ -77,7 +98,9 @@ namespace mbts.ui.spark.algo { public static readonly DependencyProperty ShowToggleFavoriteProperty = WPFHelper.create_dp( nameof(ShowToggleFavorite), - (o, v) => VisualStates.goto_toggle_favorite_button_state(o)); + (o, v) => VisualStateNames.ToggleFavorite.apply(o._vsm, v), + coerce_require_persisted); + public bool ShowToggleFavorite { get => (bool)GetValue(ShowToggleFavoriteProperty); set => SetValue(ShowToggleFavoriteProperty, value); } #endregion @@ -91,7 +114,9 @@ namespace mbts.ui.spark.algo { public static readonly DependencyProperty ShowUndoRedoButtonsProperty = WPFHelper.create_dp( nameof(ShowUndoRedoButtons), - (o, v) => VisualStates.goto_undo_redo_buttons_state(o)); + (o, v) => VisualStateNames.UndoRedo.apply(o._vsm, v), + coerce_require_persisted); + public bool ShowUndoRedoButtons { get => (bool)GetValue(ShowUndoRedoButtonsProperty); set => SetValue(ShowUndoRedoButtonsProperty, value); } #endregion @@ -99,29 +124,42 @@ namespace mbts.ui.spark.algo { public static readonly DependencyProperty ShowRevertDefinitionProperty = WPFHelper.create_dp( nameof(ShowRevertDefinition), - (o, v) => VisualStates.goto_revert_definition_button_state(o)); + (o, v) => VisualStateNames.RevertDefinition.apply(o._vsm, v), + coerce_require_persisted); + public bool ShowRevertDefinition { get => (bool)GetValue(ShowRevertDefinitionProperty); set => SetValue(ShowRevertDefinitionProperty, value); } #endregion - #region CanUserModifyDefinitionName - public static readonly DependencyProperty CanUserModifyDefinitionNameProperty = + #region ShowRenameDefinition + public static readonly DependencyProperty ShowRenameDefinitionProperty = WPFHelper.create_dp( - nameof(CanUserModifyDefinitionName), - (o, v) => VisualStates.goto_definition_name_editing_state(o)); - public bool CanUserModifyDefinitionName { get => (bool)GetValue(CanUserModifyDefinitionNameProperty); set => SetValue(CanUserModifyDefinitionNameProperty, value); } + nameof(ShowRenameDefinition), + (o, v) => VisualStateNames.RenameDefinition.apply(o._vsm, v), + coerce_require_persisted); + + public bool ShowRenameDefinition { get => (bool)GetValue(ShowRenameDefinitionProperty); set => SetValue(ShowRenameDefinitionProperty, value); } #endregion - #region CanUserModifyDefinitionValues - public static readonly DependencyProperty CanUserModifyDefinitionValuesProperty = + #region ShowSaveDefinition + public static readonly DependencyProperty ShowSaveDefinitionProperty = WPFHelper.create_dp( - nameof(CanUserModifyDefinitionValues), - (o, v) => VisualStates.goto_definition_values_editing_state(o)); - public bool CanUserModifyDefinitionValues { get => (bool)GetValue(CanUserModifyDefinitionValuesProperty); set => SetValue(CanUserModifyDefinitionValuesProperty, value); } + nameof(ShowSaveDefinition), + (o, v) => VisualStateNames.SaveDefinition.apply(o._vsm, v), + coerce_require_persisted); + + public bool ShowSaveDefinition { get => (bool)GetValue(ShowSaveDefinitionProperty); set => SetValue(ShowSaveDefinitionProperty, value); } #endregion #region Definition public static readonly DependencyProperty DefinitionProperty = - WPFHelper.create_dp(nameof(Definition)); + WPFHelper.create_dp(nameof(Definition), + (o, v) => { + o.CoerceValue(ShowRenameDefinitionProperty); + o.CoerceValue(ShowSaveDefinitionProperty); + o.CoerceValue(ShowRevertDefinitionProperty); + o.CoerceValue(ShowUndoRedoButtonsProperty); + }); + public AlgoDefinitionVM Definition { get => GetValue(DefinitionProperty) as AlgoDefinitionVM; set => SetValue(DefinitionProperty, value); } #endregion @@ -283,7 +321,6 @@ namespace mbts.ui.spark.algo { break; } })); - VisualStates.goto_all_states(this); } protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e) { @@ -291,6 +328,9 @@ namespace mbts.ui.spark.algo { _editable_items = Items; } + static bool coerce_require_persisted(AlgoTemplateToolBar d, bool value) => + value && d.Definition is AlgoDefinitionVM vm && vm.key.mode == AlgoKey.Mode.Persisted; + #region Transactional void _add_new() { _prepare_edit(); @@ -392,57 +432,79 @@ namespace mbts.ui.spark.algo { } #endregion - public static class VisualStates { - public const string - ShowUndoRedoButtons = nameof(ShowUndoRedoButtons), - HideUndoRedoButtons = nameof(HideUndoRedoButtons), - ShowRevertDefinitionButton = nameof(ShowRevertDefinitionButton), - HideRevertDefinitionButton = nameof(HideRevertDefinitionButton), - ToggleFavoriteNormal = nameof(ToggleFavoriteNormal), - ToggleFavoriteDisabled = nameof(ToggleFavoriteDisabled), - AllowDefinitionNameEditing = nameof(AllowDefinitionNameEditing), - ProhibitDefinitionNameEditing = nameof(ProhibitDefinitionNameEditing), - AllowDefinitionValuesEditing = nameof(AllowDefinitionValuesEditing), - ProhibitDefinitionValuesEditing = nameof(ProhibitDefinitionValuesEditing), - AllowTemplateNameEditing = nameof(AllowTemplateNameEditing), - ProhibitTemplateNameEditing = nameof(ProhibitTemplateNameEditing), - AllowTemplateValuesEditing = nameof(AllowTemplateValuesEditing), - ProhibitTemplateValuesEditing = nameof(ProhibitTemplateValuesEditing), - ShowTemplatesDropDown = nameof(ShowTemplatesDropDown), - HideTemplatesDropDown = nameof(HideTemplatesDropDown); - - static readonly Func - _get_undo_redo_buttons_state = _binary_state_delegate(ShowUndoRedoButtonsProperty, ShowUndoRedoButtons, HideUndoRedoButtons), - _get_revert_definition_button_state = _binary_state_delegate(ShowRevertDefinitionProperty, ShowRevertDefinitionButton, HideRevertDefinitionButton), - _get_toggle_favorite_button_state = _binary_state_delegate(ShowToggleFavoriteProperty, ToggleFavoriteNormal, ToggleFavoriteDisabled), - _get_definition_name_editing_state = _binary_state_delegate(CanUserModifyDefinitionNameProperty, AllowDefinitionNameEditing, ProhibitDefinitionNameEditing), - _get_definition_values_editing_state = _binary_state_delegate(CanUserModifyDefinitionValuesProperty, AllowDefinitionValuesEditing, ProhibitDefinitionValuesEditing), - _get_templates_dropdown_state = _binary_state_delegate(ShowTemplatesDropDownProperty, ShowTemplatesDropDown, HideTemplatesDropDown); - - public static void goto_all_states(AlgoTemplateToolBar toolbar) { - goto_undo_redo_buttons_state(toolbar); - goto_revert_definition_button_state(toolbar); - goto_toggle_favorite_button_state(toolbar); - goto_definition_name_editing_state(toolbar); - goto_definition_values_editing_state(toolbar); - goto_templates_dropdown_state(toolbar); + public static class VisualStateNames { + public static void apply_all(AlgoTemplateToolBar toolbar) { + UndoRedo.apply(toolbar._vsm, toolbar.ShowUndoRedoButtons); + RevertDefinition.apply(toolbar._vsm, toolbar.ShowRevertDefinition); + RenameDefinition.apply(toolbar._vsm, toolbar.ShowRenameDefinition); + SaveDefinition.apply(toolbar._vsm, toolbar.ShowSaveDefinition); + TemplatesDropDown.apply(toolbar._vsm, toolbar.ShowTemplatesDropDown); + RenameTemplate.apply(toolbar._vsm, toolbar.ShowTemplatesDropDown); // there is no corresponding 'CanUserRenameTemplate' property at the moment, for now it just refers to ShowTemplates. + ToggleFavorite.apply(toolbar._vsm, toolbar.ShowToggleFavorite); } + public static class UndoRedo { + public const string GroupName = nameof(UndoRedo); + public static readonly string + Active = $"{GroupName}{VisualStates.Active}", + Inactive = $"{GroupName}{VisualStates.Inactive}"; - public static void goto_undo_redo_buttons_state(AlgoTemplateToolBar toolbar) => _goto_state(toolbar, _get_undo_redo_buttons_state); - public static void goto_revert_definition_button_state(AlgoTemplateToolBar toolbar) => _goto_state(toolbar, _get_revert_definition_button_state); - public static void goto_toggle_favorite_button_state(AlgoTemplateToolBar toolbar) => _goto_state(toolbar, _get_toggle_favorite_button_state); - public static void goto_definition_name_editing_state(AlgoTemplateToolBar toolbar) => _goto_state(toolbar, _get_definition_name_editing_state); - public static void goto_definition_values_editing_state(AlgoTemplateToolBar toolbar) => _goto_state(toolbar, _get_definition_values_editing_state); - public static void goto_templates_dropdown_state(AlgoTemplateToolBar toolbar) => _goto_state(toolbar, _get_templates_dropdown_state); + public static void apply(VisualStateModel vsm, bool active) => + vsm.set_state(GroupName, active ? Active : Inactive); + } + public static class RevertDefinition { + public const string GroupName = nameof(RevertDefinition); + public static readonly string + Active = $"{GroupName}{VisualStates.Active}", + Inactive = $"{GroupName}{VisualStates.Inactive}"; - static void _goto_state(AlgoTemplateToolBar toolbar, Func get_state) => - VisualStateManager.GoToState(toolbar, get_state(toolbar), true); + public static void apply(VisualStateModel vsm, bool active) => + vsm.set_state(GroupName, active ? Active : Inactive); + } + public static class RenameDefinition { + public const string GroupName = nameof(RenameDefinition); + public static readonly string + Active = $"{GroupName}{VisualStates.Active}", + Inactive = $"{GroupName}{VisualStates.Inactive}"; - static Func _binary_state_delegate(DependencyProperty prop, string state_for_true, string state_for_false) => - _binary_state_delegate(tb => (bool)tb.GetValue(prop), state_for_true, state_for_false); + public static void apply(VisualStateModel vsm, bool active) => + vsm.set_state(GroupName, active ? Active : Inactive); + } + public static class SaveDefinition { + public const string GroupName = nameof(SaveDefinition); + public static readonly string + Active = $"{GroupName}{VisualStates.Active}", + Inactive = $"{GroupName}{VisualStates.Inactive}"; - static Func _binary_state_delegate(Func get_value, string state_for_true, string state_for_false) => - tb => get_value(tb) ? state_for_true : state_for_false; + public static void apply(VisualStateModel vsm, bool active) => + vsm.set_state(GroupName, active ? Active : Inactive); + } + public static class TemplatesDropDown { + public const string GroupName = nameof(TemplatesDropDown); + public static readonly string + Active = $"{GroupName}{VisualStates.Active}", + Inactive = $"{GroupName}{VisualStates.Inactive}"; + + public static void apply(VisualStateModel vsm, bool active) => + vsm.set_state(GroupName, active ? Active : Inactive); + } + public static class RenameTemplate { + public const string GroupName = nameof(RenameTemplate); + public static readonly string + Active = $"{GroupName}{VisualStates.Active}", + Inactive = $"{GroupName}{VisualStates.Inactive}"; + + public static void apply(VisualStateModel vsm, bool active) => + vsm.set_state(GroupName, active ? Active : Inactive); + } + public static class ToggleFavorite { + public const string GroupName = nameof(ToggleFavorite); + public static readonly string + Active = $"{GroupName}{VisualStates.Active}", + Inactive = $"{GroupName}{VisualStates.Inactive}"; + + public static void apply(VisualStateModel vsm, bool active) => + vsm.set_state(GroupName, active ? Active : Inactive); + } } } } \ No newline at end of file diff --git a/src/client/spark/view/Controls/Order/OrderDetailsPopupControl.xaml b/src/client/spark/view/Controls/Order/OrderDetailsPopupControl.xaml index 643b38120..6997917ee 100644 --- a/src/client/spark/view/Controls/Order/OrderDetailsPopupControl.xaml +++ b/src/client/spark/view/Controls/Order/OrderDetailsPopupControl.xaml @@ -93,11 +93,11 @@