SPARK-2093 Attach/Detach ui
This commit is contained in:
1 parent
ac67c84ce7
commit
4e425a3380
17 files changed
+413
-29
No files matched your search
@@ -23,6 +23,7 @@ namespace mbts.ui {
|
||||
AddFileGeometryKey = nameof(AddFileGeometryKey),
|
||||
AddFileThinGeometryKey = nameof(AddFileThinGeometryKey),
|
||||
CheckMarkGeometryKey = nameof(CheckMarkGeometryKey),
|
||||
DetachAlgosGeometryKey = nameof(DetachAlgosGeometryKey),
|
||||
DiskGeometryKey = nameof(DiskGeometryKey),
|
||||
DiskFileGeometryKey = nameof(DiskFileGeometryKey),
|
||||
DocumentGeometryKey = nameof(DocumentGeometryKey),
|
||||
@@ -139,6 +140,7 @@ namespace mbts.ui {
|
||||
public static ImageSource CheckMark => create_icon(CheckMarkGeometryKey);
|
||||
public static ImageSource Clock { get { return load_resource_and_freeze("Clock"); } }
|
||||
public static ImageSource Defrag { get { return load_resource_and_freeze("Defrag"); } }
|
||||
public static ImageSource DetachAlgos => create_icon(DetachAlgosGeometryKey);
|
||||
public static ImageSource Disk => create_icon(DiskGeometryKey);
|
||||
public static ImageSource DiskFile => create_icon(DiskFileGeometryKey);
|
||||
public static ImageSource Display { get { return load_resource_and_freeze("Display"); } }
|
||||
|
||||
@@ -40,6 +40,17 @@
|
||||
</sys:String>
|
||||
</x:Array>
|
||||
|
||||
<!--File (the icon is free to use if we include this information in our credit section)
|
||||
Source: https://www.flaticon.com/authors/chanut
|
||||
Ttile: Cancel free icon
|
||||
Credit: Icon made by Chanut from www.flaticon.com-->
|
||||
<sys:String x:Key="{x:Static mbts:Icons.DetachAlgosGeometryKey}">
|
||||
M32.759,0C14.696,0,0,14.695,0,32.759s14.695,32.759,32.759,32.759s32.759-14.695,32.759-32.759S50.822,0,32.759,0z
|
||||
M6,32.759C6,18.004,18.004,6,32.759,6c6.648,0,12.734,2.443,17.419,6.472L12.472,50.178C8.443,45.493,6,39.407,6,32.759z
|
||||
M32.759,59.518c-5.948,0-11.447-1.953-15.895-5.248l37.405-37.405c3.295,4.448,5.248,9.947,5.248,15.895
|
||||
C59.518,47.514,47.514,59.518,32.759,59.518z
|
||||
</sys:String>
|
||||
|
||||
<!--File (the icon is free to use if we include this information in our credit section)
|
||||
Source: https://www.flaticon.com/authors/smashicons
|
||||
Ttile: File free icon
|
||||
|
||||
@@ -13,7 +13,7 @@ using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace mbts.spark {
|
||||
partial class OrderBookRowVM : DisposableViewModelBase, IEquatable<OrderBookRowVM>, DIYGrid.IRowVM, DIYGrid.IActionableRowVM {
|
||||
partial class OrderBookRowVM : DisposableViewModelBase, IEquatable<OrderBookRowVM>, DIYGrid.IRowVM {
|
||||
const string _unknown_security_price_format_string = "0.#########";
|
||||
const int _unknown_security_price_num_fractional_digits = 9;
|
||||
readonly OrderBookVM _owner;
|
||||
@@ -128,8 +128,8 @@ namespace mbts.spark {
|
||||
public ICommand toggle_command => _toggle_expanded_cmd ?? (
|
||||
_toggle_expanded_cmd = new DelegateCommand(() => is_expanded = !is_expanded));
|
||||
|
||||
ICommand DIYGrid.IActionableRowVM.default_command => _show_order_modify_cmd ??
|
||||
(_show_order_modify_cmd = new DelegateCommand(() => _owner.show_order_modify(this), () => status == OrderStatus.Working));
|
||||
public ICommand show_order_modify_cmd =>
|
||||
_show_order_modify_cmd ?? (_show_order_modify_cmd = new DelegateCommand(() => _owner.show_order_modify(this), () => status == OrderStatus.Working));
|
||||
|
||||
public ICommand cancel_command => _cancel_cmd ??
|
||||
(_cancel_cmd = new DelegateCommand(() => _owner.cancel_order(this), () => status == OrderStatus.Working));
|
||||
|
||||
@@ -47,12 +47,14 @@ namespace mbts.spark {
|
||||
readonly OrderBookColumnCollection _columns;
|
||||
readonly IWindowSettingsManager<OrderBookGridSettings> _settings_manager;
|
||||
readonly SelectedAlgosMonitor _selected_algo_mon;
|
||||
bool _algo_editor_is_visible = OrderBookStartupData.Default.algo_editor_is_visible;
|
||||
double
|
||||
_raw_algo_editor_width = OrderBookStartupData.Default.algo_editor_width,
|
||||
_raw_algo_editor_height = OrderBookStartupData.Default.algo_editor_height;
|
||||
OrderBookStartupData _state;
|
||||
bool _is_row_collection_populated;
|
||||
bool
|
||||
_algo_editor_is_visible = OrderBookStartupData.Default.algo_editor_is_visible,
|
||||
_is_attaching_algos,
|
||||
_is_row_collection_populated;
|
||||
|
||||
public OrderBookVM(IObservable<string> owner_title, IBus bus, INotificationService notification_service, OrdersModel model, IWindowSettingsManager<OrderBookGridSettings> settings_manager, bool rows_are_initially_expanded = false) {
|
||||
_bus = bus;
|
||||
@@ -67,7 +69,7 @@ namespace mbts.spark {
|
||||
// we use an ObservableAppendCollection b/c the mini-ob needs a cancel column at the front
|
||||
columns = new ObservableAppendCollection<DIYGrid.ColumnBase>(_columns);
|
||||
_row_collection = new OrderBookRowCollection(ort => new OrderBookRowVM(this, ort, rows_are_initially_expanded), _columns.get_sorting_data().comparer) { filter = _columns.get_filter() };
|
||||
_row_collection.CollectionChanged += _row_collection_CollectionChanged;
|
||||
_row_collection.CollectionChanged += _row_collection_CollectionChanged;
|
||||
_current_row = backing<OrderBookRowVM>(nameof(current_row));
|
||||
_columns.filter_changed += on_filter_changed;
|
||||
collapse_all_rows_command = new DelegateCommand(_row_collection.collapse_all);
|
||||
@@ -175,6 +177,7 @@ namespace mbts.spark {
|
||||
public ObservableCollection<OrderBookRowVM> selected_rows { get; } = new ObservableCollection<OrderBookRowVM>();
|
||||
public IEnumerable<OrderRecordImmutable> selected_orders => selected_rows.Select(r => r.order);
|
||||
public _GridSettingsManager grid_settings_manager { get; }
|
||||
public bool is_attaching_algos { get => _is_attaching_algos; set => Set(ref _is_attaching_algos, value); }
|
||||
public ICommand collapse_all_rows_command { get; }
|
||||
public ICommand expand_all_rows_command { get; }
|
||||
public ICommand modify_selected_algos_command { get; }
|
||||
@@ -236,7 +239,6 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public OrderBookStartupData create() {
|
||||
var (filters, sorting) = _columns.create();
|
||||
var gs = grid_settings_manager.create();
|
||||
@@ -294,6 +296,21 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
public void begin_attach_algos() => is_attaching_algos = true;
|
||||
public void end_attach_algos() => is_attaching_algos = false;
|
||||
public void cancel_attach_algos() => is_attaching_algos = false;
|
||||
|
||||
public void set_algo_attachment_target(OrderBookRowVM row) {
|
||||
if (is_attaching_algos) {
|
||||
is_attaching_algos = false;
|
||||
// TODO: hook up 'attach-algos' call to model
|
||||
}
|
||||
}
|
||||
|
||||
public void detach_selected_algos() {
|
||||
// TODO: hook up 'detach-algos' call to model
|
||||
}
|
||||
|
||||
internal void show_order_modify(OrderBookRowVM row) =>
|
||||
_bus.post(SparkTags.ShowModifyOrderTag, row.order_key);
|
||||
|
||||
@@ -509,4 +526,4 @@ namespace mbts.spark {
|
||||
osam.security : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,14 @@
|
||||
using bts.api.orderman;
|
||||
using bts.shell;
|
||||
using bts.spark;
|
||||
using bts.view;
|
||||
using mbts.persist;
|
||||
using mbts.ui;
|
||||
using mbts.ui.converters;
|
||||
using mbts.ui.extensions;
|
||||
using mbts.ui.spark;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -15,7 +18,6 @@ using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
//using IOrderBookWSM = mbts.persist.IWindowSettingsManager<mbts.spark.GridSettingsWithNotifications<mbts.spark.OrderRecordTuple, mbts.OrderRecordTuplePredicate>>;
|
||||
using OrderBookGridSettings = bts.shell.OrderBookWindowFactory.OrderBookGridSettings;
|
||||
using OrderBookGridSettingsVM = mbts.spark.GridSettingsVM<bts.api.orderman.OrderSecurity, mbts.OrderRecordTuplePredicate, bts.shell.OrderBookWindowFactory.OrderBookGridSettings>;
|
||||
|
||||
@@ -28,6 +30,7 @@ namespace mbts.spark {
|
||||
OrdersModel _model;
|
||||
OrderBookVM _vm;
|
||||
OrderBookView _view;
|
||||
SparkWindowView _parent_view;
|
||||
OrderBookWindowFactory _factory;
|
||||
SparkCommand[] _commands;
|
||||
|
||||
@@ -103,6 +106,38 @@ namespace mbts.spark {
|
||||
can_execute: () => _vm.selected_orders.Any(x => passes_recreate_search_criteria(x))
|
||||
);
|
||||
|
||||
IDisposable attach_algos_op = null;
|
||||
var attach_selected_orders_command = new SparkCommandCommand(
|
||||
"Attach Selected Orders",
|
||||
Icons.Target,
|
||||
new DelegateCommand(() => {
|
||||
Disposable.dispose(ref attach_algos_op);
|
||||
_vm.begin_attach_algos();
|
||||
if (_parent_view != null) {
|
||||
attach_algos_op = _parent_view.SubscribePreviewKeyDown((s, e) => {
|
||||
switch (e.Key) {
|
||||
case Key.Escape:
|
||||
break;
|
||||
case Key.Z:
|
||||
if (KeyboardExtensions.IsCtrlDown()) {
|
||||
break;
|
||||
} else return;
|
||||
default: return;
|
||||
}
|
||||
_vm.cancel_attach_algos();
|
||||
});
|
||||
}
|
||||
}, () => _vm.selected_rows.Count > 0),
|
||||
new KeyGesture(Key.A, ModifierKeys.Control | ModifierKeys.Shift));
|
||||
|
||||
var detach_selected_orders_command = new SparkCommandCommand(
|
||||
"Detach Selected Orders",
|
||||
Icons.DetachAlgos,
|
||||
new DelegateCommand(() => {
|
||||
_vm.detach_selected_algos();
|
||||
}, () => _vm.selected_rows.Count > 0),
|
||||
new KeyGesture(Key.D, ModifierKeys.Control | ModifierKeys.Shift));
|
||||
|
||||
var toggle_algo_editor_visible_cmd = new SparkCommandCommand(
|
||||
get_toggle_algo_editor_cmd_title(),
|
||||
Icons.Tetris,
|
||||
@@ -150,6 +185,8 @@ namespace mbts.spark {
|
||||
cancel_sell_orders_command,
|
||||
cancel_all_orders_command,
|
||||
recreate_selected_orders_command,
|
||||
attach_selected_orders_command,
|
||||
detach_selected_orders_command,
|
||||
toggle_algo_editor_visible_cmd,
|
||||
toggle_collapse_all_command,
|
||||
toggle_expand_all_command,
|
||||
@@ -171,7 +208,12 @@ namespace mbts.spark {
|
||||
modify_order_command.raiseCanExecuteChanged();
|
||||
cancel_selected_orders_command.raiseCanExecuteChanged();
|
||||
recreate_selected_orders_command.raiseCanExecuteChanged();
|
||||
attach_selected_orders_command.raiseCanExecuteChanged();
|
||||
detach_selected_orders_command.raiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnParentViewCreated(SparkWindowView parent_view) =>
|
||||
_parent_view = parent_view;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,13 +109,6 @@
|
||||
<MouseBinding MouseAction="LeftDoubleClick" Command="{x:Static c:DIYGrid.DefaultRowCommand}"/>
|
||||
<KeyBinding Key="Return" Command="{x:Static c:DIYGrid.DefaultRowCommand}"/>
|
||||
</c:DIYGrid.InputBindings>
|
||||
<c:DIYGrid.CommandBindings>
|
||||
<CommandBinding
|
||||
Command="{x:Static c:DIYGrid.DefaultRowCommand}"
|
||||
Executed="{x:Static c:DIYGrid.DefaultRowActionExecuted}"
|
||||
CanExecute="{x:Static c:DIYGrid.DefaultRowActionCanExecute}"
|
||||
/>
|
||||
</c:DIYGrid.CommandBindings>
|
||||
<c:DIYGrid.RowStyle>
|
||||
<Style TargetType="ListBoxItem" BasedOn="{StaticResource DIYGridRowStyle}">
|
||||
<Style.Triggers>
|
||||
|
||||
@@ -21,4 +21,4 @@ namespace mbts.spark {
|
||||
class OrderBookRowView : DIYGrid.HighPerformanceRow<OrderBookRowVM, OrderBookGridView.ColumnKeys> {
|
||||
public OrderBookRowView() : base() { }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<UserControl
|
||||
x:Class="mbts.spark.OrderBookView"
|
||||
x:ClassModifier="internal"
|
||||
x:Name="_grid"
|
||||
x:Name="Root"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:sp="clr-namespace:mbts.spark"
|
||||
@@ -21,7 +21,11 @@
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<sys:Double x:Key="GridSplitterWidth">5</sys:Double>
|
||||
<sys:Double x:Key="GridSplitterHeight">5</sys:Double>
|
||||
<SolidColorBrush x:Key="AlgoAttachmentBackground" Color="#55009500"/>
|
||||
<cv:GridLengthConverter x:Key="GridLengthPixelConverter" UnitType="Pixel"/>
|
||||
<cv:ValueMap x:Key="AlgoAttachmentStateConverter" Default="{x:Static Inactive, MemberType={u:Nested sp:OrderBookView.VisualStateNames.AlgoAttachment}}">
|
||||
<cv:KeyValue Key="{u:True}" Value="{x:Static Active, MemberType={u:Nested sp:OrderBookView.VisualStateNames.AlgoAttachment}}"/>
|
||||
</cv:ValueMap>
|
||||
<Style TargetType="GridSplitter">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
@@ -33,7 +37,47 @@
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<AdornerDecorator>
|
||||
<Grid>
|
||||
<Grid x:Name="ContentRoot">
|
||||
<u:StateManager.Groups>
|
||||
<u:StateGroupsManager Target="{Binding Source={u:DirectReference ContentRoot}}">
|
||||
<u:StateDefinitionCollection>
|
||||
<u:StateDefinition State="{Binding DataContext.is_attaching_algos, Source={u:DirectReference ContentRoot}, Converter={StaticResource AlgoAttachmentStateConverter}}"/>
|
||||
</u:StateDefinitionCollection>
|
||||
</u:StateGroupsManager>
|
||||
</u:StateManager.Groups>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup Name="AlgoAttachmentStates">
|
||||
<VisualState Name="{x:Static Active, MemberType={u:Nested sp:OrderBookView.VisualStateNames.AlgoAttachment}}">
|
||||
<Storyboard>
|
||||
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="PART_AlgoAttachmentRoot_Border" Storyboard.TargetProperty="(UIElement.Opacity)">
|
||||
<DiscreteDoubleKeyFrame KeyTime="0" Value="1"/>
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_Orders_DIYGrid" Storyboard.TargetProperty="(FrameworkElement.Cursor)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Cursors.Pen}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_AlgoAttachmentInstructions_TextBlock" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
|
||||
<DiscreteObjectKeyFrame KeyTime="00:00:03.5" Value="{x:Static Visibility.Collapsed}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<DoubleAnimation Storyboard.TargetName="PART_AlgoAttachmentInstructions_TextBlock" Storyboard.TargetProperty="(UIElement.Opacity)" BeginTime="00:00:00" Duration="00:00:00" To="1"/>
|
||||
<DoubleAnimation Storyboard.TargetName="PART_AlgoAttachmentInstructions_TextBlock" Storyboard.TargetProperty="(UIElement.Opacity)" BeginTime="00:00:02.5" Duration="00:00:01" To="0"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState Name="{x:Static Inactive, MemberType={u:Nested sp:OrderBookView.VisualStateNames.AlgoAttachment}}">
|
||||
<Storyboard>
|
||||
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="PART_AlgoAttachmentRoot_Border" Storyboard.TargetProperty="(UIElement.Opacity)">
|
||||
<DiscreteDoubleKeyFrame KeyTime="0" Value="0"/>
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_Orders_DIYGrid" Storyboard.TargetProperty="(FrameworkElement.Cursor)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Cursors.Arrow}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_AlgoAttachmentInstructions_TextBlock" Storyboard.TargetProperty="(UIElement.Visibility)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
@@ -43,11 +87,40 @@
|
||||
<ColumnDefinition Width="{Binding algo_editor_width, Converter={StaticResource GridLengthPixelConverter}, Mode=TwoWay}"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<sp:OrderBookGridView
|
||||
x:Name="PART_Orders_DIYGrid"
|
||||
Background="Transparent"
|
||||
Columns="{Binding columns}"
|
||||
CurrentRow="{Binding current_row, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
Rows="{Binding rows}"
|
||||
SelectionHighlight="{Binding grid_settings_manager.selection_highlight, Mode=OneWay}"
|
||||
/>
|
||||
Cursor="Arrow"
|
||||
>
|
||||
<c:DIYGrid.CommandBindings>
|
||||
<CommandBinding
|
||||
Command="{x:Static c:DIYGrid.DefaultRowCommand}"
|
||||
Executed="{x:Static sp:OrderBookView.DefaultRowActionExecuted}"
|
||||
CanExecute="{x:Static sp:OrderBookView.DefaultRowActionCanExecute}"
|
||||
/>
|
||||
</c:DIYGrid.CommandBindings>
|
||||
</sp:OrderBookGridView>
|
||||
<Border
|
||||
x:Name="PART_AlgoAttachmentRoot_Border"
|
||||
Width="{Binding ActualWidth, ElementName=PART_Orders_DIYGrid}"
|
||||
Height="{Binding ActualHeight, ElementName=PART_Orders_DIYGrid}"
|
||||
Background="{StaticResource AlgoAttachmentBackground}"
|
||||
Opacity="0"
|
||||
IsHitTestVisible="False"
|
||||
>
|
||||
<TextBlock x:Name="PART_AlgoAttachmentInstructions_TextBlock" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="Collapsed" FontSize="28" TextAlignment="Center">
|
||||
<Bold>
|
||||
Attach Orders
|
||||
</Bold>
|
||||
<LineBreak/>
|
||||
Double Click to select target
|
||||
<LineBreak/>
|
||||
(Press Esc to cancel)
|
||||
</TextBlock>
|
||||
</Border>
|
||||
<GridSplitter
|
||||
Grid.Column="1"
|
||||
Panel.ZIndex="1"
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.controls.adorners;
|
||||
using mbts.ui.converters;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace mbts.spark {
|
||||
internal partial class OrderBookView : UserControl {
|
||||
@@ -9,9 +13,32 @@ namespace mbts.spark {
|
||||
OrderDescriptionConverter = ValueConverter.create<OrderBookRowVM, string>(row => row == null ? string.Empty : row.order.short_description(row.security)),
|
||||
FillsPanelVisualStateConverter = ValueConverter.create<bool, string>(show => show ? VisualStateNames.FillsPanel.Active : VisualStateNames.FillsPanel.Inactive);
|
||||
|
||||
public static readonly ExecutedRoutedEventHandler DefaultRowActionExecuted = (sender, e) => {
|
||||
if (sender is DIYGrid g && g.DataContext is OrderBookVM vm && g.CurrentRow is OrderBookRowVM row) {
|
||||
if (vm.is_attaching_algos) {
|
||||
vm.set_algo_attachment_target(row);
|
||||
} else {
|
||||
row.show_order_modify_cmd.ExecuteIfCan(e.Parameter);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static readonly CanExecuteRoutedEventHandler DefaultRowActionCanExecute = (sender, e) => {
|
||||
if (sender is DIYGrid g && g.CurrentRow is OrderBookRowVM row)
|
||||
e.CanExecute = true;
|
||||
};
|
||||
|
||||
readonly DIYGridRowHighlighterAdorner _algo_attachment_target_adorner;
|
||||
|
||||
public OrderBookView(OrderBookVM vm) {
|
||||
InitializeComponent();
|
||||
DataContext = vm;
|
||||
_algo_attachment_target_adorner = new DIYGridRowHighlighterAdorner(PART_Orders_DIYGrid) {
|
||||
Fill = new SolidColorBrush(Colors.Blue) { Opacity = 0.4 },
|
||||
Stroke = new Pen(Brushes.Blue, 1)
|
||||
};
|
||||
_algo_attachment_target_adorner.attach_binding(DIYGridRowHighlighterAdorner.IsActiveProperty, nameof(OrderBookVM.is_attaching_algos), this);
|
||||
_algo_attachment_target_adorner.attach_async().ignore();
|
||||
}
|
||||
|
||||
public static class VisualStateNames {
|
||||
@@ -22,6 +49,14 @@ namespace mbts.spark {
|
||||
Active = $"{GroupName}{VisualStates.Active}",
|
||||
Inactive = $"{GroupName}{VisualStates.Inactive}";
|
||||
}
|
||||
|
||||
public static class AlgoAttachment {
|
||||
public const string GroupName = nameof(AlgoAttachment);
|
||||
|
||||
public static readonly string
|
||||
Active = $"{GroupName}{VisualStates.Active}",
|
||||
Inactive = $"{GroupName}{VisualStates.Inactive}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace mbts.ui {
|
||||
class StatefulCommand<T> : IRaiseCanExecuteChangedCommand {
|
||||
readonly Dictionary<T, ICommand> _cmds;
|
||||
readonly IEqualityComparer<T> _comparer;
|
||||
T _current_state;
|
||||
ICommand _current_cmd;
|
||||
|
||||
public StatefulCommand()
|
||||
: this(default, EqualityComparer<T>.Default) { }
|
||||
|
||||
public StatefulCommand(T init_state)
|
||||
: this(init_state, EqualityComparer<T>.Default) { }
|
||||
|
||||
public StatefulCommand(IEqualityComparer<T> comparer)
|
||||
: this(default, comparer) { }
|
||||
|
||||
public StatefulCommand(T init_state, IEqualityComparer<T> comparer) {
|
||||
_comparer = comparer;
|
||||
_cmds = new Dictionary<T, ICommand>(comparer);
|
||||
}
|
||||
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
public void add_cmd(T state, ICommand cmd) =>
|
||||
_cmds.Add(state, cmd);
|
||||
|
||||
public T current_state {
|
||||
get => _current_state;
|
||||
set {
|
||||
if (!_comparer.Equals(_current_state, value)) {
|
||||
if (_current_cmd != null) {
|
||||
_current_cmd.CanExecuteChanged += _on_current_cmd_CanExecuteChanged;
|
||||
}
|
||||
_current_state = value;
|
||||
if (_cmds.TryGetValue(current_state, out _current_cmd)) {
|
||||
_current_cmd.CanExecuteChanged += _on_current_cmd_CanExecuteChanged;
|
||||
}
|
||||
RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanExecute(object parameter) => _current_cmd?.CanExecute(parameter) ?? false;
|
||||
public void Execute(object parameter) => _current_cmd?.Execute(parameter);
|
||||
public void RaiseCanExecuteChanged() => CanExecuteChanged?.Invoke(this, new EventArgs());
|
||||
void _on_current_cmd_CanExecuteChanged(object sender, EventArgs e) => RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
using bts.utils;
|
||||
using mbts.ui.extensions;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace mbts.ui.controls.adorners {
|
||||
/// <summary>
|
||||
/// This Adorner draws a rectangle over rows when the mouse hovers over them.
|
||||
/// </summary>
|
||||
class DIYGridRowHighlighterAdorner : Adorner {
|
||||
readonly DIYGrid _grid;
|
||||
DIYGridRowsPresenter _rows_presenter_backing;
|
||||
ScrollContentPresenter _content_presenter_backing;
|
||||
bool _is_active;
|
||||
Brush _fill;
|
||||
Pen _stroke;
|
||||
|
||||
#region IsActive
|
||||
public static readonly DependencyProperty IsActiveProperty =
|
||||
WPFHelper.create_dp<bool, DIYGridRowHighlighterAdorner>(
|
||||
nameof(IsActive),
|
||||
FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
(o, v) => o._is_active = v,
|
||||
false);
|
||||
|
||||
public bool IsActive {
|
||||
get => (bool)GetValue(IsActiveProperty);
|
||||
set => SetValue(IsActiveProperty, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Fill
|
||||
public static readonly DependencyProperty FillProperty =
|
||||
WPFHelper.create_dp<SolidColorBrush, DIYGridRowHighlighterAdorner>(
|
||||
nameof(Fill),
|
||||
FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
(o, v) => o._fill = v,
|
||||
DIYGrid.DefaultSelectionHighlight);
|
||||
|
||||
public SolidColorBrush Fill {
|
||||
get => GetValue(FillProperty) as SolidColorBrush;
|
||||
set => SetValue(FillProperty, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Stroke
|
||||
public static readonly DependencyProperty StrokeProperty =
|
||||
WPFHelper.create_dp<Pen, DIYGridRowHighlighterAdorner>(
|
||||
nameof(Stroke),
|
||||
FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
(o, v) => o._stroke = v,
|
||||
DIYGrid.DefaultSelectionStroke);
|
||||
|
||||
public Pen Stroke {
|
||||
get => GetValue(StrokeProperty) as Pen;
|
||||
set => SetValue(StrokeProperty, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public DIYGridRowHighlighterAdorner(DIYGrid grid) : base(grid) {
|
||||
_grid = grid;
|
||||
_is_active = IsActive;
|
||||
_fill = Fill;
|
||||
_stroke = Stroke;
|
||||
IsHitTestVisible = false;
|
||||
grid.SubscribeMouseEnter(on_mouse_enter);
|
||||
grid.SubscribeMouseLeave(on_mouse_leave);
|
||||
grid.SubscribePreviewMouseMove(on_mouse_move);
|
||||
void on_mouse_enter(object sender, MouseEventArgs e) => InvalidateVisual();
|
||||
void on_mouse_move(object sender, MouseEventArgs e) => InvalidateVisual();
|
||||
void on_mouse_leave(object sender, MouseEventArgs e) => InvalidateVisual();
|
||||
}
|
||||
|
||||
DIYGridRowsPresenter _rows_presenter => _rows_presenter_backing ?? (_rows_presenter_backing = _grid.descendants_of_type<DIYGridRowsPresenter>().FirstOrDefault());
|
||||
ScrollContentPresenter _content_presenter => _content_presenter_backing ?? (_content_presenter_backing = _rows_presenter?.descendants_of_type<ScrollContentPresenter>().empty_if_null().FirstOrDefault());
|
||||
|
||||
protected override void OnRender(DrawingContext drawingContext) {
|
||||
if (_content_presenter == null || !_is_active)
|
||||
return;
|
||||
var pt = Mouse.GetPosition(_grid);
|
||||
var row = _grid.ChildAtPoint<ListBoxItem>(pt);
|
||||
if (row != null) {
|
||||
var top_left = row.TranslatePoint(new Point(0, 0), _content_presenter);
|
||||
double x_adj = MathUtils.within_range(0.0, _content_presenter.ActualWidth, top_left.X);
|
||||
double y_adj = MathUtils.within_range(0.0, _content_presenter.ActualHeight, top_left.Y);
|
||||
top_left = _content_presenter.TranslatePoint(new Point(x_adj, y_adj), _grid);
|
||||
drawingContext.DrawRectangle(_fill, _stroke, new Rect(top_left, new Point(top_left.X + _content_presenter.ActualWidth, top_left.Y + row.ActualHeight)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
using mbts.ui.utility.text;
|
||||
using mbts.ui.extensions;
|
||||
using mbts.ui.utility.text;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Media;
|
||||
@@ -8,9 +10,22 @@ namespace mbts.ui {
|
||||
enum RelativePosition { Left, Right, Above, Below }
|
||||
|
||||
static class AdornerHelper {
|
||||
public static void attach(this Adorner adorner) {
|
||||
public static void attach(this Adorner adorner) => try_attach(adorner);
|
||||
|
||||
public static async Task attach_async(this Adorner adorner) {
|
||||
if (!adorner.try_attach()) {
|
||||
await adorner.LoadedAsync();
|
||||
adorner.attach();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool try_attach(this Adorner adorner) {
|
||||
var al = AdornerLayer.GetAdornerLayer(adorner.AdornedElement);
|
||||
if (al != null) al.Add(adorner);
|
||||
if (al != null) {
|
||||
al.Add(adorner);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void detach(this Adorner adorner) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace mbts.ui.extensions {
|
||||
@@ -29,5 +30,17 @@ namespace mbts.ui.extensions {
|
||||
element.SizeChanged += callback;
|
||||
return Disposable.Create(() => element.SizeChanged -= callback);
|
||||
}
|
||||
|
||||
public static Task<RoutedEventArgs> LoadedAsync(this FrameworkElement element) {
|
||||
if (element.IsLoaded)
|
||||
return Task.FromResult(new RoutedEventArgs(FrameworkElement.LoadedEvent, element));
|
||||
var tcs = new TaskCompletionSource<RoutedEventArgs>();
|
||||
element.Loaded += on_loaded;
|
||||
return tcs.Task;
|
||||
void on_loaded(object sender, RoutedEventArgs e) {
|
||||
element.Loaded -= on_loaded;
|
||||
tcs.TrySetResult(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using mbts.ui.utility.text;
|
||||
using mbts.utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -108,6 +107,11 @@ namespace mbts.ui.extensions {
|
||||
return Disposable.Create(() => target.PreviewMouseDown -= callback);
|
||||
}
|
||||
|
||||
public static IDisposable SubscribePreviewMouseMove(this UIElement target, MouseEventHandler callback) {
|
||||
target.PreviewMouseMove += callback;
|
||||
return Disposable.Create(() => target.PreviewMouseMove -= callback);
|
||||
}
|
||||
|
||||
public static IDisposable SubscribePreviewDragOver(this UIElement target, DragEventHandler callback) {
|
||||
target.PreviewDragOver += callback;
|
||||
return Disposable.Create(() => target.PreviewDragOver -= callback);
|
||||
|
||||
@@ -211,6 +211,32 @@ namespace mbts.ui {
|
||||
foreach (var dp in d_props)
|
||||
BindingOperations.ClearBinding(d_obj, dp);
|
||||
}
|
||||
|
||||
public static IDisposable attach_binding(this DependencyObject target, DependencyProperty target_property, string path, FrameworkElement source_view) {
|
||||
object source_vm = source_view.DataContext;
|
||||
try_reset_binding();
|
||||
source_view.DataContextChanged += on_data_context_changed;
|
||||
return Disposable.Create(() => {
|
||||
try {
|
||||
source_view.DataContextChanged -= on_data_context_changed;
|
||||
} catch (Exception ex) {
|
||||
Log.Ui.warn($"Error detaching from {nameof(source_view)}.{nameof(FrameworkElement.DataContextChanged)} event: {ex}.");
|
||||
}
|
||||
});
|
||||
void on_data_context_changed(object sender, DependencyPropertyChangedEventArgs e) {
|
||||
source_vm = e.NewValue;
|
||||
try_reset_binding();
|
||||
}
|
||||
void try_reset_binding() {
|
||||
if (source_vm != null)
|
||||
target.reset_binding(target_property, new Binding(path) { Source = source_vm });
|
||||
}
|
||||
}
|
||||
|
||||
public static void reset_binding(this DependencyObject target, DependencyProperty target_property, BindingBase binding) {
|
||||
BindingOperations.ClearBinding(target, target_property);
|
||||
BindingOperations.SetBinding(target, target_property, binding);
|
||||
}
|
||||
|
||||
public static void TryRaiseCanExecuteChanged(this ICommand command) {
|
||||
if (command == null) return;
|
||||
|
||||
@@ -63,8 +63,11 @@ namespace bts.spark {
|
||||
public virtual double MinWidth => 400;
|
||||
public virtual double MinHeight => Math.Max(ABSOLUTE_MIN_HEIGHT, TITLE_PANEL_HEIGHT + COLUMN_HEADER_HEIGHT + GRID_FOOTER_HEIGHT + Commands.Count() * SPARK_MENU_ITEM_HEIGHT);
|
||||
|
||||
public ShellWindowUI GetContent() =>
|
||||
new ShellWindowUI(new SparkWindowView(_bus, Commands, Content));
|
||||
public ShellWindowUI GetContent() {
|
||||
var parent_view = new SparkWindowView(_bus, Commands, Content);
|
||||
OnParentViewCreated(parent_view);
|
||||
return new ShellWindowUI(parent_view);
|
||||
}
|
||||
|
||||
public void GetState(Stream save_here) =>
|
||||
_save.save(SaveState, save_here);
|
||||
@@ -82,5 +85,7 @@ namespace bts.spark {
|
||||
}
|
||||
|
||||
public abstract void Dispose();
|
||||
|
||||
protected virtual void OnParentViewCreated(SparkWindowView parent_view) { }
|
||||
}
|
||||
}
|
||||
@@ -55,4 +55,4 @@ namespace bts.view {
|
||||
_menu.ShowText = !_menu.ShowText;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user