AlgoStudio - hook up flat definition favorites
This commit is contained in:
1 parent
bdf3c79147
commit
c7725fe681
26 files changed
+603
-156
No files matched your search
@@ -34,6 +34,12 @@
|
||||
<cv:ValueMap x:Key="AlgoTemplateFavoriteToggleButtonToolTipConverter" Default="Add to Favorites">
|
||||
<cv:KeyValue Key="{u:True}" Value="Remove from Favorites"/>
|
||||
</cv:ValueMap>
|
||||
<sys:String x:Key="AlgoAbbreviationActiveState">AbbreviationActive</sys:String>
|
||||
<sys:String x:Key="AlgoAbbreviationInactiveState">AbbreviationInactive</sys:String>
|
||||
<cv:ValueMap x:Key="AlgoAbbreviationVisualStateConverter" Default="{StaticResource AlgoAbbreviationActiveState}">
|
||||
<cv:KeyValue Key="{x:Null}" Value="{StaticResource AlgoAbbreviationInactiveState}"/>
|
||||
<cv:KeyValue Key="{x:Static sys:String.Empty}" Value="{StaticResource AlgoAbbreviationInactiveState}"/>
|
||||
</cv:ValueMap>
|
||||
<uspcv:OrderTypeBrushConverter x:Key="OrderTypeBrushConverter" DefaultBrush="Transparent"/>
|
||||
<Style TargetType="GroupBox">
|
||||
<Setter Property="BorderBrush" Value="Transparent"/>
|
||||
@@ -109,7 +115,7 @@
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup>
|
||||
<VisualStateGroup Name="NormalStates">
|
||||
<VisualState Name="{x:Static u:VisualStates.Active}">
|
||||
<Storyboard>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="edit_pane" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
@@ -200,27 +206,65 @@
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock VerticalAlignment="Center">Name:</TextBlock>
|
||||
<TextBox
|
||||
x:Name="name_text_box"
|
||||
Grid.Column="1"
|
||||
ToolTipService.ShowOnDisabled="True"
|
||||
u:TextBoxBehavior.EnterKeyBehavior="CommitAndRelease"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Center"
|
||||
IsEnabled="{Binding content_source.can_edit_name}"
|
||||
Margin="{StaticResource Margin.LP1}"
|
||||
Text="{Binding content_source.name, UpdateSourceTrigger=PropertyChanged}"
|
||||
ToolTip="{Binding content_source.name_tool_tip}"
|
||||
/>
|
||||
<Grid u:StateManager.VisualState="{Binding content_source.abbreviation, Converter={StaticResource AlgoAbbreviationVisualStateConverter}}">
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup Name="AlgoAbbreviationStates">
|
||||
<VisualState Name="{StaticResource AlgoAbbreviationInactiveState}"/>
|
||||
<VisualState Name="{StaticResource AlgoAbbreviationActiveState}">
|
||||
<Storyboard>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="abbreviation_label" Storyboard.TargetProperty="(TextElement.Foreground)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{u:Brush Black}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="abbreviation_value" Storyboard.TargetProperty="(TextElement.Foreground)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{u:Brush Black}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="abbreviation_value" Storyboard.TargetProperty="(TextElement.FontStyle)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{u:FontStyle Normal}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState></VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="3*"/>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock VerticalAlignment="Center">Name:</TextBlock>
|
||||
<TextBox
|
||||
x:Name="name_text_box"
|
||||
Grid.Column="1"
|
||||
ToolTipService.ShowOnDisabled="True"
|
||||
u:TextBoxBehavior.EnterKeyBehavior="CommitAndRelease"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Center"
|
||||
IsEnabled="{Binding content_source.can_edit_name}"
|
||||
Margin="{StaticResource Margin.LP1}"
|
||||
Text="{Binding content_source.name, UpdateSourceTrigger=PropertyChanged, Delay=25}"
|
||||
ToolTip="{Binding content_source.name_tool_tip}"
|
||||
/>
|
||||
<Grid Grid.Column="2">
|
||||
<Grid.ToolTip>
|
||||
<TextBlock>
|
||||
<TextBlock.Inlines>
|
||||
<Run>Specify an abbreviation for this algo to use in ladder algo 'favorite' buttons.</Run>
|
||||
<LineBreak/>
|
||||
<Run FontStyle="Italic">Hint: To add/remove algos from 'favorites', open the ladder settings dialog and select the 'Algo Favorites' tab.</Run>
|
||||
</TextBlock.Inlines>
|
||||
</TextBlock>
|
||||
</Grid.ToolTip>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock x:Name="abbreviation_label" FontStyle="Italic" Foreground="Gray" Margin="{StaticResource Margin.LP1}" VerticalAlignment="Center">Abbrev.</TextBlock>
|
||||
<TextBox x:Name="abbreviation_value" Grid.Column="1" Margin="{StaticResource Margin.LP1}" Text="{Binding content_source.abbreviation, UpdateSourceTrigger=PropertyChanged, Delay=25}"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<GroupBox
|
||||
x:Name="content_host"
|
||||
Grid.Row="1"
|
||||
Grid.ColumnSpan="2"
|
||||
Background="Transparent"
|
||||
BorderBrush="{Binding editable_content, Converter={StaticResource OrderTypeBrushConverter}}"
|
||||
Margin="0,6,0,0"
|
||||
@@ -278,7 +322,7 @@
|
||||
Margin="{StaticResource Margin.TP1}"
|
||||
/>
|
||||
</GroupBox>
|
||||
<c:DialogSkirt Grid.Row="2" Grid.ColumnSpan="2" Margin="{StaticResource Margin.TP2}" Background="Transparent">
|
||||
<c:DialogSkirt Grid.Row="2" Margin="{StaticResource Margin.TP2}" Background="Transparent">
|
||||
<c:DialogSkirt.RightItems>
|
||||
<x:ArrayExtension Type="{x:Type Button}">
|
||||
<Button ToolTipService.ShowOnDisabled="True" Command="{Binding save_cmd}" CommandParameter="{Binding content_source}" Width="100" Style="{StaticResource {x:Static c:DialogSkirt.DialogSkirtButtonStyleKey}}" ToolTip="{Binding save_cmd_tooltip}" IsDefault="True">
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using bts.api.orderman;
|
||||
using bts;
|
||||
using bts.api.orderman;
|
||||
using bts.utils;
|
||||
using mbts.spark.utilities;
|
||||
using mbts.ui;
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using bts;
|
||||
using bts.api.core;
|
||||
using bts.api.orderman;
|
||||
using bts.collections;
|
||||
using bts.utils;
|
||||
using mbts.collections;
|
||||
using mbts.spark.utilities;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
@@ -21,20 +20,22 @@ namespace mbts.spark {
|
||||
public const string new_algo_name = "New Algo";
|
||||
readonly OrdersModel _model;
|
||||
readonly ObservableKeyedCollection<AlgoDefinitionTemplateVM, AlgoVMKey> _templates = new ObservableKeyedCollection<AlgoDefinitionTemplateVM, AlgoVMKey>(t => t.vm_key);
|
||||
readonly EditStack<AlgoDefinitionData> _edit_stack = new EditStack<AlgoDefinitionData>();
|
||||
readonly VersionContainer<AlgoDefinitionData> _version;
|
||||
readonly EditStack<Snapshot> _edit_stack = new EditStack<Snapshot>();
|
||||
readonly VersionContainer<Snapshot> _version;
|
||||
readonly Property<bool> _is_expanded, _is_selected;
|
||||
readonly Property<IOrderTypeVM> _algo_root;
|
||||
readonly Property<IOrderTypeVM> _visible_algo_root;
|
||||
readonly Property<AlgoDefinitionTemplateVM> _selected_template;
|
||||
readonly DelegateProperty<bool> _is_dirty, _can_undo, _can_redo;
|
||||
readonly DelegateProperty<bool> _is_favorite, _is_dirty, _can_undo, _can_redo;
|
||||
readonly Property<string> _abbreviation;
|
||||
readonly OrderTypeVMCollection _algo_roots;
|
||||
readonly ObservableAppendCollection<AlgoDefinitionTemplateVM> _templates_with_custom;
|
||||
readonly DeferrableActionWrapper _edit_stack_push;
|
||||
readonly ReactiveThresholdMonitor<AlgoDefinitionTemplateVM> _any_templates_dirty_monitor = new ReactiveThresholdMonitor<AlgoDefinitionTemplateVM>(t => t.observe_is_dirty());
|
||||
OrderTypeEditingPermissions _editing_permissions = _get_permissions(0);
|
||||
int? _favorite_index;
|
||||
string _name;
|
||||
AlgoDefinitionData? _committed;
|
||||
Snapshot? _committed;
|
||||
AlgoDefinitionMetadata _metadata;
|
||||
TableUpdateBuffer<AlgoTemplateData, AlgoPersistedKey> _template_update_buffer;
|
||||
bool _connected;
|
||||
@@ -56,7 +57,9 @@ namespace mbts.spark {
|
||||
_model = model;
|
||||
this.vm_key = vm_key;
|
||||
this.security_md_source = security_md_source ?? Observable.Return<SecurityMD?>(null);
|
||||
_version = new VersionContainer<Snapshot>(_snapshot);
|
||||
_name = name;
|
||||
_abbreviation = backing(nameof(abbreviation), string.Empty);
|
||||
_template_update_buffer = new TableUpdateBuffer<AlgoTemplateData, AlgoPersistedKey>(t => t.key);
|
||||
_algo_roots = new OrderTypeVMCollection(_model);
|
||||
_algo_root = backing(nameof(algo_root), _algo_roots.GetOrAdd(init_algo_root.id, _ => OrderTypeVMFactory.create(_model, this.security_md_source, init_algo_root, _editing_permissions)));
|
||||
@@ -74,12 +77,12 @@ namespace mbts.spark {
|
||||
resources.Add(_algo_root.observe_current(true).Subscribe(_visible_algo_root.set));
|
||||
}
|
||||
resources.Add(templates.ObserveSelf().Subscribe(_ => RaisePropertyChanged(nameof(can_edit_structure))));
|
||||
_version = new VersionContainer<AlgoDefinitionData>(() => create_algo_def());
|
||||
_committed = _version.value;
|
||||
_edit_stack_push = new DeferrableActionWrapper(() => {
|
||||
if (algo_root != null)
|
||||
_edit_stack.push_distinct(_version.value);
|
||||
});
|
||||
_is_favorite = backing(nameof(is_favorite), () => _favorite_index.HasValue);
|
||||
_is_expanded = backing(nameof(is_expanded), true);
|
||||
_is_selected = backing(nameof(is_selected), true);
|
||||
_can_redo = backing(nameof(can_redo), () => _edit_stack.get_can_redo(_version.value));
|
||||
@@ -91,12 +94,7 @@ namespace mbts.spark {
|
||||
_editing_permissions = _get_permissions(templates.Count);
|
||||
resources.AddRange(
|
||||
templates.ObserveSelf().Select(_ => _get_permissions(templates.Count)).DistinctUntilChanged().OnDispatcher().Subscribe(on_editing_permissions),
|
||||
_algo_root.observe_current(true).SubscribeHookLatest(ot => ot == null ? Disposable.empty : ot.subscribe_definition().Subscribe(d => {
|
||||
_version.increment_version();
|
||||
_edit_stack_push.execute();
|
||||
_is_dirty.refresh();
|
||||
_refresh_undo_redo();
|
||||
})),
|
||||
_algo_root.observe_current(true).SubscribeHookLatest(ot => ot == null ? Disposable.empty : ot.subscribe_definition().Subscribe(d => _on_local_changed())),
|
||||
Disposable.wrap_collection(algo_roots),
|
||||
Disposable.Create(templates.Clear),
|
||||
ObservableAutoWrapper.connect_item_hooks(templates, t => new CompositeDisposable(_any_templates_dirty_monitor.join(t), t)),
|
||||
@@ -106,6 +104,7 @@ namespace mbts.spark {
|
||||
}));
|
||||
switch (vm_key.mode) {
|
||||
case AlgoVMKey.Mode.Persisted:
|
||||
_metadata = new AlgoDefinitionMetadata(vm_key.persisted_id);
|
||||
resources.Add(_template_update_buffer.OnDispatcher().Subscribe(_on_templates));
|
||||
resources.Add(model.algo_model.metadata_service.subscribe_metadata(vm_key.persisted_id).OnDispatcher().Subscribe(_on_metadata));
|
||||
break;
|
||||
@@ -142,12 +141,15 @@ namespace mbts.spark {
|
||||
public string name {
|
||||
get => _name;
|
||||
set {
|
||||
if (Set(ref _name, value)) {
|
||||
_version.increment_version();
|
||||
_edit_stack.push(_version.value);
|
||||
_is_dirty.refresh();
|
||||
_refresh_undo_redo();
|
||||
}
|
||||
if (Set(ref _name, value))
|
||||
_on_local_changed();
|
||||
}
|
||||
}
|
||||
public string abbreviation {
|
||||
get => _abbreviation.Value;
|
||||
set {
|
||||
if (_abbreviation.set_new(value))
|
||||
_on_local_changed();
|
||||
}
|
||||
}
|
||||
public ObservableCollection<IOrderTypeVM> algo_roots => _algo_roots;
|
||||
@@ -180,6 +182,14 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
}
|
||||
public int? favorite_index {
|
||||
get => _favorite_index;
|
||||
set {
|
||||
if (Set(ref _favorite_index, value))
|
||||
_is_favorite.refresh();
|
||||
}
|
||||
}
|
||||
public bool is_favorite => _is_favorite.Value;
|
||||
public bool is_expanded { get => _is_expanded.Value; set => _is_expanded.set(value); }
|
||||
public bool is_selected { get => _is_selected.Value; set => _is_selected.set(value); }
|
||||
public bool is_dirty => _is_dirty.Value;
|
||||
@@ -217,9 +227,7 @@ namespace mbts.spark {
|
||||
public void load_committed() {
|
||||
using (_edit_stack_push.defer_execution())
|
||||
_assign_from_data(_committed.Value);
|
||||
_version.increment_version();
|
||||
_committed = _version.value;
|
||||
_is_dirty.refresh();
|
||||
_on_committed_changed();
|
||||
}
|
||||
/// <summary>
|
||||
/// Subscribes to the templates source for this definition if it has been persisted (subscription requires a persistant id); does nothing if this definition has not been persisted, or if it is already subscribed (idempotent).
|
||||
@@ -242,9 +250,7 @@ namespace mbts.spark {
|
||||
_edit_stack.clear();
|
||||
using (_edit_stack_push.defer_execution())
|
||||
_assign_from_data(named_def.display_name, named_def.definition);
|
||||
_version.increment_version();
|
||||
_committed = _version.value;
|
||||
_is_dirty.refresh();
|
||||
_on_committed_changed();
|
||||
}
|
||||
|
||||
public void load(AlgoDefinitionData data) {
|
||||
@@ -252,9 +258,7 @@ namespace mbts.spark {
|
||||
_edit_stack_push.execute();
|
||||
using (_edit_stack_push.defer_execution())
|
||||
_assign_from_data(data);
|
||||
_version.increment_version();
|
||||
_committed = _version.value;
|
||||
_is_dirty.refresh();
|
||||
_on_committed_changed();
|
||||
}
|
||||
|
||||
// pass a copy of the persisted state - rather than use local values - because if something goes wrong, it is better to be in sync with data fresh from the server/api.
|
||||
@@ -264,9 +268,13 @@ namespace mbts.spark {
|
||||
public AlgoDefinitionData create_algo_def() =>
|
||||
new AlgoDefinitionData(new CustomOrderDefinitionImmutable(algo_root.create()), name, vm_key.persisted_id);
|
||||
|
||||
public AlgoDefinitionMetadata create_metadata() =>
|
||||
_metadata.with(abbreviation: abbreviation);
|
||||
|
||||
public bool Equals(AlgoDefinitionVM other) => other != null && vm_key == other.vm_key;
|
||||
public override bool Equals(object obj) => Equals(obj as AlgoDefinitionVM);
|
||||
public override int GetHashCode() => vm_key.GetHashCode();
|
||||
public override string ToString() => algo_root == null ? $"!:{name}" : $"{algo_root.order_type}:{name}";
|
||||
|
||||
static OrderTypeEditingPermissions _get_permissions(int n_templates) {
|
||||
var permissions = OrderTypeEditingPermissions.None;
|
||||
@@ -285,6 +293,11 @@ namespace mbts.spark {
|
||||
throw new InvalidOperationException($"{typeof(AlgoDefinitionVM)} '{nameof(vm_key)}' not equal to the key generated from the specified data.");
|
||||
}
|
||||
|
||||
void _assign_from_data(Snapshot state) {
|
||||
_assign_from_data(state.data);
|
||||
_abbreviation.set(state.abbreviation);
|
||||
}
|
||||
|
||||
void _assign_from_data(AlgoDefinitionData data) =>
|
||||
_assign_from_data(data.name, data.value);
|
||||
|
||||
@@ -294,17 +307,37 @@ namespace mbts.spark {
|
||||
algo_root.load_from(definition);
|
||||
}
|
||||
|
||||
void _on_committed_changed() {
|
||||
_committed = _version.value;
|
||||
_is_dirty.refresh();
|
||||
}
|
||||
|
||||
void _on_local_changed() {
|
||||
_version.increment_version();
|
||||
_edit_stack_push.execute();
|
||||
_is_dirty.refresh();
|
||||
_refresh_undo_redo();
|
||||
}
|
||||
|
||||
IOrderTypeVM _mk_algo_root(CustomOrderDefinition.CustomOneofCase t) =>
|
||||
OrderTypeVMFactory.create(_model, security_md_source, t, editing_permissions: _editing_permissions);
|
||||
|
||||
void _on_metadata(AlgoDefinitionMetadata metadata) {
|
||||
_metadata = metadata;
|
||||
foreach (var t in templates) {
|
||||
if (t.vm_key.mode == AlgoVMKey.Mode.Persisted)
|
||||
t.on_meta(t.vm_key.persisted_id == _metadata.default_template, _metadata.favorite_templates.Contains(t.vm_key.persisted_id));
|
||||
else
|
||||
t.on_meta(false, false);
|
||||
using (_edit_stack_push.supress_execution()) {
|
||||
_committed = _committed.HasValue ? new Snapshot(_committed.Value.data, metadata.abbreviation) : new Snapshot(default, metadata.abbreviation);
|
||||
_abbreviation.set(metadata.abbreviation);
|
||||
foreach (var t in templates) {
|
||||
if (t.vm_key.mode == AlgoVMKey.Mode.Persisted)
|
||||
t.on_meta(t.vm_key.persisted_id == metadata.default_template, metadata.favorite_templates.Contains(t.vm_key.persisted_id));
|
||||
else
|
||||
t.on_meta(false, false);
|
||||
}
|
||||
}
|
||||
_version.increment_version();
|
||||
if (_edit_stack.size == 1 && _edit_stack.pos == 1) {
|
||||
_edit_stack.clear();
|
||||
_edit_stack.push(_snapshot());
|
||||
} else _edit_stack.push_distinct(_snapshot());
|
||||
}
|
||||
|
||||
void _on_templates(TableUpdate<AlgoTemplateData, AlgoPersistedKey> table) {
|
||||
@@ -328,17 +361,38 @@ namespace mbts.spark {
|
||||
_can_redo.refresh();
|
||||
}
|
||||
|
||||
void _restore(TryGetValue<AlgoDefinitionData> try_get_snapshot) {
|
||||
while (try_get_snapshot(out AlgoDefinitionData next_state)) {
|
||||
void _restore(TryGetValue<Snapshot> try_get_snapshot) {
|
||||
while (try_get_snapshot(out Snapshot next_state)) {
|
||||
if (!_version.value.Equals(next_state)) {
|
||||
using (_edit_stack_push.supress_execution())
|
||||
_assign_from_data(next_state);
|
||||
_version.increment_version();
|
||||
_abbreviation.set(next_state.abbreviation);
|
||||
_is_dirty.refresh();
|
||||
break;
|
||||
}
|
||||
}
|
||||
_refresh_undo_redo();
|
||||
}
|
||||
|
||||
Snapshot _snapshot() =>
|
||||
new Snapshot(create_algo_def(), abbreviation);
|
||||
|
||||
struct Snapshot : IEquatable<Snapshot> {
|
||||
public readonly AlgoDefinitionData data;
|
||||
public readonly string abbreviation;
|
||||
|
||||
public Snapshot(AlgoDefinitionData data, string abbreviation) {
|
||||
this.data = data;
|
||||
this.abbreviation = abbreviation;
|
||||
}
|
||||
|
||||
public bool Equals(Snapshot other) => data == other.data && abbreviation == other.abbreviation;
|
||||
public override bool Equals(object obj) => EqualityComparer.equals_obj(this, obj);
|
||||
public override int GetHashCode() => EqualityComparer.aggregate_hash(data.GetHashCode(), abbreviation == null ? 0 : abbreviation.GetHashCode());
|
||||
|
||||
public static bool operator ==(Snapshot a, Snapshot b) => a.Equals(b);
|
||||
public static bool operator !=(Snapshot a, Snapshot b) => !a.Equals(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -160,8 +160,21 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
public async Task save_definition(AlgoDefinitionVM definition) {
|
||||
using (_save_op())
|
||||
await AlgoPersistenceHelper.persist_definition(_model, _definitions, definition);
|
||||
using (_save_op()) {
|
||||
var newly_persisted_keys = await AlgoPersistenceHelper.persist_definition(_model, _definitions, definition);
|
||||
AlgoPersistedKey pkey;
|
||||
switch (definition.vm_key.mode) {
|
||||
case AlgoVMKey.Mode.Unpersisted:
|
||||
if (!newly_persisted_keys.TryGetValue(definition.vm_key.custom_placeholder_id, out pkey))
|
||||
return;
|
||||
break;
|
||||
case AlgoVMKey.Mode.Persisted:
|
||||
pkey = definition.vm_key.persisted_id;
|
||||
break;
|
||||
default: return;
|
||||
}
|
||||
await _model.algo_model.metadata_service.update_metadata(pkey, _ => definition.create_metadata());
|
||||
}
|
||||
}
|
||||
|
||||
public async Task save_template(AlgoDefinitionTemplateVM template) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using mbts.persist;
|
||||
using bts.utils;
|
||||
using mbts.persist;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
using mbts.utils;
|
||||
@@ -14,15 +15,11 @@ namespace bts {
|
||||
interface IAlgoTemplateMetadataService {
|
||||
IObservable<IReadOnlyDictionary<AlgoPersistedKey, AlgoDefinitionMetadata>> subscribe_metadata();
|
||||
IObservable<AlgoDefinitionMetadata> subscribe_metadata(AlgoPersistedKey definition_key);
|
||||
Task add_to_favorites(AlgoPersistedKey definition, AlgoPersistedKey template);
|
||||
Task remove_from_favorites(AlgoPersistedKey definition, AlgoPersistedKey template);
|
||||
Task set_as_default(AlgoPersistedKey definition, AlgoPersistedKey template);
|
||||
Task hide_definition(AlgoPersistedKey definition);
|
||||
Task show_definition(AlgoPersistedKey definition);
|
||||
Task update_metadata(AlgoPersistedKey definition, Func<AlgoDefinitionMetadata, AlgoDefinitionMetadata> update);
|
||||
}
|
||||
|
||||
[ProtoContract]
|
||||
struct AlgoDefinitionMetadata {
|
||||
struct AlgoDefinitionMetadata : IEquatable<AlgoDefinitionMetadata> {
|
||||
[ProtoMember(1)]
|
||||
public readonly AlgoPersistedKey id;
|
||||
[ProtoMember(2)]
|
||||
@@ -30,22 +27,79 @@ namespace bts {
|
||||
[ProtoMember(3)]
|
||||
readonly AlgoPersistedKey[] _favorite_templates;
|
||||
[ProtoMember(4)]
|
||||
public readonly bool is_favorite;
|
||||
[ProtoMember(5)]
|
||||
public readonly bool is_hidden;
|
||||
[ProtoMember(6)]
|
||||
public readonly string abbreviation;
|
||||
|
||||
public AlgoDefinitionMetadata(AlgoPersistedKey id, AlgoPersistedKey default_template, AlgoPersistedKey[] favorite_templates, bool is_hidden) {
|
||||
public AlgoDefinitionMetadata(AlgoPersistedKey id)
|
||||
: this(id, default, default, default, default, null) { }
|
||||
|
||||
public AlgoDefinitionMetadata(AlgoPersistedKey id, AlgoPersistedKey default_template, AlgoPersistedKey[] favorite_templates, bool is_favorite, bool is_hidden, string abbreviation) {
|
||||
this.id = id;
|
||||
this.default_template = default_template;
|
||||
_favorite_templates = favorite_templates;
|
||||
this.is_favorite = is_favorite;
|
||||
this.is_hidden = is_hidden;
|
||||
this.abbreviation = abbreviation;
|
||||
}
|
||||
|
||||
public IEnumerable<AlgoPersistedKey> favorite_templates => _favorite_templates.empty_if_null();
|
||||
public IReadOnlyList<AlgoPersistedKey> favorite_templates => _favorite_templates ?? Array.Empty<AlgoPersistedKey>();
|
||||
|
||||
public AlgoDefinitionMetadata with(AlgoPersistedKey? default_template = null, IEnumerable<AlgoPersistedKey> favorite_templates = null, bool? is_hidden = null) =>
|
||||
public AlgoDefinitionMetadata with(AlgoPersistedKey? default_template = null, IEnumerable<AlgoPersistedKey> favorite_templates = null, bool? is_favorite = null, bool? is_hidden = null, string abbreviation = null) =>
|
||||
new AlgoDefinitionMetadata(id,
|
||||
default_template ?? this.default_template,
|
||||
favorite_templates == null ? _favorite_templates : favorite_templates.ToArray(),
|
||||
is_hidden ?? this.is_hidden);
|
||||
is_favorite ?? this.is_favorite,
|
||||
is_hidden ?? this.is_hidden,
|
||||
abbreviation ?? this.abbreviation);
|
||||
|
||||
public bool Equals(AlgoDefinitionMetadata other) =>
|
||||
id == other.id &&
|
||||
default_template == other.default_template &&
|
||||
is_favorite == other.is_favorite &&
|
||||
is_hidden == other.is_hidden &&
|
||||
abbreviation == other.abbreviation &&
|
||||
favorite_templates.SequenceEqual(other.favorite_templates);
|
||||
|
||||
public override bool Equals(object obj) =>
|
||||
EqualityComparer.equals_obj(this, obj);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
EqualityComparer.aggregate_hash(
|
||||
id.GetHashCode(),
|
||||
default_template.GetHashCode(),
|
||||
is_favorite.GetHashCode(),
|
||||
is_hidden.GetHashCode(),
|
||||
abbreviation == null ? 0 : abbreviation.GetHashCode(),
|
||||
EqualityComparer.aggregate_hash_limited(_favorite_templates));
|
||||
|
||||
public static bool operator ==(AlgoDefinitionMetadata a, AlgoDefinitionMetadata b) => a.Equals(b);
|
||||
public static bool operator !=(AlgoDefinitionMetadata a, AlgoDefinitionMetadata b) => !a.Equals(b);
|
||||
}
|
||||
|
||||
static class AlgoTemplateMetadataServiceExtensions {
|
||||
public static Task add_to_favorites(this IAlgoTemplateMetadataService service, AlgoPersistedKey definition) =>
|
||||
service.update_metadata(definition, d => d.with(is_favorite: true));
|
||||
|
||||
public static Task add_to_favorites(this IAlgoTemplateMetadataService service, AlgoPersistedKey definition, AlgoPersistedKey template) =>
|
||||
service.update_metadata(definition, m => m.with(favorite_templates: ListUtils.add_distinct(m.favorite_templates, template)));
|
||||
|
||||
public static Task remove_from_favorites(this IAlgoTemplateMetadataService service, AlgoPersistedKey definition) =>
|
||||
service.update_metadata(definition, d => d.with(is_favorite: false));
|
||||
|
||||
public static Task remove_from_favorites(this IAlgoTemplateMetadataService service, AlgoPersistedKey definition, AlgoPersistedKey template) =>
|
||||
service.update_metadata(definition, m => m.with(favorite_templates: ListUtils.remove(m.favorite_templates, template)));
|
||||
|
||||
public static Task set_as_default(this IAlgoTemplateMetadataService service, AlgoPersistedKey definition, AlgoPersistedKey template) =>
|
||||
service.update_metadata(definition, m => m.with(default_template: template));
|
||||
|
||||
public static Task hide_definition(this IAlgoTemplateMetadataService service, AlgoPersistedKey definition) =>
|
||||
service.update_metadata(definition, m => m.with(is_hidden: true));
|
||||
|
||||
public static Task show_definition(this IAlgoTemplateMetadataService service, AlgoPersistedKey definition) =>
|
||||
service.update_metadata(definition, m => m.with(is_hidden: false));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -69,65 +123,29 @@ namespace bts {
|
||||
|
||||
int IInitializable.priority => int.MaxValue;
|
||||
|
||||
public async Task add_to_favorites(AlgoPersistedKey definition, AlgoPersistedKey template) =>
|
||||
await Task.Run(() => {
|
||||
lock (_data) {
|
||||
if (_data.TryGetValue(definition, out AlgoDefinitionMetadata curr)) {
|
||||
if (curr.favorite_templates.Contains(template))
|
||||
return;
|
||||
_data[definition] = curr.with(favorite_templates: new List<AlgoPersistedKey>(curr.favorite_templates) { template });
|
||||
} else {
|
||||
_data.Add(definition, new AlgoDefinitionMetadata(definition, default, new[] { template }, false));
|
||||
}
|
||||
_publish();
|
||||
}
|
||||
});
|
||||
|
||||
public async Task remove_from_favorites(AlgoPersistedKey definition, AlgoPersistedKey template) =>
|
||||
await Task.Run(() => {
|
||||
lock (_data) {
|
||||
if (_data.TryGetValue(definition, out AlgoDefinitionMetadata curr)) {
|
||||
var favorites = new List<AlgoPersistedKey>(curr.favorite_templates);
|
||||
if (favorites.Remove(template)) {
|
||||
_data[definition] = curr.with(favorite_templates: favorites);
|
||||
_publish();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
public async Task set_as_default(AlgoPersistedKey definition, AlgoPersistedKey template) =>
|
||||
await Task.Run(() => {
|
||||
lock (_data) {
|
||||
_data.AddOrUpdate(definition, d => new AlgoDefinitionMetadata(d, template, null, false), (d, curr) => curr.with(template));
|
||||
_publish();
|
||||
}
|
||||
});
|
||||
|
||||
public async Task hide_definition(AlgoPersistedKey definition) =>
|
||||
await Task.Run(() => {
|
||||
lock (_data) {
|
||||
_data.AddOrUpdate(definition, d => new AlgoDefinitionMetadata(d, default, null, true), (d, curr) => curr.with(is_hidden: true));
|
||||
_publish();
|
||||
}
|
||||
});
|
||||
|
||||
public async Task show_definition(AlgoPersistedKey definition) =>
|
||||
await Task.Run(() => {
|
||||
lock (_data) {
|
||||
_data.AddOrUpdate(definition, d => new AlgoDefinitionMetadata(d, default, null, false), (d, curr) => curr.with(is_hidden: false));
|
||||
_publish();
|
||||
}
|
||||
});
|
||||
|
||||
public IObservable<IReadOnlyDictionary<AlgoPersistedKey, AlgoDefinitionMetadata>> subscribe_metadata() => _subject;
|
||||
|
||||
public IObservable<AlgoDefinitionMetadata> subscribe_metadata(AlgoPersistedKey definition) =>
|
||||
_metadata_demuxer.subscribe(definition);
|
||||
|
||||
public async Task update_metadata(AlgoPersistedKey definition, Func<AlgoDefinitionMetadata, AlgoDefinitionMetadata> update_meta_factory) =>
|
||||
await Task.Run(() => _update_metadata(definition, update_meta_factory));
|
||||
|
||||
void _publish() =>
|
||||
_subject.OnNext(new Dictionary<AlgoPersistedKey, AlgoDefinitionMetadata>(_data));
|
||||
|
||||
void _update_metadata(AlgoPersistedKey definition, Func<AlgoDefinitionMetadata, AlgoDefinitionMetadata> update_meta_factory) {
|
||||
lock (_data) {
|
||||
if (!_data.TryGetValue(definition, out AlgoDefinitionMetadata orig_meta))
|
||||
orig_meta = new AlgoDefinitionMetadata(definition);
|
||||
AlgoDefinitionMetadata new_meta = update_meta_factory(orig_meta);
|
||||
if (new_meta != orig_meta) {
|
||||
_data[definition] = new_meta;
|
||||
_publish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async void IInitializable.initialize() {
|
||||
try {
|
||||
var meta_array = await _persist.get<AlgoDefinitionMetadata[]>(_namespace, _name);
|
||||
|
||||
@@ -57,11 +57,13 @@ namespace mbts.spark {
|
||||
readonly SelectorProperty<TimeInForce> _time_in_force;
|
||||
readonly SelectionModel<AlgoDefinitionVM> _selected_algo_definition;
|
||||
readonly ObservableKeyedCollection<AlgoDefinitionVM, AlgoVMKey> _algo_definitions = new ObservableKeyedCollection<AlgoDefinitionVM, AlgoVMKey>(d => d.vm_key);
|
||||
readonly ListCollectionView<AlgoDefinitionVM> _algo_definitions_view;
|
||||
readonly ListCollectionView<AlgoDefinitionVM> _algo_definitions_view, _favorite_algo_definitions_view;
|
||||
readonly TableUpdateBuffer<AlgoDefinitionData, AlgoPersistedKey> _definitions_buffer = new TableUpdateBuffer<AlgoDefinitionData, AlgoPersistedKey>(d => d.key);
|
||||
readonly EditableCollectionModel<AlgoDefinitionTemplateVM, AlgoDefinitionVM> _algo_template_collection_model;
|
||||
readonly ObservableKeyedCollection<AlgoDefinitionTemplateVM, AlgoVMKey> _favorite_templates = new ObservableKeyedCollection<AlgoDefinitionTemplateVM, AlgoVMKey>(tvm => tvm.vm_key);
|
||||
IReadOnlyDictionary<AlgoPersistedKey, AlgoDefinitionMetadata> _algo_metadata = DictionaryHelper.empty<AlgoPersistedKey, AlgoDefinitionMetadata>();
|
||||
IReadOnlyDictionary<AlgoPersistedKey, int> _favorite_algos_index = DictionaryHelper.empty<AlgoPersistedKey, int>();
|
||||
int _favorite_algos_column_count;
|
||||
|
||||
public OrderPropertiesEditorVM(OrdersModel model, IObservable<SecurityMD> security_md_source, IObservable<InlineOrderProperties> order_properties) {
|
||||
_model = model;
|
||||
@@ -69,6 +71,13 @@ namespace mbts.spark {
|
||||
CustomSort = AlgoDefinitionVMCollectionHelper.default_comparer.to_non_generic()
|
||||
};
|
||||
algo_definitions_view.Filter = d => !(d.vm_key.mode == AlgoVMKey.Mode.Persisted && _algo_metadata.TryGetValue(d.vm_key.persisted_id, out AlgoDefinitionMetadata meta) && meta.is_hidden);
|
||||
_favorite_algo_definitions_view = new ListCollectionView<AlgoDefinitionVM>(_algo_definitions);
|
||||
_favorite_algo_definitions_view.SortDescriptions.Add(new SortDescription(nameof(AlgoDefinitionVM.favorite_index), ListSortDirection.Ascending));
|
||||
_favorite_algo_definitions_view.LiveSortingProperties.Add(nameof(AlgoDefinitionVM.favorite_index));
|
||||
_favorite_algo_definitions_view.IsLiveSorting = true;
|
||||
_favorite_algo_definitions_view.LiveFilteringProperties.Add(nameof(AlgoDefinitionVM.is_favorite));
|
||||
_favorite_algo_definitions_view.IsLiveFiltering = true;
|
||||
favorite_algo_definitions_view.Filter = d => d.is_favorite;
|
||||
var security_source = security_md_source.Select(smd => smd.security);
|
||||
_security = backing(nameof(security), security_source, SecurityDataHelper.Defaults.SecurityImmutable);
|
||||
security_source = _security.observe_current(true);
|
||||
@@ -107,7 +116,7 @@ namespace mbts.spark {
|
||||
save_definition_cmd = new AsyncCommand<AlgoDefinitionVM>(save_definition_async);
|
||||
save_template_cmd = new AsyncCommand<AlgoDefinitionTemplateVM>(save_template_async);
|
||||
remove_template_cmd = new AsyncCommand<AlgoDefinitionTemplateVM>(tvm => _model.algo_model.remove_template(tvm.vm_key.persisted_id));
|
||||
add_to_favorites_cmd = new DelegateCommand<AlgoDefinitionTemplateVM>(tvm => _favorite_templates.Add(tvm));
|
||||
toggle_is_favorite_cmd = new DelegateCommand<AlgoDefinitionTemplateVM>(tvm => _favorite_templates.Add(tvm));
|
||||
_algo_template_collection_model = new EditableCollectionModel<AlgoDefinitionTemplateVM, AlgoDefinitionVM>(d => selected_algo_definition == null ? default : selected_algo_definition.template_factory(), d => d != null);
|
||||
redo_cmd = ObservantCommand.create(
|
||||
t => t?.redo(),
|
||||
@@ -154,7 +163,13 @@ namespace mbts.spark {
|
||||
AlgoDefinitionVMCollectionHelper.update_factory_definitions(_algo_definitions, factory_defs, fd => AlgoDefinitionVM.create_factory_def(_model, fd, nullable_security_md_source));
|
||||
}),
|
||||
model.algo_model.definitions.Subscribe(_definitions_buffer),
|
||||
_definitions_buffer.OnDispatcher().Subscribe(u => AlgoDefinitionVMCollectionHelper.update_persisted_definitions(_algo_definitions, u, d => AlgoDefinitionVM.create_persisted(model, d, nullable_security_md_source, true))),
|
||||
_definitions_buffer.OnDispatcher().Subscribe(u => {
|
||||
AlgoDefinitionVMCollectionHelper.update_persisted_definitions(_algo_definitions, u, def_data => {
|
||||
var def_vm = AlgoDefinitionVM.create_persisted(model, def_data, nullable_security_md_source, true);
|
||||
def_vm.favorite_index = _get_favorite_algo_index(def_vm.vm_key);
|
||||
return def_vm;
|
||||
});
|
||||
}),
|
||||
model.algo_model.metadata_service.subscribe_metadata().OnDispatcher().Subscribe(_on_template_metadata)) {
|
||||
() => {
|
||||
Disposable.dispose(ref _template_collection_sync);
|
||||
@@ -181,6 +196,7 @@ namespace mbts.spark {
|
||||
}
|
||||
if (reason == SelectionReason.UserSelectedNewValue && new_value?.algo_root is IOrderTypeVM ar && ar.has_editable_properties) {
|
||||
ar.editable_properties_open = true;
|
||||
RaisePropertyChanged(nameof(selected_favorite_algo_definition));
|
||||
}
|
||||
if (selected_algo_template == null) {
|
||||
if (new_value != null)
|
||||
@@ -199,14 +215,21 @@ namespace mbts.spark {
|
||||
public ReadOnlyObservableCollection<TimeInForce> time_in_forces => _time_in_force.items;
|
||||
public TimeInForce selected_time_in_force { get => _time_in_force.selected_item; set => _time_in_force.selected_item = value; }
|
||||
public CustomOrderDefinitionImmutable? definition => selected_algo_template?.algo_root is IOrderTypeVM vm ? vm.createi() : (CustomOrderDefinitionImmutable?)null;
|
||||
public int favorite_algos_column_count { get => _favorite_algos_column_count; private set => Set(ref _favorite_algos_column_count, value); }
|
||||
// items sources
|
||||
public ObservableCollection<AlgoDefinitionVM> algo_definitions => _algo_definitions;
|
||||
public ObservableCollection<AlgoDefinitionTemplateVM> algo_templates { get; } = new ObservableCollection<AlgoDefinitionTemplateVM>();
|
||||
public ICollectionView<AlgoDefinitionVM> algo_definitions_view => _algo_definitions_view;
|
||||
public ICollectionView<AlgoDefinitionVM> favorite_algo_definitions_view => _favorite_algo_definitions_view;
|
||||
public ICollectionView algo_templates_view { get; }
|
||||
public ICollectionView favorite_algo_templates_view { get; }
|
||||
// selected items
|
||||
public AlgoDefinitionVM selected_algo_definition { get => _selected_algo_definition.selected_item; set => _selected_algo_definition.selected_item = value; }
|
||||
public AlgoDefinitionVM selected_algo_definition {
|
||||
get => _selected_algo_definition.selected_item;
|
||||
set {
|
||||
_selected_algo_definition.selected_item = value;
|
||||
}
|
||||
}
|
||||
public AlgoDefinitionTemplateVM selected_algo_template {
|
||||
get => selected_algo_definition?.selected_template;
|
||||
set {
|
||||
@@ -237,6 +260,14 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
}
|
||||
public AlgoDefinitionVM selected_favorite_algo_definition {
|
||||
get => selected_algo_definition?.is_favorite ?? false ? selected_algo_definition : null;
|
||||
set {
|
||||
if (value != null)
|
||||
_selected_algo_definition.select_explicit(value);
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
public bool has_editable_properties => selected_algo_definition?.algo_root?.has_editable_properties ?? false;
|
||||
public bool editable_properties_open {
|
||||
get => selected_algo_definition?.algo_root?.editable_properties_open ?? false;
|
||||
@@ -258,7 +289,7 @@ namespace mbts.spark {
|
||||
public ICommand undo_definition_cmd { get; }
|
||||
public ICommand redo_definition_cmd { get; }
|
||||
public ICommand remove_template_cmd { get; }
|
||||
public ICommand add_to_favorites_cmd { get; }
|
||||
public ICommand toggle_is_favorite_cmd { get; }
|
||||
public IEditableCollectionModel<AlgoDefinitionTemplateVM> algo_template_collection_model => _algo_template_collection_model;
|
||||
|
||||
public IObservable<AccountTuple?> observe_account(bool start_immediately = false) =>
|
||||
@@ -283,6 +314,16 @@ namespace mbts.spark {
|
||||
public OrderMetadata get_metadata(CustomOrderDefinition.CustomOneofCase order_type) =>
|
||||
_model.factory.get_metadata(order_type);
|
||||
|
||||
public void on_favorite_algos(LadderFavoriteAlgosSettings value) {
|
||||
_favorite_algos_index = value.favorite_algos.Select((v, i) => (v, i)).ToDictionaryCrushed(t => t.v, t => t.i);
|
||||
foreach (var d in algo_definitions)
|
||||
d.favorite_index = _get_favorite_algo_index(d.vm_key);
|
||||
favorite_algos_column_count = value.column_count;
|
||||
}
|
||||
|
||||
int? _get_favorite_algo_index(AlgoVMKey vm_key) =>
|
||||
vm_key.mode == AlgoVMKey.Mode.Persisted && _favorite_algos_index.TryGetValue(vm_key.persisted_id, out int i) ? i : (int?)null;
|
||||
|
||||
void _on_template_metadata(IReadOnlyDictionary<AlgoPersistedKey, AlgoDefinitionMetadata> meta) {
|
||||
_algo_metadata = meta;
|
||||
var curr_selected_template = selected_algo_template;
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
||||
namespace mbts.collections {
|
||||
class ObservableKeyedCollection<T, TKey> : ObservableCollection<T>, IDictionary<TKey, T> {
|
||||
class ObservableKeyedCollection<T, TKey> : ObservableCollection<T>, ui.utility.IObservableCollection<T>, IDictionary<TKey, T> {
|
||||
const string _indexer_name = "Item[]";
|
||||
readonly Func<T, TKey> _key;
|
||||
readonly Dictionary<TKey, T> _map;
|
||||
|
||||
@@ -210,6 +210,13 @@ namespace System.Collections.Generic {
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static Dictionary<TKey, TElement> ToDictionaryCrushed<T, TKey, TElement>(this IEnumerable<T> source, Func<T, TKey> key_selector, Func<T, TElement> element_selector) {
|
||||
var rv = new Dictionary<TKey, TElement>();
|
||||
foreach (T v in source)
|
||||
rv[key_selector(v)] = element_selector(v);
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static ReadOnlyDictionary<TKey, T> ToReadOnlyDictionary<T, TKey>(this IEnumerable<T> enumerable, Func<T, TKey> key_selector) =>
|
||||
new ReadOnlyDictionary<TKey, T>(enumerable.ToDictionary(key_selector));
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace mbts.utils {
|
||||
public EditStack(IEqualityComparer<T> comparer) =>
|
||||
_comparer = comparer;
|
||||
|
||||
public int size => _log.Count;
|
||||
/// This value represents the index where the next 'pushed' item will go (<see cref="push(T)"/>).
|
||||
public int pos { get; private set; }
|
||||
public bool can_undo => pos > 0;
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
namespace mbts.utils {
|
||||
class VersionContainer<T> {
|
||||
readonly Func<T> _get_value;
|
||||
ulong _version, _last_read;
|
||||
ulong _version, _last_read = ulong.MaxValue;
|
||||
T _last_value;
|
||||
|
||||
public VersionContainer(Func<T> get_value) =>
|
||||
_last_value = (_get_value = get_value)();
|
||||
_get_value = get_value;
|
||||
|
||||
public T value {
|
||||
get {
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock
|
||||
x:Name="name_text"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
Text="{Binding abbreviation}"
|
||||
@@ -68,7 +69,10 @@
|
||||
<Setter Property="Opacity" Value="1"/>
|
||||
<Setter TargetName="_checkmark" Property="Visibility" Value="Visible"/>
|
||||
</Trigger>
|
||||
<DataTrigger Binding="{Binding is_edited}" Value="True">
|
||||
<DataTrigger Binding="{Binding abbreviation, Converter={StaticResource StringIsNullOrEmptyConverter}}" Value="{u:True}">
|
||||
<Setter TargetName="name_text" Property="Text" Value="{Binding name}"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding is_dirty}" Value="True">
|
||||
<Setter Property="BorderBrush" Value="{u:BTSColor UI.input_dirty_border}"/>
|
||||
</DataTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
@@ -81,12 +85,5 @@
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
<Setter Property="Focusable" Value="False"/>
|
||||
<Setter Property="ItemContainerStyle" Value="{StaticResource AlgoFavoriteItemContainerStyle}"/>
|
||||
<Setter Property="ItemsPanel">
|
||||
<Setter.Value>
|
||||
<ItemsPanelTemplate>
|
||||
<UniformGrid Columns="2" Focusable="False"/>
|
||||
</ItemsPanelTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
@@ -190,9 +190,8 @@
|
||||
<MenuItem
|
||||
x:Name="PART_IsFavorite_MenuItem"
|
||||
u:Behavior.AutoRaiseCanExecuteChanged="True"
|
||||
Command="{x:Static uag:AlgoTemplateToolBar.BeginToggleFavoriteCommand}"
|
||||
CommandParameter="{Binding SelectedItem, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
|
||||
Command="{TemplateBinding ToggleFavoriteCommand}"
|
||||
CommandParameter="{Binding ToggleFavoriteCommandParameter, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
Style="{StaticResource AlgoMenuItem}"
|
||||
ToolTip="{x:Static uag:AlgoTemplateToolBar.AddToFavoritesToolTip}"
|
||||
>
|
||||
@@ -238,6 +237,9 @@
|
||||
<Setter TargetName="PART_Undo_MenuItem" Property="Visibility" Value="Collapsed"/>
|
||||
<Setter TargetName="PART_Redo_MenuItem" Property="Visibility" Value="Collapsed"/>
|
||||
</Trigger>
|
||||
<Trigger Property="ShowToggleFavorite" Value="False">
|
||||
<Setter TargetName="PART_IsFavorite_MenuItem" Property="Visibility" Value="Collapsed"/>
|
||||
</Trigger>
|
||||
<DataTrigger Binding="{Binding SelectedItem.is_favorite, RelativeSource={RelativeSource Self}, FallbackValue={u:False}}" Value="{u:True}">
|
||||
<Setter TargetName="_favorite_image" Property="Source" Value="{u:Icon Star, Brush=Gold, Pen={u:Pen Black, Thickness=3}}"/>
|
||||
<Setter TargetName="PART_IsFavorite_MenuItem" Property="ToolTip" Value="{x:Static uag:AlgoTemplateToolBar.RemoveFromFavoritesToolTip}"/>
|
||||
|
||||
@@ -54,10 +54,7 @@ namespace mbts.ui.spark.algo {
|
||||
BeginRedoDefinitionExecuted = WPFHelper.create_cmd_executed<object, AlgoTemplateToolBar>((tb, _) => tb._redo_definition()),
|
||||
BeginUndoDefinitionExecuted = WPFHelper.create_cmd_executed<object, AlgoTemplateToolBar>((tb, _) => tb._undo_definition()),
|
||||
BeginRemoveExecuted = WPFHelper.create_cmd_executed<object, AlgoTemplateToolBar>((tb, t) => tb._remove(t)),
|
||||
BeginToggleFavoriteExecuted = WPFHelper.create_cmd_executed<object, AlgoTemplateToolBar>((tb, param) => {
|
||||
if (param is AlgoDefinitionTemplateVM t)
|
||||
t.is_favorite = !t.is_favorite;
|
||||
});
|
||||
BeginToggleFavoriteExecuted = WPFHelper.create_cmd_executed<object, AlgoTemplateToolBar>((tb, param) => tb.ToggleFavoriteCommand.TryExecuteIfCan(param));
|
||||
|
||||
ComboBox _templates_combo;
|
||||
EditableTextBlock _definition_name_text;
|
||||
@@ -74,6 +71,12 @@ namespace mbts.ui.spark.algo {
|
||||
public bool ShowTemplatesDropDown { get => (bool)GetValue(ShowTemplatesDropDownProperty); set => SetValue(ShowTemplatesDropDownProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region ShowToggleFavorite
|
||||
public static readonly DependencyProperty ShowToggleFavoriteProperty =
|
||||
WPFHelper.create_dp<bool, AlgoTemplateToolBar>(nameof(ShowToggleFavorite));
|
||||
public bool ShowToggleFavorite { get => (bool)GetValue(ShowToggleFavoriteProperty); set => SetValue(ShowToggleFavoriteProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region ShowDefinitionName
|
||||
public static readonly DependencyProperty ShowDefinitionNameProperty =
|
||||
WPFHelper.create_dp<bool, AlgoTemplateToolBar>(nameof(ShowDefinitionName));
|
||||
@@ -191,6 +194,18 @@ namespace mbts.ui.spark.algo {
|
||||
public ICommand RedoDefinitionCommand { get => GetValue(RedoDefinitionCommandProperty) as ICommand; set => SetValue(RedoDefinitionCommandProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region ToggleFavorite
|
||||
public static readonly DependencyProperty ToggleFavoriteCommandProperty =
|
||||
WPFHelper.create_dp<ICommand, AlgoTemplateToolBar>(nameof(ToggleFavoriteCommand));
|
||||
public ICommand ToggleFavoriteCommand { get => GetValue(ToggleFavoriteCommandProperty) as ICommand; set => SetValue(ToggleFavoriteCommandProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region ToggleFavorite Parameter
|
||||
public static readonly DependencyProperty ToggleFavoriteCommandParameterProperty =
|
||||
WPFHelper.create_dp<object, AlgoTemplateToolBar>(nameof(ToggleFavoriteCommandParameter));
|
||||
public object ToggleFavoriteCommandParameter { get => GetValue(ToggleFavoriteCommandParameterProperty); set => SetValue(ToggleFavoriteCommandParameterProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region IsEdited
|
||||
/// <summary>
|
||||
/// This property indicates whether or not the order definition held by the <see cref="SelectedItem"/> is 'dirty' - different from the one that would be created by the OrderPropertiesEditor at this time.
|
||||
|
||||
@@ -110,6 +110,7 @@
|
||||
RedoDefinitionCommand="{Binding redo_definition_cmd}"
|
||||
SaveCommand="{Binding save_template_cmd}"
|
||||
SaveDefinitionCommand="{Binding save_definition_cmd}"
|
||||
ToggleFavoriteCommand="{Binding toggle_favorite_cmd}"
|
||||
SelectedItem="{Binding selected_algo_template, Mode=TwoWay}"
|
||||
ItemContainerStyle="{StaticResource AlgoTemplateItemContainerStyle}"
|
||||
>
|
||||
@@ -143,7 +144,6 @@
|
||||
<CommandBinding Command="{x:Static uag:AlgoTemplateToolBar.BeginRevertCommand}" Executed="{x:Static uag:AlgoTemplateToolBar.BeginRevertExecuted}"/>
|
||||
<CommandBinding Command="{x:Static uag:AlgoTemplateToolBar.BeginRevertDefinitionCommand}" Executed="{x:Static uag:AlgoTemplateToolBar.BeginRevertDefinitionExecuted}"/>
|
||||
<CommandBinding Command="{x:Static uag:AlgoTemplateToolBar.BeginRemoveCommand}" Executed="{x:Static uag:AlgoTemplateToolBar.BeginRemoveExecuted}"/>
|
||||
<CommandBinding Command="{x:Static uag:AlgoTemplateToolBar.BeginToggleFavoriteCommand}" Executed="{x:Static uag:AlgoTemplateToolBar.BeginToggleFavoriteExecuted}"/>
|
||||
</uag:AlgoTemplateToolBar.CommandBindings>
|
||||
</uag:AlgoTemplateToolBar>
|
||||
<ContentControl
|
||||
|
||||
@@ -70,6 +70,10 @@
|
||||
<cv:ValueMap x:Key="IsNullConverter" Default="{u:False}">
|
||||
<cv:KeyValue Key="{x:Null}" Value="{u:True}"/>
|
||||
</cv:ValueMap>
|
||||
<cv:ValueMap x:Key="StringIsNullOrEmptyConverter" Default="{u:False}">
|
||||
<cv:KeyValue Key="{x:Null}" Value="{u:True}"/>
|
||||
<cv:KeyValue Key="{x:Static sys:String.Empty}" Value="{u:True}"/>
|
||||
</cv:ValueMap>
|
||||
<uspcv:TickDisplayConverter x:Key="TickDisplayConverter"/>
|
||||
<cv:ImageSourceIconConverter x:Key="IconConverter"/>
|
||||
<sys:Int32 x:Key="IntZero">0</sys:Int32>
|
||||
|
||||
@@ -174,6 +174,36 @@ namespace mbts.spark {
|
||||
(int)color;
|
||||
}
|
||||
|
||||
[ProtoContract]
|
||||
struct LadderFavoriteAlgosSettings : IEquatable<LadderFavoriteAlgosSettings> {
|
||||
[ProtoMember(1)]
|
||||
readonly AlgoPersistedKey[] _favorite_algos;
|
||||
[ProtoMember(2)]
|
||||
public readonly int column_count;
|
||||
|
||||
public LadderFavoriteAlgosSettings(AlgoPersistedKey[] favorite_algos, int column_count) {
|
||||
_favorite_algos = favorite_algos;
|
||||
this.column_count = column_count;
|
||||
}
|
||||
|
||||
public IReadOnlyList<AlgoPersistedKey> favorite_algos => _favorite_algos ?? Array.Empty<AlgoPersistedKey>();
|
||||
|
||||
public bool Equals(LadderFavoriteAlgosSettings other) =>
|
||||
column_count == other.column_count &&
|
||||
favorite_algos.SequenceEqual(other.favorite_algos);
|
||||
|
||||
public override bool Equals(object obj) =>
|
||||
EqualityComparer.equals_obj(this, obj);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
EqualityComparer.aggregate_hash(
|
||||
column_count,
|
||||
EqualityComparer.aggregate_hash_limited(favorite_algos));
|
||||
|
||||
public static bool operator ==(LadderFavoriteAlgosSettings a, LadderFavoriteAlgosSettings b) => a.Equals(b);
|
||||
public static bool operator !=(LadderFavoriteAlgosSettings a, LadderFavoriteAlgosSettings b) => !a.Equals(b);
|
||||
}
|
||||
|
||||
// IMPORTANT: BE SURE TO ADD ANY NEW PROPERTIES TO THE EQUALS FUNCTION!
|
||||
// 1 important reason at this time:
|
||||
// From the settings dialog, default settings will only be persisted when they are NOT EQUAL to the current default settings.
|
||||
@@ -206,6 +236,7 @@ namespace mbts.spark {
|
||||
order_entry_panel_initial_width = _default_order_entry_panel_width;
|
||||
zoom_factor = _default_zoom_factor;
|
||||
use_defaults = true;
|
||||
favorite_algos = new LadderFavoriteAlgosSettings(null, 2);
|
||||
}
|
||||
|
||||
public static LadderSettings Default {
|
||||
@@ -374,6 +405,9 @@ namespace mbts.spark {
|
||||
[ProtoMember(46), DefaultValue(_default_zoom_factor)]
|
||||
public double zoom_factor { get; set; }
|
||||
|
||||
[ProtoMember(47)]
|
||||
public LadderFavoriteAlgosSettings favorite_algos { get; set; }
|
||||
|
||||
public bool Equals(LadderSettings other) =>
|
||||
other != null &&
|
||||
row_height == other.row_height &&
|
||||
@@ -418,7 +452,8 @@ namespace mbts.spark {
|
||||
order_entry_panel_initial_width == other.order_entry_panel_initial_width &&
|
||||
zoom_slider_visible == other.zoom_slider_visible &&
|
||||
zoom_factor == other.zoom_factor &&
|
||||
use_defaults == other.use_defaults;
|
||||
use_defaults == other.use_defaults &&
|
||||
favorite_algos == other.favorite_algos;
|
||||
|
||||
public override bool Equals(object obj) => Equals(obj as LadderSettings);
|
||||
|
||||
@@ -466,7 +501,8 @@ namespace mbts.spark {
|
||||
order_entry_panel_initial_width.GetHashCode(),
|
||||
zoom_slider_visible.GetHashCode(),
|
||||
zoom_factor.GetHashCode(),
|
||||
use_defaults.GetHashCode());
|
||||
use_defaults.GetHashCode(),
|
||||
favorite_algos.GetHashCode());
|
||||
|
||||
public struct WindowSpecifics {
|
||||
public readonly double order_entry_panel_width, zoom_factor;
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
using bts.api;
|
||||
using bts.utils;
|
||||
using mbts.collections;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.controls.color_picker;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.spark;
|
||||
using mbts.ui.utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using TextUtils = mbts.ui.utility.text.TextUtils;
|
||||
|
||||
namespace mbts.spark {
|
||||
class LadderSettingsVM : ViewModelBase, IWindowSettingsVM<LadderSettings>, ITemplateSelectorKey {
|
||||
class LadderSettingsVM : ViewModelBase, IWindowSettingsVM<LadderSettings>, ITemplateSelectorKey, IDisposable {
|
||||
readonly Property<LadderSettings.BadgeStyle> _badge_style;
|
||||
readonly Property<uint> _alternate_order_size;
|
||||
readonly DelegateProperty<double> _row_height;
|
||||
@@ -52,8 +57,9 @@ namespace mbts.spark {
|
||||
_cancel_sells_visibility = new OrderEntryPanelItemVisibilityVM("Cancel Sells"),
|
||||
_cancel_all_visibility = new OrderEntryPanelItemVisibilityVM("Cancel All");
|
||||
|
||||
public LadderSettingsVM(bool is_synthetic, Func<double> get_left_panel_width, Func<double> get_zoom_factor) {
|
||||
public LadderSettingsVM(OrdersModel model, bool is_synthetic, Func<double> get_left_panel_width, Func<double> get_zoom_factor) {
|
||||
this.is_synthetic = is_synthetic;
|
||||
favorite_algos_vm = new FavoriteAlgosVM(model);
|
||||
size_presets = new ObservableEditableCollection<IMutableValueWrapperVM<uint>>(_create_size_preset_vm);
|
||||
size_presets.CollectionChanged += (s, e) => RaisePropertyChanged(nameof(size_presets_text));
|
||||
_badge_style = backing<LadderSettings.BadgeStyle>(nameof(badge_style));
|
||||
@@ -91,6 +97,7 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
public MarketSizeDisplayVM size_display { get; } = new MarketSizeDisplayVM();
|
||||
public FavoriteAlgosVM favorite_algos_vm { get; }
|
||||
|
||||
public double row_height => _row_height.Value;
|
||||
public bool is_synthetic { get; }
|
||||
@@ -158,6 +165,7 @@ namespace mbts.spark {
|
||||
_current = settings;
|
||||
badge_style = settings.badge_style;
|
||||
alternate_order_size = settings.alternate_order_size;
|
||||
favorite_algos_vm.load_from(settings.favorite_algos);
|
||||
size_display.load_from(settings.size_display);
|
||||
size_presets.SetItems(settings.calculator_buttons.empty_if_null().Select(s => _create_size_preset_vm((uint)s)));
|
||||
_orders.assign_from(_current.orders_column);
|
||||
@@ -199,6 +207,7 @@ namespace mbts.spark {
|
||||
var clone = SparkUtils.clone_proto(_current);
|
||||
clone.badge_style = badge_style;
|
||||
clone.alternate_order_size = alternate_order_size;
|
||||
clone.favorite_algos = favorite_algos_vm.create();
|
||||
clone.size_display = size_display.create();
|
||||
clone.calculator_buttons = size_presets.Select(vm => (int)vm.value).ToArray();
|
||||
clone.orders_column = _orders.get_settings();
|
||||
@@ -236,6 +245,8 @@ namespace mbts.spark {
|
||||
return clone;
|
||||
}
|
||||
|
||||
public void Dispose() => favorite_algos_vm.Dispose();
|
||||
|
||||
IMutableValueWrapperVM<uint> _create_size_preset_vm() => _create_size_preset_vm(0);
|
||||
IMutableValueWrapperVM<uint> _create_size_preset_vm(uint init) {
|
||||
var vm = PropertyWrapperVMUtils.create_mutable_vm(init);
|
||||
@@ -486,5 +497,64 @@ namespace mbts.spark {
|
||||
show_numbers = show_numbers
|
||||
};
|
||||
}
|
||||
|
||||
public class FavoriteAlgosVM : DisposableViewModelBase, IValueFactoryVM<LadderFavoriteAlgosSettings> {
|
||||
readonly ObservableKeyedCollection<AlgoDefinitionVM, AlgoVMKey> _algo_definitions = new ObservableKeyedCollection<AlgoDefinitionVM, AlgoVMKey>(d => d.vm_key);
|
||||
readonly ObservableCollection<FavoriteAlgoItem> _raw_items = new ObservableCollection<FavoriteAlgoItem>();
|
||||
int _column_count = 2;
|
||||
|
||||
public FavoriteAlgosVM(OrdersModel model) {
|
||||
items = new ObservableAggregateCollection<FavoriteAlgoItem>(_raw_items, new ObservableCollection<FavoriteAlgoItem> { FavoriteAlgoItem.AddButtonPlaceholderItem });
|
||||
add_item_cmd = new DelegateCommand(() => _raw_items.Add(_item_factory()));
|
||||
remove_item_cmd = new DelegateCommand<FavoriteAlgoItem>(fai => _raw_items.Remove(fai));
|
||||
_dispose = model.algo_model.definitions.OnDispatcher().Subscribe(update => {
|
||||
AlgoDefinitionVMCollectionHelper.update_persisted_definitions(_algo_definitions, update, d => AlgoDefinitionVM.create_persisted(model, d, Observable.Return<SecurityMD?>(null), false));
|
||||
});
|
||||
}
|
||||
|
||||
public ObservableCollection<FavoriteAlgoItem> items { get; }
|
||||
public ICommand add_item_cmd { get; }
|
||||
public ICommand remove_item_cmd { get; }
|
||||
public int column_count { get => _column_count; set => Set(ref _column_count, value); }
|
||||
public ObservableCollection<int> column_count_options { get; } = new ObservableCollection<int>(Enumerable.Range(1, 4));
|
||||
|
||||
public void load_from(LadderFavoriteAlgosSettings value) {
|
||||
_raw_items.Clear();
|
||||
column_count = value.column_count;
|
||||
_raw_items.AddRange(value.favorite_algos.Select(k => {
|
||||
var fai = _item_factory();
|
||||
fai.selector.try_select(new AlgoVMKey(k));
|
||||
return fai;
|
||||
}));
|
||||
}
|
||||
|
||||
public LadderFavoriteAlgosSettings create() =>
|
||||
new LadderFavoriteAlgosSettings(_raw_items.Where(fai => fai.algo_definition != null).Select(fai => fai.algo_definition.vm_key.persisted_id).ToArray(), column_count);
|
||||
|
||||
FavoriteAlgoItem _item_factory() =>
|
||||
new FavoriteAlgoItem(_algo_definitions, new ListCollectionView<AlgoDefinitionVM>(_algo_definitions) {
|
||||
CustomSort = AlgoDefinitionVMCollectionHelper.default_comparer.to_non_generic()
|
||||
});
|
||||
}
|
||||
|
||||
public class FavoriteAlgoItem : ViewModelBase {
|
||||
public static readonly FavoriteAlgoItem AddButtonPlaceholderItem = new _AddButtonPlaceholderItem();
|
||||
|
||||
internal readonly KeyedItemSelector<AlgoDefinitionVM, AlgoVMKey> selector;
|
||||
|
||||
protected FavoriteAlgoItem() { }
|
||||
|
||||
public FavoriteAlgoItem(ObservableKeyedCollection<AlgoDefinitionVM, AlgoVMKey> algo_definitions, ICollectionView<AlgoDefinitionVM> algo_definitions_view) {
|
||||
selector = new KeyedItemSelector<AlgoDefinitionVM, AlgoVMKey>(this, nameof(algo_definition), algo_definitions, d => d.vm_key);
|
||||
this.algo_definitions_view = algo_definitions_view;
|
||||
}
|
||||
|
||||
public ICollectionView<AlgoDefinitionVM> algo_definitions_view { get; }
|
||||
public AlgoDefinitionVM algo_definition { get => selector.value; set => selector.value = value; }
|
||||
|
||||
class _AddButtonPlaceholderItem : FavoriteAlgoItem, ITemplateSelectorKey {
|
||||
public string key => LadderSettingsView.FavoriteAlgoAddButtonTemplateKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@
|
||||
<sys:Double x:Key="CollapsedSizePresetsHeight">24</sys:Double>
|
||||
<Thickness x:Key="MarginLPush" Left="{StaticResource HorizontalPush}"/>
|
||||
<Thickness x:Key="MarginIndentChild" Left="{StaticResource IndentChild}"/>
|
||||
<Thickness x:Key="Margin.UP1" Left="{StaticResource HorizontalPush}" Top="{StaticResource VerticalPush}" Right="{StaticResource HorizontalPush}" Bottom="{StaticResource VerticalPush}"/>
|
||||
<cv:ValueMap x:Key="ColumnSpanToVisibilityConverter" Default="{u:Visibility Visible}">
|
||||
<cv:KeyValue Key="{u:Int 0}" Value="{u:Visibility Collapsed}"/>
|
||||
</cv:ValueMap>
|
||||
@@ -597,6 +598,63 @@
|
||||
</Button>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
<!-- Algo Favorites-->
|
||||
<TabItem Header="Algo Favorites" VerticalAlignment="Stretch">
|
||||
<Grid HorizontalAlignment="Left" Margin="{StaticResource Margin.UP1}" DataContext="{Binding favorite_algos_vm}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalPush}}"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush}}"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock VerticalAlignment="Center">Number of Columns</TextBlock>
|
||||
<ComboBox Grid.Column="2" HorizontalAlignment="Stretch" ItemsSource="{Binding column_count_options}" SelectedItem="{Binding column_count}"/>
|
||||
<ItemsControl Grid.Row="2" Grid.ColumnSpan="3" Grid.IsSharedSizeScope="True" ItemsSource="{Binding items}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<UniformGrid Columns="{Binding column_count}"/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplateSelector>
|
||||
<u:KeyedTemplateSelector>
|
||||
<u:KeyedTemplateSelector.Default>
|
||||
<DataTemplate>
|
||||
<Grid Margin="2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="c0"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Button Command="{Binding DataContext.remove_item_cmd, RelativeSource={RelativeSource AncestorType=ItemsControl}}" CommandParameter="{Binding}" Style="{StaticResource RoundCloseButton}"/>
|
||||
<ComboBox Grid.Column="1" ItemsSource="{Binding algo_definitions_view}" SelectedItem="{Binding algo_definition}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<usp:OrderTypeItem OrderType="{Binding algo_root.order_type}" DisplayName="{Binding name}" Metadata="{Binding algo_root.meta}"/>
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</u:KeyedTemplateSelector.Default>
|
||||
<u:TemplateSelectorKeyValue Key="{x:Static usp:LadderSettingsView.FavoriteAlgoAddButtonTemplateKey}">
|
||||
<DataTemplate>
|
||||
<Grid Margin="2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="c0"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Button Grid.Column="1" HorizontalAlignment="Stretch" Command="{Binding DataContext.add_item_cmd, RelativeSource={RelativeSource AncestorType=ItemsControl}}">Add</Button>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</u:TemplateSelectorKeyValue>
|
||||
</u:KeyedTemplateSelector>
|
||||
</ItemsControl.ItemTemplateSelector>
|
||||
</ItemsControl>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
<!-- Order Entry Panel Item Control Visbility -->
|
||||
<TabItem Header="Left Panel" VerticalAlignment="Stretch">
|
||||
<Grid HorizontalAlignment="Left" Grid.IsSharedSizeScope="True">
|
||||
|
||||
@@ -11,7 +11,8 @@ namespace mbts.ui.spark {
|
||||
partial class LadderSettingsView : UserControl {
|
||||
public const string
|
||||
OrdersColumnSampleTemplateKey = nameof(OrdersColumnSampleTemplateKey),
|
||||
ColumnVisibilityToggleTemplateKey = nameof(ColumnVisibilityToggleTemplateKey);
|
||||
ColumnVisibilityToggleTemplateKey = nameof(ColumnVisibilityToggleTemplateKey),
|
||||
FavoriteAlgoAddButtonTemplateKey = nameof(FavoriteAlgoAddButtonTemplateKey);
|
||||
|
||||
public LadderSettingsView() =>
|
||||
InitializeComponent();
|
||||
|
||||
@@ -105,10 +105,10 @@ namespace mbts.spark {
|
||||
show_book_command = new DelegateCommand(_show_book);
|
||||
show_ticket_command = new DelegateCommand(_show_ticket);
|
||||
settings_command = new DialogCommand(() => {
|
||||
var vm = new WindowSettingsDialogVM<LadderSettings, LadderSettingsVM>(
|
||||
var vm = new WindowSettingsDialogVM<LadderSettings, LadderSettingsVM>(
|
||||
settings_manager, s => s.ladder, UserSettings.FileExtensions.LADDER,
|
||||
s => {
|
||||
var svm = new LadderSettingsVM(security.ContractCase == Security.ContractOneofCase.Synthetic, () => left_panel_width, () => zoom_factor);
|
||||
var svm = new LadderSettingsVM(model.order_gateway, security.ContractCase == Security.ContractOneofCase.Synthetic, () => left_panel_width, () => zoom_factor);
|
||||
svm.load(s);
|
||||
return svm;
|
||||
}, s => s.with_window_specifics(get_save_state().get_window_specifics()));
|
||||
@@ -125,6 +125,7 @@ namespace mbts.spark {
|
||||
_dispose = Disposable.Create(
|
||||
settings_command,
|
||||
non_shared_wsm,
|
||||
settings.OnDispatcher().Subscribe(s => order_properties_vm.on_favorite_algos(s.favorite_algos)),
|
||||
order_properties_vm,
|
||||
order_properties_vm.observe_account(true).Select(a => a?.name ?? string.Empty).Subscribe(account_positions),
|
||||
account_positions,
|
||||
|
||||
@@ -483,9 +483,15 @@
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<uag:AlgoTemplateFavoriteButtonsView
|
||||
ItemsSource="{Binding order_properties_vm.favorite_algo_templates_view}"
|
||||
SelectedItem="{Binding order_properties_vm.selected_favorite_algo_template}"
|
||||
/>
|
||||
ItemsSource="{Binding order_properties_vm.favorite_algo_definitions_view}"
|
||||
SelectedItem="{Binding order_properties_vm.selected_favorite_algo_definition}"
|
||||
>
|
||||
<uag:AlgoTemplateFavoriteButtonsView.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<UniformGrid Columns="{Binding order_properties_vm.favorite_algos_column_count}" Focusable="False"/>
|
||||
</ItemsPanelTemplate>
|
||||
</uag:AlgoTemplateFavoriteButtonsView.ItemsPanel>
|
||||
</uag:AlgoTemplateFavoriteButtonsView>
|
||||
<!-- Clear button -->
|
||||
<Button Margin="2" HorizontalAlignment="Stretch" Command="{Binding size_calculator.clear}"
|
||||
Visibility="{Binding show_clear, Converter={StaticResource BooleanToVisibilityConverter}}">Clear</Button>
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace mbts.spark {
|
||||
T get_result();
|
||||
}
|
||||
|
||||
class WindowSettingsDialogVM<T, TVM> : ViewModelBase, IRequestViewClose where T : class, IEquatable<T> where TVM : IWindowSettingsVM<T> {
|
||||
class WindowSettingsDialogVM<T, TVM> : ViewModelBase, IRequestViewClose, IDisposable where T : class, IEquatable<T> where TVM : IWindowSettingsVM<T> {
|
||||
readonly Property<bool> _use_default;
|
||||
readonly DialogSkirtItem _ok_item, _apply_item, _cancel_item, _apply_to_defaults_item;
|
||||
readonly DelegateProperty<IEnumerable<DialogSkirtItem>> _left_skirt_items;
|
||||
|
||||
@@ -98,6 +98,9 @@ namespace bts.utils {
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static int aggregate_hash_limited<T>(IReadOnlyList<T> items, int max_count = 16) =>
|
||||
items.Count < max_count ? aggregate_hash(items) : items.Count;
|
||||
|
||||
// WARNING: be sure to call this within in an unchecked scope
|
||||
static void _accumulate_hash(ref int aggregate_hash, ref int item_hash) =>
|
||||
aggregate_hash = aggregate_hash * _hash_multiplier + item_hash;
|
||||
|
||||
@@ -43,6 +43,13 @@ namespace bts.collections {
|
||||
list.RemoveAt(index);
|
||||
}
|
||||
|
||||
public static int IndexOf<T>(IReadOnlyList<T> list, T value) {
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
if (value.Equals(list[i]))
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
class SubRangeWrapper<T> : IList<T>, IReadOnlyList<T> {
|
||||
readonly IList<T> _source;
|
||||
readonly int _start;
|
||||
|
||||
@@ -31,5 +31,29 @@ namespace bts.utils {
|
||||
Array.Copy(array, rv, array.Length);
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static T[] remove<T>(T[] source, T value) {
|
||||
int i = Array.IndexOf(source, value);
|
||||
return i < 0 ? source : remove_at(source, i);
|
||||
}
|
||||
|
||||
public static T[] remove_at<T>(T[] array, int index) {
|
||||
T[] clone = new T[array.Length - 1];
|
||||
Array.Copy(array, 0, clone, 0, index);
|
||||
Array.Copy(array, index + 1, clone, index, clone.Length - index);
|
||||
return clone;
|
||||
}
|
||||
|
||||
public static T[] add<T>(T[] array, T value) {
|
||||
T[] clone = new T[array.Length + 1];
|
||||
Array.Copy(array, clone, array.Length);
|
||||
clone[array.Length] = value;
|
||||
return clone;
|
||||
}
|
||||
|
||||
public static T[] add_distinct<T>(T[] array, T value) {
|
||||
int i = Array.IndexOf(array, value);
|
||||
return i < 0 ? add(array, value) : array;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace bts.utils {
|
||||
public static class ListUtils {
|
||||
public static IReadOnlyList<T> add<T>(IReadOnlyList<T> list, T value) {
|
||||
var clone = new T[list.Count + 1];
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
clone[i] = list[i];
|
||||
clone[list.Count] = value;
|
||||
return clone;
|
||||
}
|
||||
|
||||
public static IReadOnlyList<T> add_distinct<T>(IReadOnlyList<T> list, T value) {
|
||||
int i = index_of(list, value);
|
||||
return i >= 0 ? list : add(list, value);
|
||||
}
|
||||
|
||||
public static int index_of<T>(IReadOnlyList<T> list, T value) {
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
if (value.Equals(list[i]))
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static IReadOnlyList<T> remove<T>(IReadOnlyList<T> list, T value) {
|
||||
int i = index_of(list, value);
|
||||
return i < 0 ? list : remove_at(list, i);
|
||||
}
|
||||
|
||||
public static IReadOnlyList<T> remove_at<T>(IReadOnlyList<T> list, int index) {
|
||||
T[] clone = new T[list.Count - 1];
|
||||
for (int i = 0; i < index; i++)
|
||||
clone[i] = list[i];
|
||||
for (int i = index + 1; i < clone.Length; i++)
|
||||
clone[i] = list[i];
|
||||
return clone;
|
||||
}
|
||||
|
||||
static void _copy<T>(IReadOnlyList<T> source, int source_index, ref IList<T> target, int target_index, int length) {
|
||||
for (int i = 0; i < length; i++)
|
||||
target[target_index + i] = source[source_index + i];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user