ladder - hook up algotoolbar button visibility to ui.proto config

This commit is contained in:
John Colvin committed 2019-02-14 15:02:03 -06:00
1 parent 2794d7e9e7
commit 1dbba9713d
8 files changed
+167 -110

No files matched your search

@@ -16,9 +16,11 @@ namespace mbts.spark {
internal class AlgoStudioWindow : SparkWindow<StartupData>, 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,
@@ -42,8 +42,10 @@ namespace mbts.spark {
public static IReadOnlyDictionary<object, object> get_dynamic_resources(bts.config.AlgoStudioOptions ui_configuration) =>
new Dictionary<object, object> {
{ 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) }
};
}
@@ -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;
}
@@ -65,7 +65,7 @@ namespace mbts.spark {
IReadOnlyDictionary<AlgoKey, AlgoDefinitionMetadata> _algo_metadata = DictionaryHelper.empty<AlgoKey, AlgoDefinitionMetadata>();
IReadOnlyDictionary<AlgoKey, int> _favorite_algos_index = DictionaryHelper.empty<AlgoKey, int>();
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<SecurityMD> security_md_source, IObservable<InlineOrderProperties> 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; }
@@ -21,6 +21,7 @@
<Setter.Value>
<ControlTemplate TargetType="uag:AlgoTemplateToolBar">
<Border
x:Name="PART_Root_Border"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
@@ -28,9 +29,9 @@
Padding="{TemplateBinding Padding}"
>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="UndoRedoButtonStates">
<VisualState Name="{x:Static Member=ShowUndoRedoButtons, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStates}}"/>
<VisualState Name="{x:Static Member=HideUndoRedoButtons, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStates}}">
<VisualStateGroup Name="{x:Static GroupName, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStateNames.UndoRedo}}">
<VisualState Name="{x:Static Active, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStateNames.UndoRedo}}"/>
<VisualState Name="{x:Static Inactive, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStateNames.UndoRedo}}">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_Undo_MenuItem" Storyboard.TargetProperty="(UIElement.Visibility)">
<DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Collapsed}" />
@@ -47,9 +48,9 @@
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup Name="ToggleFavoriteButtonStates">
<VisualState Name="{x:Static Member=ToggleFavoriteNormal, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStates}}"/>
<VisualState Name="{x:Static Member=ToggleFavoriteDisabled, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStates}}">
<VisualStateGroup Name="{x:Static GroupName, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStateNames.ToggleFavorite}}">
<VisualState Name="{x:Static Active, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStateNames.ToggleFavorite}}"/>
<VisualState Name="{x:Static Inactive, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStateNames.ToggleFavorite}}">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_IsFavorite_MenuItem" Storyboard.TargetProperty="(UIElement.Visibility)">
<DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Collapsed}" />
@@ -57,9 +58,9 @@
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup Name="AlgoDefinitionNameEditingStates">
<VisualState Name="{x:Static Member=AllowDefinitionNameEditing, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStates}}"/>
<VisualState Name="{x:Static Member=ProhibitDefinitionNameEditing, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStates}}">
<VisualStateGroup Name="{x:Static GroupName, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStateNames.RenameDefinition}}">
<VisualState Name="{x:Static Active, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStateNames.RenameDefinition}}"/>
<VisualState Name="{x:Static Inactive, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStateNames.RenameDefinition}}">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_RenameDefinition_MenuItem" Storyboard.TargetProperty="(UIElement.Visibility)">
<DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Collapsed}" />
@@ -67,25 +68,19 @@
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup Name="AlgoDefinitionValueEditingStates">
<VisualState Name="{x:Static Member=AllowDefinitionValuesEditing, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStates}}"/>
<VisualState Name="{x:Static Member=ProhibitDefinitionValuesEditing, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStates}}">
<VisualStateGroup Name="{x:Static GroupName, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStateNames.SaveDefinition}}">
<VisualState Name="{x:Static Active, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStateNames.SaveDefinition}}"/>
<VisualState Name="{x:Static Inactive, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStateNames.SaveDefinition}}">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_SaveDefinition_MenuItem" Storyboard.TargetProperty="(UIElement.Visibility)">
<DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Collapsed}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_UndoDefinition_MenuItem" Storyboard.TargetProperty="(UIElement.Visibility)">
<DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Collapsed}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_RedoDefinition_MenuItem" Storyboard.TargetProperty="(UIElement.Visibility)">
<DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Collapsed}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup Name="RevertDefinitionButtonStates">
<VisualState Name="{x:Static Member=ShowRevertDefinitionButton,MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStates}}"/>
<VisualState Name="{x:Static Member=HideRevertDefinitionButton,MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStates}}">
<VisualStateGroup Name="{x:Static GroupName, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStateNames.RevertDefinition}}">
<VisualState Name="{x:Static Active,MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStateNames.RevertDefinition}}"/>
<VisualState Name="{x:Static Inactive,MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStateNames.RevertDefinition}}">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_RevertDefinition_MenuItem" Storyboard.TargetProperty="(UIElement.Visibility)">
<DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Collapsed}"/>
@@ -93,9 +88,9 @@
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup Name="AlgoTemplateNameEditingStates">
<VisualState Name="{x:Static Member=AllowTemplateNameEditing, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStates}}"/>
<VisualState Name="{x:Static Member=ProhibitTemplateNameEditing, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStates}}">
<VisualStateGroup Name="{x:Static GroupName, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStateNames.RenameTemplate}}">
<VisualState Name="{x:Static Active, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStateNames.RenameTemplate}}"/>
<VisualState Name="{x:Static Inactive, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStateNames.RenameTemplate}}">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_Rename_MenuItem" Storyboard.TargetProperty="(UIElement.Visibility)">
<DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Collapsed}" />
@@ -103,9 +98,9 @@
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup Name="TemplateDropDownStates">
<VisualState Name="{x:Static Member=ShowTemplatesDropDown, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStates}}"/>
<VisualState Name="{x:Static Member=HideTemplatesDropDown, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStates}}">
<VisualStateGroup Name="{x:Static GroupName, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStateNames.TemplatesDropDown}}">
<VisualState Name="{x:Static Active, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStateNames.TemplatesDropDown}}"/>
<VisualState Name="{x:Static Inactive, MemberType={u:Nested uag:AlgoTemplateToolBar.VisualStateNames.TemplatesDropDown}}">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_Templates_ComboBox" Storyboard.TargetProperty="(UIElement.Visibility)">
<DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Collapsed}" />
@@ -300,7 +295,7 @@
<Image Source="{x:Static u:Icons.UndoCircular}"/>
</MenuItem.Header>
<MenuItem.ToolTip>
<TextBlock Text="{Binding SelectedItem.name, RelativeSource={RelativeSource TemplatedParent}, StringFormat='{}Undo changes to \&apos;{0}\&apos;'}"/>
<TextBlock Text="{Binding Definition.name, RelativeSource={RelativeSource TemplatedParent}, StringFormat='{}Undo changes to \&apos;{0}\&apos;'}"/>
</MenuItem.ToolTip>
</MenuItem>
<MenuItem
@@ -2,6 +2,7 @@
using mbts.ui.controls;
using mbts.ui.converters;
using mbts.ui.extensions;
using mbts.ui.utility;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
@@ -65,11 +66,31 @@ namespace mbts.ui.spark.algo {
static AlgoTemplateToolBar() =>
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<bool, AlgoTemplateToolBar>(
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<bool, AlgoTemplateToolBar>(
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<bool, AlgoTemplateToolBar>(
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<bool, AlgoTemplateToolBar>(
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<bool, AlgoTemplateToolBar>(
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<bool, AlgoTemplateToolBar>(
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<AlgoDefinitionVM, AlgoTemplateToolBar>(nameof(Definition));
WPFHelper.create_dp<AlgoDefinitionVM, AlgoTemplateToolBar>(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<AlgoTemplateToolBar, string>
_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<AlgoTemplateToolBar, string> 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<AlgoTemplateToolBar, string> _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<AlgoTemplateToolBar, string> _binary_state_delegate(Func<AlgoTemplateToolBar, bool> 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);
}
}
}
}
@@ -93,11 +93,11 @@
<Rectangle Grid.ColumnSpan="{Binding ColumnDefinitions.Count, RelativeSource={RelativeSource AncestorType=Grid}}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Fill="{x:Static u:BTSColors.dialog_skirt_brush}"/>
<uag:AlgoTemplateToolBar
x:Name="PART_AlgoTemplateToolBar"
MinWidth="230"
Margin="{StaticResource Margin.LP1}"
MinWidth="230"
IsReadOnly="{TemplateBinding IsAlgoTemplateToolBarReadOnly}"
CanUserModifyDefinitionName="False"
CanUserModifyDefinitionValues="False"
ShowRenameDefinition="{DynamicResource {x:Static sp:AlgoStudioWindow.ShowAlgoToolBarRenameDefinitionKey}}"
ShowSaveDefinition="{DynamicResource {x:Static sp:AlgoStudioWindow.ShowAlgoToolBarSaveDefinitionKey}}"
ShowTemplatesDropDown="{DynamicResource {x:Static sp:AlgoStudioWindow.TemplatesEnabledKey}}"
Definition="{Binding SelectedItem, RelativeSource={RelativeSource AncestorType=uag:OrderDetailsPopupControl}}"
EditableCollectionModel="{Binding algo_template_collection_model}"
@@ -109,9 +109,9 @@
RedoCommand="{Binding redo_cmd}"
UndoDefinitionCommand="{Binding undo_definition_cmd}"
RedoDefinitionCommand="{Binding redo_definition_cmd}"
ShowUndoRedoButtons="False"
ShowUndoRedoButtons="{DynamicResource {x:Static sp:AlgoStudioWindow.ShowAlgoToolBarUndoRedoDefinitionKey}}"
RevertDefinitionCommand="{Binding revert_definition_cmd}"
ShowRevertDefinition="False"
ShowRevertDefinition="{DynamicResource {x:Static sp:AlgoStudioWindow.ShowAlgoToolBarRevertDefinitionKey}}"
SaveCommand="{Binding save_template_cmd}"
SaveDefinitionCommand="{Binding save_definition_cmd}"
ToggleFavoriteCommand="{Binding toggle_favorite_cmd}"
+4 -2
View File
@@ -57,8 +57,6 @@ message LadderKnobs {
optional uint32 max_open_ladders = 4 [default = 75];
optional uint32 security_timeout_secs = 5 [default = 60];
optional bool open_algo_popup_on_select = 6 [default = false];
optional bool show_algo_popup_undo_redo_buttons = 7 [default = false];
optional bool show_revert_definition_button = 8 [default = true];
}
message ShellPingOptions {
@@ -93,6 +91,10 @@ message AlgoStudioOptions {
optional bool show_badges_in_tree_view = 8 [default = false];
optional AddTemplateButton add_template_button = 9 [default = None];
optional ModelType model_type = 10 [default = FlatDefinitions];
optional bool show_algo_toolbar_rename = 11 [default = false];
optional bool show_algo_toolbar_revert = 12 [default = true];
optional bool show_algo_toolbar_save = 13 [default = true];
optional bool show_algo_toolbar_undo_redo = 14 [default = false];
}
message AlgoStudioFlatDefinitionModelOptions {