Merged from dev

This commit is contained in:
Pedro Pinto committed 2018-05-18 16:57:03 -04:00
1 parent ec7a4df5ee
commit ab950cba91
424 files changed
+31620 -4908

No files matched your search

+3
View File
@@ -16,3 +16,6 @@ src/client/spark/Properties/launchSettings.json
compile_commands.json
.cquery_cached_index/
src/client/sparkcmd/Properties/launchSettings.json
node_modules
paket-files
project.lock.json
+4 -2
View File
@@ -17,7 +17,9 @@
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
},
"cStandard": "c11",
"cppStandard": "c++17"
},
{
"name": "Windows",
@@ -96,5 +98,5 @@
"cppStandard": "c++17"
}
],
"version": 3
"version": 4
}
+66 -1
View File
@@ -1,6 +1,7 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
@@ -117,12 +118,76 @@
"/home/bts/spark/": "${workspaceRoot}"
}
},
{
"name": "Admin Service Tests",
"type": "cppdbg",
"request": "launch",
"program": "/home/bts/spark/build/ninja_debug/src/server/sparkd/sparkd",
"args": ["test", "[admin_service]"],
"stopAtEntry": false,
"cwd": "/home/bts/spark/build/ninja_debug/src/server/sparkd/",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"preLaunchTask": "",
"logging": {
"engineLogging": false
},
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "enable pretty-printer",
"ignoreFailures": true
}
],
"pipeTransport": {
"pipeCwd": "${workspaceRoot}",
"pipeProgram": "c:\\program files\\git\\usr\\bin\\ssh.exe",
"pipeArgs": ["bts@sparkvm"],
"debuggerPath": "/usr/bin/gdb"
},
"sourceFileMap": {
"/home/bts/spark/": "${workspaceRoot}"
}
},
{
"name": "Limiter Tests",
"type": "cppdbg",
"request": "launch",
"program": "/home/bts/spark/build/ninja_debug/src/server/sparkd/sparkd",
"args": ["test", "[limiter]"],
"stopAtEntry": false,
"cwd": "/home/bts/spark/build/ninja_debug/src/server/sparkd/",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"preLaunchTask": "",
"logging": {
"engineLogging": false
},
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "enable pretty-printer",
"ignoreFailures": true
}
],
"pipeTransport": {
"pipeCwd": "${workspaceRoot}",
"pipeProgram": "c:\\program files\\git\\usr\\bin\\ssh.exe",
"pipeArgs": ["bts@sparkvm"],
"debuggerPath": "/usr/bin/gdb"
},
"sourceFileMap": {
"/home/bts/spark/": "${workspaceRoot}"
}
},
{
"name": "MD Tests",
"type": "cppdbg",
"request": "launch",
"program": "/home/bts/spark/build/ninja_debug/src/server/sparkd/sparkd",
"args": ["test", "-a", "LoadSessionKeys"],
"args": ["test", "[md]"],
"stopAtEntry": false,
"cwd": "/home/bts/spark/build/ninja_debug/src/server/sparkd/",
"environment": [],
+1 -2
View File
@@ -36,6 +36,5 @@ else ()
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_DEBUG} -DNDEBUG -O3")
add_subdirectory(src/lib)
add_subdirectory(src/server/sparkd)
add_subdirectory(src/web)
endif()
+30
View File
@@ -0,0 +1,30 @@
using bts.api;
using bts.api.admin;
using bts.api.core;
using bts.spark;
using mbts.spark.utilities;
using mbts.utils;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Composition;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
namespace mbts.spark {
[Export]
class AdminModel {
readonly AdminService _service;
[ImportingConstructor]
private AdminModel(AdminService service) {
_service = service;
on_admin_data = _service.subscribei_admin_data().Table().Replay(1).RefCount();
}
public IObservable<TableUpdate<AdminDataImmutable, int>> on_admin_data { get; }
}
}
@@ -57,7 +57,8 @@ namespace bts.shell {
}
void _show_modify_order(uint order_key) {
if (_orders.state.TryGetValue(order_key, out OrderRecordImmutable ori) && _md_map.TryGetValue(ori.Def.SecurityKey, out SecurityMD smd))
if (_orders.state.TryGetValue(order_key, out OrderRecordImmutable ori) && _md_map.TryGetValue(ori.Def.SecurityKey, out SecurityMD smd)
&& (ori.HasDef && ori.Def.HasCustomDef && !(ori.Def.CustomDef.HasStop || ori.Def.CustomDef.HasStopLimit)))
_show_order_window(new OrderModificationDialog {
DataContext = new ExistingOrderTicketVM(_model,
Observable.Return(new OrderRecordTuple(ori, smd)),
@@ -11,6 +11,7 @@ using bts.support;
using bts.api.orderman;
using bts.api.synthetic;
using bts.api.diagnostic;
using bts.api.admin;
namespace Spark
{
@@ -34,6 +35,9 @@ namespace Spark
[Export]
public OrderService order_service => context.locate<OrderService>();
[Export]
public AdminService admin_service => context.locate<AdminService>();
[Export]
public SyntheticSecurityService synthetic_security_service => context.locate<SyntheticSecurityService>();
+38
View File
@@ -0,0 +1,38 @@
using mbts.ui.shell;
using System.Windows.Input;
using System.Windows.Media;
namespace mbts.ui {
interface IMenuItemVM {
string name { get; }
string group { get; }
ImageSource icon { get; }
ICommand command { get; }
object parameter { get; }
}
class MenuItemVM : ViewModelBase, IMenuItemVM {
object _parameter;
public MenuItemVM(string name, ICommand command, ImageSource icon = null, string group = null, object parameter = null) {
this.name = name;
this.group = group;
this.command = command;
this.icon = icon;
_parameter = parameter;
}
public string name { get; }
public string group { get; }
public ImageSource icon { get; }
public ICommand command { get; }
public object parameter {
get => _parameter;
set {
_parameter = value;
command.TryRaiseCanExecuteChanged();
RaisePropertyChanged();
}
}
}
}
+4 -2
View File
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -42,7 +42,6 @@ namespace mbts.ui
public static ImageSource DataCopy { get { return load_image("DataCopy.ico"); } }
public static ImageSource Import { get { return load_image("Import.ico"); } }
public static ImageSource Refresh { get { return load_image("Refresh.png"); } }
public static ImageSource FavoriteWindow { get { return load_image("FavoriteWindow.png"); } }
//public static ImageSource Ticket { get { return load_image("Ticket.png"); } } // replaced with AddOrders
@@ -98,14 +97,17 @@ namespace mbts.ui
public static ImageSource Clock { get { return (DrawingImage)_resources["Clock"]; } }
public static ImageSource Defrag { get { return (DrawingImage)_resources["Defrag"]; } }
public static ImageSource Display { get { return (DrawingImage)_resources["Display"]; } }
public static ImageSource Export => (DrawingImage)_resources["Export"];
public static ImageSource Filter { get { return (DrawingImage)_resources["Filter"]; } }
public static ImageSource FilterActive { get { return (DrawingImage)_resources["FilterActive"]; } }
public static ImageSource FilterError { get { return (DrawingImage)_resources["FilterError"]; } }
public static ImageSource Import => (DrawingImage)_resources["Import"];
public static ImageSource Knight { get { return (DrawingImage)_resources["Knight"]; } }
public static ImageSource Payment { get { return (DrawingImage)_resources["Payment"]; } }
public static ImageSource Spawn { get { return (DrawingImage)_resources["Spawn"]; } }
public static ImageSource Target { get { return (DrawingImage)_resources["Target"]; } }
public static ImageSource Tetris { get { return (DrawingImage)_resources["Tetris"]; } }
public static ImageSource ViewSettings => (DrawingImage)_resources["ViewSettings"];
public static ImageSource Wrench { get { return (DrawingImage)_resources["Wrench"]; } }
public static ImageSource Support => (DrawingImage)_resources["SupportIcon"];
+42 -3
View File
@@ -319,7 +319,7 @@ M0,0L63.999001,0 63.999001,48.792999 0,48.792999z">
</DrawingImage.Drawing>
</DrawingImage>
<DrawingImage x:Key="Clock">
<DrawingImage x:Key="Clock" x:Shared="False">
<DrawingImage.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
@@ -608,7 +608,7 @@ M0,0L63.999001,0 63.999001,48.792999 0,48.792999z">
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
<DrawingImage x:Key="CancelSelected">
<DrawingImage.Drawing>
<DrawingGroup>
@@ -718,7 +718,7 @@ M0,0L63.999001,0 63.999001,48.792999 0,48.792999z">
</DrawingImage.Drawing>
</DrawingImage>
<DrawingImage x:Key="CloneSynthetic" x:Shared="False">
<DrawingImage x:Key="CloneSynthetic" x:Shared="False">
<DrawingImage.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
@@ -730,6 +730,45 @@ M0,0L63.999001,0 63.999001,48.792999 0,48.792999z">
</DrawingImage.Drawing>
</DrawingImage>
<DrawingImage x:Key="ViewSettings" x:Shared="False">
<DrawingImage.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing
Brush="Black"
Geometry="M22.889013,19.178117C23.365026,19.178117 23.75202,19.56508 23.75202,20.040055 23.75202,20.516007 23.365026,20.904069 22.889013,20.904069 22.413031,20.904069 22.02503,20.516007 22.02503,20.040055 22.02503,19.56508 22.413031,19.178117 22.889013,19.178117z M22.889013,15.528093C20.40003,15.528092 18.375006,17.552018 18.375006,20.040055 18.375006,22.529069 20.40003,24.554093 22.889013,24.554093 25.37702,24.554093 27.402014,22.529069 27.402014,20.040055 27.402014,17.552018 25.37702,15.528092 22.889013,15.528093z M22.167028,12.426042L23.834021,12.426042 23.834021,13.935075 23.981024,13.958024C24.912024,14.12404,25.772009,14.500016,26.509008,15.03505L26.62702,15.12404 27.757025,13.993058 28.935034,15.171037 27.806005,16.301042 27.940008,16.484025C28.422033,17.167008,28.769018,17.950089,28.943029,18.796037L28.996008,19.093034 30.500006,19.093034 30.500006,20.759049 29.02503,20.759049 28.997015,20.980119C28.848028,21.952043,28.472021,22.85109,27.924017,23.619035L27.805029,23.779069 28.935034,24.909074 27.757025,26.088029 26.62702,24.958024 26.61701,24.966081C25.866034,25.536027,24.981024,25.938004,24.019018,26.117082L23.834021,26.147111 23.834021,27.426042 22.167028,27.426042 22.167028,26.177018 21.949011,26.149064C20.942022,25.995011,20.014013,25.596086,19.228033,25.016007L19.151007,24.957047 18.019018,26.088029 16.841009,24.909074 17.972021,23.779069 17.863013,23.633073C17.294012,22.839005,16.908026,21.905046,16.767034,20.894059L16.75202,20.759049 15.500006,20.759049 15.500006,19.093034 16.783026,19.093034 16.812017,18.91005C16.991034,17.947038,17.393011,17.063004,17.963019,16.312028L17.972021,16.301042 16.841009,15.171037 18.019018,13.993058 19.15003,15.123063 19.310034,15.005021C20.078009,14.458024,20.977026,14.081071,21.949011,13.932023L22.167028,13.905046z M16.000014,6.0000114C14.346014,6.0000114 13.000014,7.3460112 13.000014,9.0000114 13.000014,10.654011 14.346014,12.000011 16.000014,12.000011 17.654014,12.000011 19.000014,10.654011 19.000014,9.0000114 19.000014,7.3460112 17.654014,6.0000114 16.000014,6.0000114z M16.000014,4.0000114C18.757014,4.0000114 21.000014,6.2430115 21.000014,9.0000114 21.000014,11.757011 18.757014,14.000011 16.000014,14.000011 13.243014,14.000011 11.000014,11.757011 11.000014,9.0000114 11.000014,6.2430115 13.243014,4.0000114 16.000014,4.0000114z M16.000123,0C24.651189,0 31.47924,8.0160384 31.765244,8.3580403 32.078245,8.7290418 32.078245,9.2720447 31.765244,9.6440461 31.700243,9.7220466 30.130231,11.580056 27.56321,13.533065L26.352201,11.941058C27.853213,10.798052 29.000222,9.6770465 29.645226,9.0010433 27.881213,7.1610341 22.366171,2.0000095 16.000123,2.0000095 9.6350741,2.0000095 4.1210318,7.1590343 2.3550186,9.0000434 4.013031,10.731052 8.9770689,15.388074 14.846114,15.946077L14.657112,17.936087C6.6410513,17.175083 0.49200439,9.9510479 0.23400211,9.6430461 -0.078000069,9.2720447 -0.078000069,8.7290418 0.23400211,8.3580403 0.52000427,8.0160384 7.3480568,0 16.000123,0z"
/>
</DrawingGroup.Children>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
<DrawingImage x:Key="Export" x:Shared="False">
<DrawingImage.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing
Brush="Black"
Geometry="M23.471008,4.2230202L32,12.800012 23.471008,20.360005 23.471008,16.322012C23.471008,16.322012 8.7430115,12.294 5.0610046,20.360005 5.0610046,18.343985 6.3990173,8.2560073 23.471008,8.2560073z M0,0L21.334015,0 21.334015,2.1340014 21.334015,4.2690102 19.200012,4.2690102 19.200012,2.1340014 2.1340027,2.1340014 2.1340027,23.466997 19.200012,23.466997 19.200012,21.331989 21.334015,21.331989 21.334015,23.466997 21.334015,25.601 19.200012,25.601 0,25.601 0,23.466997 0,2.1340014z"
/>
</DrawingGroup.Children>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
<DrawingImage x:Key="Import" x:Shared="False">
<DrawingImage.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing
Brush="Black"
Geometry="M13.594002,4.2219891L13.594002,8.255989C30.661003,8.255989 32,18.345018 32,20.360004 28.319,12.293011 13.594002,16.32399 13.594002,16.32399L13.594002,20.360004 5.0610008,12.798993z M0,0L21.333,0 21.333,2.1329974 21.333,4.2670025 19.201,4.2670025 19.201,2.1329974 2.1330032,2.1329974 2.1330032,23.467003 19.201,23.467003 19.201,21.332998 21.333,21.332998 21.333,23.467003 21.333,25.6 19.201,25.6 0,25.6 0,23.467003 0,2.1329974z"
/>
</DrawingGroup.Children>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
<!-- Pin
<Path Data="F1M3,11L3,7 0,7 0,6 1,6 1,1 1,0 6,0 6,1 6,6 7,6 7,7 4,7 4,11 3,11z M2,1L2,6 4,6 4,1 2,1z" />
Unpin
@@ -44,7 +44,7 @@ namespace mbts.spark {
}), DataGridFilterHelper.hook_filters(rows_view,
security_filter, bid_price_filter, bid_size_filter, ask_price_filter, ask_size_filter, last_price_filter, last_size_filter, day_change_filter, settlement_filter,
session_low_filter, session_high_filter, position_filter, working_bid_volume_filter, working_ask_volume_filter, volume_filter, security_key_filter),
WorkLoop.Start(_refresh)
WorkLoop.Start("MarketView", _refresh)
);
}
@@ -83,224 +83,226 @@
</Style>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<c:DataGridEx x:Name="grid" ItemsSource="{Binding rows_view}" IsReadOnly="True" CanUserSortColumns="True" GridLinesVisibility="None"
<AdornerDecorator>
<Grid>
<c:DataGridEx x:Name="grid" ItemsSource="{Binding rows_view}" IsReadOnly="True" CanUserSortColumns="True" GridLinesVisibility="None"
CurrentItem="{Binding current_row, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
u:DataGridBehavior.NotifyColumnsOfSorting="True" usp:GridAnimation.Enableanimation="True" BorderThickness="0">
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="usp:GridAnimation.RowAnimation" Value="{Binding animations}"/>
<Setter Property="u:AttachedCommands.DoubleClick" Value="{Binding show_ladder}"/>
<Setter Property="u:AttachedCommands.Enter" Value="{Binding show_ladder}"/>
</Style>
</DataGrid.RowStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Security" Binding="{Binding security}"
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="usp:GridAnimation.RowAnimation" Value="{Binding animations}"/>
<Setter Property="u:AttachedCommands.DoubleClick" Value="{Binding show_ladder}"/>
<Setter Property="u:AttachedCommands.Enter" Value="{Binding show_ladder}"/>
</Style>
</DataGrid.RowStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Security" Binding="{Binding security}"
c:DataGridEx.CellKey="{u:Enum Security, Type={u:Nested usp:MarketViewView.Columns}}"
c:DataGridFilterProperties.Filter="{Binding DataContext.security_filter, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterActive="{Binding DataContext.security_filter.active, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.security_filter.open, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterTemplate="{StaticResource RegexTemplate}"/>
<DataGridTextColumn Header="Volume" Binding="{Binding volume}"
<DataGridTextColumn Header="Volume" Binding="{Binding volume}"
c:DataGridEx.CellKey="{u:Enum Volume, Type={u:Nested usp:MarketViewView.Columns}}"
c:DataGridFilterProperties.Filter="{Binding DataContext.volume_filter, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterActive="{Binding DataContext.volume_filter.active, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.volume_filter.open, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterTemplate="{StaticResource ULongMinMaxTemplate}"/>
<DataGridTextColumn Header="Last" ElementStyle="{StaticResource LastPriceElement}" SortMemberPath="last_price"
<DataGridTextColumn Header="Last" ElementStyle="{StaticResource LastPriceElement}" SortMemberPath="last_price"
c:DataGridEx.CellKey="{u:Enum Last, Type={u:Nested usp:MarketViewView.Columns}}"
c:DataGridFilterProperties.Filter="{Binding DataContext.last_price_filter, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterActive="{Binding DataContext.last_price_filter.active, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.last_price_filter.open, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterTemplate="{StaticResource DoubleMinMaxTemplate}">
<DataGridTextColumn.Binding>
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
<Binding Path="last_price"/>
<Binding Path="security.ContractSpec"/>
</MultiBinding>
</DataGridTextColumn.Binding>
</DataGridTextColumn>
<DataGridTextColumn Header="Qty" ElementStyle="{StaticResource LastSizeElement}" Binding="{Binding last_size}"
<DataGridTextColumn.Binding>
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
<Binding Path="last_price"/>
<Binding Path="security.ContractSpec"/>
</MultiBinding>
</DataGridTextColumn.Binding>
</DataGridTextColumn>
<DataGridTextColumn Header="Qty" ElementStyle="{StaticResource LastSizeElement}" Binding="{Binding last_size}"
c:DataGridEx.CellKey="{u:Enum LastSize, Type={u:Nested usp:MarketViewView.Columns}}"
c:DataGridFilterProperties.Filter="{Binding DataContext.last_size_filter, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterActive="{Binding DataContext.last_size_filter.active, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.last_size_filter.open, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterTemplate="{StaticResource UShortMinMaxTemplate}"/>
<DataGridTextColumn Header="Pos" CellStyle="{StaticResource PositionCell}" Binding="{Binding position}"
<DataGridTextColumn Header="Pos" CellStyle="{StaticResource PositionCell}" Binding="{Binding position}"
c:DataGridEx.CellKey="{u:Enum Position, Type={u:Nested usp:MarketViewView.Columns}}"
c:DataGridFilterProperties.Filter="{Binding DataContext.position_filter, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterActive="{Binding DataContext.position_filter.active, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.position_filter.open, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterTemplate="{StaticResource IntMinMaxTemplate}"/>
<DataGridTemplateColumn Header="Working" SortMemberPath="working_best_bid"
<DataGridTemplateColumn Header="Working" SortMemberPath="working_best_bid"
c:DataGridEx.CellKey="{u:Enum WorkingBids, Type={u:Nested usp:MarketViewView.Columns}}"
c:DataGridFilterProperties.Filter="{Binding DataContext.working_bid_volume_filter, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterActive="{Binding DataContext.working_bid_volume_filter.active, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.working_bid_volume_filter.open, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterTemplate="{StaticResource UIntMinMaxTemplate}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock>
<Hyperlink Command="{Binding show_order_book}" Style="{StaticResource HyperlinkBidFG}">
<TextBlock Text="{Binding working_bids_text}" Foreground="{u:BTSColor MarketData.bid}"/>
</Hyperlink>
</TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Qty"
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Qty" SortMemberPath="bid_size"
c:DataGridEx.CellKey="{u:Enum BidSize, Type={u:Nested usp:MarketViewView.Columns}}"
c:DataGridFilterProperties.Filter="{Binding DataContext.bid_size_filter, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterActive="{Binding DataContext.bid_size_filter.active, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.bid_size_filter.open, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterTemplate="{StaticResource UShortMinMaxTemplate}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock>
<Hyperlink Command="{Binding show_order_ticket}" Style="{StaticResource HyperlinkBidFG}">
<TextBlock Text="{Binding bid_size}" Foreground="{u:BTSColor MarketData.bid}"/>
</Hyperlink>
</TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Bid" CellStyle="{StaticResource BidPriceCell}" SortMemberPath="bid_price"
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Bid" CellStyle="{StaticResource BidPriceCell}" SortMemberPath="bid_price"
c:DataGridEx.CellKey="{u:Enum Bid, Type={u:Nested usp:MarketViewView.Columns}}"
c:DataGridFilterProperties.Filter="{Binding DataContext.bid_price_filter, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterActive="{Binding DataContext.bid_price_filter.active, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.bid_price_filter.open, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterTemplate="{StaticResource DoubleMinMaxTemplate}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock>
<Hyperlink Command="{Binding show_order_ticket}" Style="{StaticResource HyperlinkWhiteFG}">
<TextBlock Foreground="White">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
<Binding Path="bid_price"/>
<Binding Path="security.ContractSpec"/>
</MultiBinding>
</TextBlock.Text>
<TextBlock.Text>
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
<Binding Path="bid_price"/>
<Binding Path="security.ContractSpec"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Hyperlink>
</TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Ask" CellStyle="{StaticResource AskPriceCell}" SortMemberPath="ask_price"
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Ask" CellStyle="{StaticResource AskPriceCell}" SortMemberPath="ask_price"
c:DataGridEx.CellKey="{u:Enum Ask, Type={u:Nested usp:MarketViewView.Columns}}"
c:DataGridFilterProperties.Filter="{Binding DataContext.ask_price_filter, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterActive="{Binding DataContext.ask_price_filter.active, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.ask_price_filter.open, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterTemplate="{StaticResource DoubleMinMaxTemplate}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock>
<Hyperlink Command="{Binding show_order_ticket}" Style="{StaticResource HyperlinkWhiteFG}">
<TextBlock Foreground="White">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
<Binding Path="ask_price"/>
<Binding Path="security.ContractSpec"/>
</MultiBinding>
</TextBlock.Text>
<TextBlock.Text>
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
<Binding Path="ask_price"/>
<Binding Path="security.ContractSpec"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Hyperlink>
</TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Qty"
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Qty" SortMemberPath="ask_size"
c:DataGridEx.CellKey="{u:Enum AskSize, Type={u:Nested usp:MarketViewView.Columns}}"
c:DataGridFilterProperties.Filter="{Binding DataContext.ask_size_filter, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterActive="{Binding DataContext.ask_size_filter.active, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.ask_size_filter.open, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterTemplate="{StaticResource UShortMinMaxTemplate}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock>
<Hyperlink Command="{Binding show_order_ticket}" Style="{StaticResource HyperlinkAskFG}">
<TextBlock Text="{Binding ask_size}" Foreground="{u:BTSColor MarketData.ask}"/>
</Hyperlink>
</TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Working" SortMemberPath="working_best_ask"
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Working" SortMemberPath="working_best_ask"
c:DataGridEx.CellKey="{u:Enum WorkingAsks, Type={u:Nested usp:MarketViewView.Columns}}"
c:DataGridFilterProperties.Filter="{Binding DataContext.working_ask_volume_filter, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterActive="{Binding DataContext.working_ask_volume_filter.active, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.working_ask_volume_filter.open, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterTemplate="{StaticResource UIntMinMaxTemplate}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock>
<Hyperlink Command="{Binding show_order_book}" Style="{StaticResource HyperlinkAskFG}">
<TextBlock Text="{Binding working_asks_text}" Foreground="{u:BTSColor MarketData.ask}"/>
</Hyperlink>
</TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Settlement" SortMemberPath="settlement"
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Settlement" SortMemberPath="settlement"
c:DataGridEx.CellKey="{u:Enum Settlement, Type={u:Nested usp:MarketViewView.Columns}}"
c:DataGridFilterProperties.Filter="{Binding DataContext.settlement_filter, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterActive="{Binding DataContext.settlement_filter.active, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.settlement_filter.open, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterTemplate="{StaticResource DoubleMinMaxTemplate}">
<DataGridTextColumn.Binding>
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
<Binding Path="settlement"/>
<Binding Path="security.ContractSpec"/>
</MultiBinding>
</DataGridTextColumn.Binding>
</DataGridTextColumn>
<DataGridTextColumn Header="Change" CellStyle="{StaticResource DayChangeCell}" SortMemberPath="day_change"
<DataGridTextColumn.Binding>
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
<Binding Path="settlement"/>
<Binding Path="security.ContractSpec"/>
</MultiBinding>
</DataGridTextColumn.Binding>
</DataGridTextColumn>
<DataGridTextColumn Header="Change" CellStyle="{StaticResource DayChangeCell}" SortMemberPath="day_change"
c:DataGridEx.CellKey="{u:Enum DayChange, Type={u:Nested usp:MarketViewView.Columns}}"
c:DataGridFilterProperties.Filter="{Binding DataContext.day_change_filter, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterActive="{Binding DataContext.day_change_filter.active, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.day_change_filter.open, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterTemplate="{StaticResource DoubleMinMaxTemplate}">
<DataGridTextColumn.Binding>
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
<Binding Path="day_change"/>
<Binding Path="security.ContractSpec"/>
</MultiBinding>
</DataGridTextColumn.Binding>
</DataGridTextColumn>
<DataGridTextColumn Header="Low" SortMemberPath="session_low"
<DataGridTextColumn.Binding>
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
<Binding Path="day_change"/>
<Binding Path="security.ContractSpec"/>
</MultiBinding>
</DataGridTextColumn.Binding>
</DataGridTextColumn>
<DataGridTextColumn Header="Low" SortMemberPath="session_low"
c:DataGridEx.CellKey="{u:Enum SessionLow, Type={u:Nested usp:MarketViewView.Columns}}"
c:DataGridFilterProperties.Filter="{Binding DataContext.session_low_filter, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterActive="{Binding DataContext.session_low_filter.active, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.session_low_filter.open, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterTemplate="{StaticResource DoubleMinMaxTemplate}">
<DataGridTextColumn.Binding>
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
<Binding Path="session_low"/>
<Binding Path="security.ContractSpec"/>
</MultiBinding>
</DataGridTextColumn.Binding>
</DataGridTextColumn>
<DataGridTextColumn Header="High" SortMemberPath="session_high"
<DataGridTextColumn.Binding>
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
<Binding Path="session_low"/>
<Binding Path="security.ContractSpec"/>
</MultiBinding>
</DataGridTextColumn.Binding>
</DataGridTextColumn>
<DataGridTextColumn Header="High" SortMemberPath="session_high"
c:DataGridEx.CellKey="{u:Enum SessionHigh, Type={u:Nested usp:MarketViewView.Columns}}"
c:DataGridFilterProperties.Filter="{Binding DataContext.session_high_filter, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterActive="{Binding DataContext.session_high_filter.active, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.session_high_filter.open, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterTemplate="{StaticResource DoubleMinMaxTemplate}">
<DataGridTextColumn.Binding>
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
<Binding Path="session_high"/>
<Binding Path="security.ContractSpec"/>
</MultiBinding>
</DataGridTextColumn.Binding>
</DataGridTextColumn>
<DataGridTextColumn Header="Security Key" Width="*" Binding="{Binding security_key}"
<DataGridTextColumn.Binding>
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
<Binding Path="session_high"/>
<Binding Path="security.ContractSpec"/>
</MultiBinding>
</DataGridTextColumn.Binding>
</DataGridTextColumn>
<DataGridTextColumn Header="Security Key" Width="*" Binding="{Binding security_key}"
c:DataGridEx.CellKey="{u:Enum SecurityKey, Type={u:Nested usp:MarketViewView.Columns}}"
c:DataGridFilterProperties.Filter="{Binding DataContext.security_key_filter, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterActive="{Binding DataContext.security_key_filter.active, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.security_key_filter.open, Source={u:DirectReference grid}}"
c:DataGridFilterProperties.FilterTemplate="{StaticResource RegexTemplate}"/>
</DataGrid.Columns>
</c:DataGridEx>
</Grid>
</DataGrid.Columns>
</c:DataGridEx>
</Grid>
</AdornerDecorator>
</UserControl>
@@ -1,5 +1,4 @@
using mbts.spark.filters;
using System.Windows.Controls;
using System.Windows.Controls;
namespace mbts.ui.spark {
/// <summary>
@@ -8,9 +7,7 @@ namespace mbts.ui.spark {
partial class MarketViewView : UserControl {
public enum Columns { Security, Volume, Last, LastSize, Position, WorkingBids, Bid, BidSize, Ask, AskSize, WorkingAsks, Settlement, DayChange, SessionLow, SessionHigh, SecurityKey }
public MarketViewView() {
public MarketViewView() =>
InitializeComponent();
DataGridFilterHelper.set_filter_key_event_hooks(this);
}
}
}
@@ -3,81 +3,68 @@ using bts.shell;
using bts.spark;
using mbts.ui;
using mbts.ui.spark;
using mbts.utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Windows;
using System.Windows.Media;
namespace mbts.spark {
class MarketViewWindow : SparkWindow<MarketViewWindowFactory.StartupData> {
const string _window_type = "MarketView";
readonly MarketViewWindowFactory _factory;
readonly MarketViewVM _vm;
MarketViewWindowFactory.StartupData _state;
class MarketViewWindow : SparkWindow<MarketViewWindowFactory.StartupData>, ISharedWindow {
const string _window_type = "MarketView", _thread_id = "MarketView";
readonly OrdersModel _orders_model;
readonly AllowOnce _init_guard = new AllowOnce("MarketView");
MarketViewVM _vm;
MarketViewView _view;
PartialCommand<SecurityCriteria> _criteria_callback_command;
MarketViewWindowFactory.StartupData _state;
IReadOnlyList<SparkCommand> _commands;
IDisposable _subscriptions;
MarketViewWindow(MarketViewWindowFactory factory, IBus bus, OrdersModel orders_model, ImageSource icon) : base("Market View", bus, factory, SparkCommands.ShowMarketView.icon) {
_factory = factory;
var state_src = Observable.FromEvent<Action<MarketViewWindowFactory.StartupData>, MarketViewWindowFactory.StartupData>(cb => _state_changed += cb, cb => _state_changed -= cb);
_vm = new MarketViewVM(bus, orders_model, state_src);
ITag <SecurityCriteria> _updated_security_criteria_tag = new SparkTags.SparkTag<SecurityCriteria>("MarketView Callback");
_criteria_callback_command = SparkCommand.create("Update Market View", SparkCommands.ShowMarketView.icon, _updated_security_criteria_tag);
Commands = new SparkCommand[] {
SparkCommand.create("Change Securities", Icons.Admin, SparkTags.ShowAndEditPickMultiple, () => (_criteria_callback_command, _state.security_criteria)),
public MarketViewWindow(MarketViewWindowFactory factory, IBus bus, OrdersModel orders_model, MarketViewWindowFactory.StartupData state)
: base("Market View", bus, factory, SparkCommands.ShowMarketView.icon) {
_orders_model = orders_model;
_state = state;
Icon.Freeze();
}
event Action<MarketViewWindowFactory.StartupData> _state_changed;
public override string window_type => _window_type;
public override UIElement Content => _view;
public override IEnumerable<SparkCommand> Commands => _commands;
public override MarketViewWindowFactory.StartupData SaveState => _state = new MarketViewWindowFactory.StartupData(_state.security_criteria, _vm.rows_view.GetSortingCriteria(), _vm.get_filter_states());
public override double MinWidth => 1035 + SPARK_MENU_COLLAPSED_WIDTH + LAUNCHER_BUTTON_BORDER_WIDTH;
public string thread_id => _thread_id;
public void thread_init() {
_init_guard.check_access();
Logger.notnull(_state);
var state_src = Observable.FromEvent<Action<MarketViewWindowFactory.StartupData>, MarketViewWindowFactory.StartupData>(cb => _state_changed += cb, cb => _state_changed -= cb).StartWith(_state);
_vm = new MarketViewVM(_bus, _orders_model, state_src);
_view = new MarketViewView { DataContext = _vm };
var update_securities_tag = new SparkTags.SparkTag<SecurityCriteria>("MarketView Callback");
var update_securities_cmd = SparkCommand.create("Update Market View", Icon, update_securities_tag);
_commands = new List<SparkCommand> {
SparkCommand.create("Change Securities", Icons.Admin, SparkTags.ShowAndEditPickMultiple, () => (update_securities_cmd, _state.security_criteria)),
SparkCommands.ShowLadders.complete(_vm.selected_security_mds_observable(), smds => smds.Count > 0),
// TODO: ShowLinkedLadder
SparkCommands.ShowOrderTicketFromSecurity.complete(_vm.current_security_md, md => md.HasValue, ObjectHelper.ValueOrDefault),
// TODO: ShowLinkedOrderTicket
SparkCommands.ShowFills.complete(_vm.selected_securities_observable(), _ => true,
secs => new FillsWindowFactory.StartupData(new FillsWindowFactory.FilterStates {
security = secs.Count > 0 ? new SecurityCriteria(secs) : _state.security_criteria
})
),
SparkCommands.ShowTimeAndSales.complete(_vm.selected_securities_observable(), _ => true, secs => secs.Count > 0 ? new SecurityCriteria(secs) : _state.security_criteria),
// SpreadMatrix ??
// SyntheticCreate
SparkCommands.ShowSyntheticCreate.complete(_vm.selected_securities_observable(), secs => secs.Count > 0, secs => new SecurityCriteria(secs))
// ModifyOrder - await orders
// CancelOrdersRoot ?
//SparkCommands.CancelBuyOrders,
//SparkCommands.CancelSellOrders,
//SparkCommands.CancelOrders,
SparkCommands.ShowSyntheticCreate.complete(_vm.selected_securities_observable(), secs => secs.Count > 0 && secs.Count < 3, secs => new SecurityCriteria(secs))
};
_subscriptions = _bus.subscribe(_updated_security_criteria_tag).ObserveOnDispatcher().Subscribe(c =>
_initialize(new MarketViewWindowFactory.StartupData(c, _vm.rows_view.GetSortingCriteria(), _vm.get_filter_states())));
_subscriptions = _bus.subscribe(update_securities_tag).ObserveOnDispatcher().Subscribe(c =>
_state_changed?.Invoke(_state = new MarketViewWindowFactory.StartupData(c, _vm.rows_view.GetSortingCriteria(), _vm.get_filter_states())));
}
event Action<MarketViewWindowFactory.StartupData> _state_changed;
public static MarketViewWindow create(MarketViewWindowFactory factory, IBus bus, OrdersModel orders_model, MarketViewWindowFactory.StartupData state, ImageSource icon) {
var window = new MarketViewWindow(factory, bus, orders_model, icon);
window._initialize(state);
return window;
}
public override string window_type => _window_type;
public override UIElement Content => _view;
public override IEnumerable<SparkCommand> Commands { get; }
public override MarketViewWindowFactory.StartupData SaveState => _state = new MarketViewWindowFactory.StartupData(_state.security_criteria, _vm.rows_view.GetSortingCriteria(), _vm.get_filter_states());
public override double MinWidth => 1035 + SPARK_MENU_COLLAPSED_WIDTH + LAUNCHER_BUTTON_BORDER_WIDTH;
public override void Dispose() {
Disposable.dispose(ref _subscriptions);
_vm.Dispose();
foreach (var c in Commands.OfType<IDisposable>()) c.Dispose();
}
void _initialize(MarketViewWindowFactory.StartupData state) {
Logger.notnull(state);
_state = state;
_state_changed?.Invoke(state);
if (_view == null)
_view = new MarketViewView { DataContext = _vm };
Commands.OfType<IDisposable>().DisposeAll();
}
}
}
@@ -1,5 +1,4 @@
using bts.api;
using bts.spark;
using mbts.spark;
using mbts.spark.filters;
using mbts.ui;
@@ -17,17 +16,16 @@ namespace bts.shell {
public MarketViewWindowFactory(MarketShellModule module, IBus bus, OrdersModel orders_model) : base(module, "MarketView") {
_bus = bus;
_orders_model = orders_model;
_dispose = bus.subscribe(SparkTags.ShowMarketViewTag).ObserveOnDispatcher().Subscribe(show);
_dispose = bus.subscribe(SparkTags.ShowMarketViewTag).ObserveOnDispatcher().Subscribe(_show);
}
public override Task<IShellWindow> load(StartupData state) =>
Task.FromResult(_create(state));
void show(SecurityCriteria criteria) =>
void _show(SecurityCriteria criteria) =>
_bus.post(SparkTags.ShowWindow, _create(new StartupData(criteria, new List<SortingCriteria> { new SortingCriteria(nameof(MarketViewVM.Row.security), true) }, null)));
IShellWindow _create(StartupData state) =>
MarketViewWindow.create(this, _bus, _orders_model, state, SparkCommands.PickMarketView.icon);
IShellWindow _create(StartupData state) => new MarketViewWindow(this, _bus, _orders_model, state);
[ProtoContract]
public class StartupData {
@@ -3,7 +3,8 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:u="clr-namespace:mbts.ui"
xmlns:c="clr-namespace:mbts.ui.controls"
xmlns:usp="clr-namespace:mbts.ui.spark">
xmlns:usp="clr-namespace:mbts.ui.spark"
FocusManager.IsFocusScope="True">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
@@ -1,5 +1,4 @@
using mbts.spark.filters;
using System.Windows.Controls;
using System.Windows.Controls;
namespace mbts.ui.spark {
/// <summary>
@@ -8,9 +7,7 @@ namespace mbts.ui.spark {
partial class TimeAndSalesView : UserControl {
public enum Columns { Time, Security, Price, Size, OrderType, TradeKey, SecurityKey }
public TimeAndSalesView() {
InitializeComponent();
DataGridFilterHelper.set_filter_key_event_hooks(this);
}
public TimeAndSalesView() =>
InitializeComponent();
}
}
@@ -30,6 +30,7 @@ namespace mbts.spark {
_consumer = consumer;
_factory = factory;
_state = state;
Icon.Freeze();
}
public override string window_type => _window_type;
@@ -44,18 +45,18 @@ namespace mbts.spark {
public void thread_init() {
_dispose_resources();
_vm = new SingleValuePump<TimeAndSalesVM>();
var updated_security_criteria_tag = new SparkTags.SparkTag<SecurityCriteria>("TimeAndSales Callback");
var criteria_callback_command = SparkCommand.create("Update Time and Sales", SparkCommands.ShowTimeAndSales.icon, updated_security_criteria_tag);
var update_securities_tag = new SparkTags.SparkTag<SecurityCriteria>("TimeAndSales Callback");
var update_securities_cmd = SparkCommand.create("Update Time and Sales", Icon, update_securities_tag);
var current_smd_source = _vm.observable.SelectMany(vm => vm.current_security_md_observable(_bus)).ObserveOnDispatcher();
var selected_secs_source = _vm.observable.SelectMany(vm => vm.selected_securities_observable()).ObserveOnDispatcher();
_commands = new SparkCommand[] {
SparkCommand.create("Change Securities", Icons.Admin, SparkTags.ShowAndEditPickMultiple, () => (criteria_callback_command, _state.security_criteria)),
SparkCommand.create("Change Securities", Icons.Admin, SparkTags.ShowAndEditPickMultiple, () => (update_securities_cmd, _state.security_criteria)),
SparkCommands.ShowLadder.complete(current_smd_source, md => md.HasValue, ObjectHelper.ValueOrDefault),
SparkCommands.ShowOrderTicketFromSecurity.complete(current_smd_source, md => md.HasValue, ObjectHelper.ValueOrDefault),
SparkCommands.ShowFills.complete(selected_secs_source, always_true, get_fills_startup_data),
SparkCommands.ShowMarketView.complete(selected_secs_source, always_true, secs => secs.Count > 0 ? new SecurityCriteria(secs) : _state.security_criteria)
};
_subscriptions = _bus.subscribe(updated_security_criteria_tag).ObserveOnDispatcher().Subscribe(update_criteria);
_subscriptions = _bus.subscribe(update_securities_tag).ObserveOnDispatcher().Subscribe(update_criteria);
_initialize();
bool always_true<T>(T _) => true;
@@ -16,7 +16,7 @@
<ResourceDictionary Source="/Modules/Spreader/ParameterSectionView.xaml"/>
</ResourceDictionary.MergedDictionaries>
<sys:Double x:Key="GroupLevelIndent">18</sys:Double>
<sys:Double x:Key="RowHeaderWidth">265</sys:Double>
<sys:Double x:Key="RowHeaderWidth">285</sys:Double>
<sys:Double x:Key="RowHeight">16</sys:Double>
<sys:Double x:Key="NegativeRowHeight">-16</sys:Double>
<sys:Double x:Key="ItemsHostCanBeDisabledCollapsedHeight">15</sys:Double>
@@ -104,7 +104,7 @@
</usp:DataGridParameterCellTemplateConverter.BooleanTemplate>
<usp:DataGridParameterCellTemplateConverter.DoubleTemplate>
<DataTemplate>
<c:TickUpDownDouble Value="{Binding value}" IsEnabled="{Binding enabled}"/>
<c:TickUpDownDouble Value="{Binding value}" IsEnabled="{Binding enabled}" Increment="{Binding tick_increment, FallbackValue={u:Double 1}}"/>
</DataTemplate>
</usp:DataGridParameterCellTemplateConverter.DoubleTemplate>
<usp:DataGridParameterCellTemplateConverter.IntTemplate>
@@ -299,6 +299,7 @@
ShowExpanderArrow="False" PopupPlacement="Right" Header="Add Leg" Padding="6,0"
Background="{StaticResource Button.Static.BackgroundBrush}"
IsOpen="{Binding IsNewLegPopupOpen, RelativeSource={RelativeSource AncestorType=usp:ExecutionStrategyEditor}, Mode=TwoWay}"
IsEnabled="{Binding CanUserAddNewLeg, RelativeSource={RelativeSource AncestorType=usp:ExecutionStrategyEditor}}"
>
<msp:ContractPickerView
CloseOnOK="False" CloseOnCancel="False"
@@ -52,8 +52,43 @@ namespace mbts.ui.spark {
#endregion
#region IsNew
public static readonly DependencyProperty IsNewProperty = DependencyProperty.Register(nameof(IsNew), typeof(bool), typeof(ExecutionStrategyEditor), new PropertyMetadata(false));
public bool IsNew { get => (bool)GetValue(IsNewProperty); set => SetValue(IsNewProperty, value); }
public static readonly DependencyProperty IsNewProperty =
DependencyProperty.Register(
nameof(IsNew),
typeof(bool),
typeof(ExecutionStrategyEditor),
new PropertyMetadata(false, OnIsNewChanged));
static void OnIsNewChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) =>
d.CoerceValue(CanUserAddNewLegProperty);
public bool IsNew {
get => (bool)GetValue(IsNewProperty);
set => SetValue(IsNewProperty, value);
}
#endregion
#region CanUserAddNewLeg
public static readonly DependencyProperty CanUserAddNewLegProperty =
DependencyProperty.Register(
nameof(CanUserAddNewLeg),
typeof(bool),
typeof(ExecutionStrategyEditor),
new PropertyMetadata(false, null, CoerceCanUserAddNewLeg));
static object CoerceCanUserAddNewLeg(DependencyObject d, object baseValue) {
var value = (bool)baseValue;
if (value) {
if (!((ExecutionStrategyEditor)d).IsNew)
return false;
}
return value;
}
public bool CanUserAddNewLeg {
get => (bool)GetValue(CanUserAddNewLegProperty);
set => SetValue(CanUserAddNewLegProperty, value);
}
#endregion
#region IsNewLegPopupOpen
@@ -230,7 +265,7 @@ namespace mbts.ui.spark {
if (_vm != null && _vm.GetErrors(nameof(SyntheticEditorVM.tick_factors)).Cast<string>().Any())
this.draw_border(drawing_context, _tick_combo_box.value, null, new Pen(Brushes.Red, 1));
string error_text = string.Join(", ", _vm.AllErrors);
this.draw_relative_text(RelativePosition.Below, error_text, drawing_context, _name_text_box.value, Brushes.OrangeRed, 0, y_offset);
this.draw_relative_text(RelativePosition.Below, error_text, drawing_context, _name_text_box.value, BTSColors.header_error_text_brush, 0, y_offset);
}
}
}
@@ -127,6 +127,10 @@ namespace bts.shell {
};
public static PostHedgePriceBasedForcedCross PostHedgePriceBasedForcedCross => new PostHedgePriceBasedForcedCross();
public static PostHedgeTimeBasedForcedCross PostHedgeTimeBasedForcedCross => new PostHedgeTimeBasedForcedCross();
public static PostHedgeOppositeMarketVolumeBasedForcedCross PostHedgeOppositeMarketVolumeBasedForcedCross =>
new PostHedgeOppositeMarketVolumeBasedForcedCross {
QuantityThreshold = OrderDataHelper.Defaults.QuantityMeasure
};
#endregion
public static SyntheticContract SyntheticContract(string name, IEnumerable<ContractLeg> legs) {
@@ -25,6 +25,7 @@
TickFactors="{Binding tick_factors}"
AvailableTickFactors="{Binding available_tick_factors_view}"
IsNew="{Binding is_new}"
CanUserAddNewLeg="{Binding can_add_leg}"
IsNewLegPopupOpen="{Binding is_new_leg_popup_open}"
PriceCalc="{Binding price_calc}"
ParameterRows="{Binding rows}"
@@ -6,9 +6,7 @@ namespace mbts.ui.spark {
/// Interaction logic for SyntheticManagementView.xaml
/// </summary>
internal partial class SyntheticManagementView : UserControl {
public SyntheticManagementView() {
public SyntheticManagementView() =>
InitializeComponent();
DataGridFilterHelper.set_filter_key_event_hooks(this);
}
}
}
@@ -10,6 +10,15 @@ namespace mbts.spark {
public override void set_value(LegSpreaderParamsTuple leg_tup, double value) =>
leg_tup.leg_params.QuoteParams.LeanQuantityRatio = value;
public override ICell create_cell(LegSpreaderParamsTuple leg_tup) => new HedgeRatioCell(this, leg_tup);
class HedgeRatioCell : Cell<double> {
public HedgeRatioCell(RowModelBase<double> model, LegSpreaderParamsTuple leg_tup)
: base(model, leg_tup) { }
public double tick_increment => 0.1;
}
}
}
}
@@ -0,0 +1,39 @@
using bts.shell;
using bts.spark;
using mbts.collections.extensions;
using mbts.ui.spark;
using System.Collections.Generic;
namespace mbts.spark {
partial class SyntheticEditorVM {
class PostHedgeOppositeMarketVolumeBasedCrossCrossTicksModel : RowModelBase<uint> {
IDictionary<uint, uint> _value_store = new Dictionary<uint, uint>();
public override string display_name { get; } = "Cross Ticks";
public override ParameterSection[] section_path { get; } = new[] { Sections.PostHedge, Subsections.OppositeMarketVolumeBasedCross };
public void apply_value(LegSpreaderParamsTuple leg_tup) =>
_get_omv_cross(leg_tup).CrossTicks = _value_from_store(leg_tup);
public override uint get_value(LegSpreaderParamsTuple leg_tup) =>
_get_omv_cross(leg_tup) is PostHedgeOppositeMarketVolumeBasedForcedCross omv_cross ?
omv_cross.CrossTicks :
_value_from_store(leg_tup);
public override void set_value(LegSpreaderParamsTuple leg_tup, uint value) {
_value_store[leg_tup.SecurityKey] = value;
if (_get_omv_cross(leg_tup) is PostHedgeOppositeMarketVolumeBasedForcedCross omv_cross)
omv_cross.CrossTicks = value;
}
protected override bool _get_enabled(LegSpreaderParamsTuple leg_tup) =>
_get_omv_cross(leg_tup) != null;
PostHedgeOppositeMarketVolumeBasedForcedCross _get_omv_cross(LegSpreaderParamsTuple leg_tup) =>
leg_tup.leg_params.PostHedgeParams.OppositeMarketVolumeBasedForcedCross;
uint _value_from_store(LegSpreaderParamsTuple leg_tup) =>
_value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.PostHedgeOppositeMarketVolumeBasedForcedCross.CrossTicks);
}
}
}
@@ -0,0 +1,36 @@
using bts.shell;
using mbts.ui.spark;
namespace mbts.spark {
partial class SyntheticEditorVM {
class PostHedgeOppositeMarketVolumeBasedCrossEnabledModel : RowModelBase<bool> {
readonly PostHedgeOppositeMarketVolumeBasedCrossThresholdModel _threshold;
readonly PostHedgeOppositeMarketVolumeBasedCrossCrossTicksModel _ticks;
public PostHedgeOppositeMarketVolumeBasedCrossEnabledModel(PostHedgeOppositeMarketVolumeBasedCrossThresholdModel threshold, PostHedgeOppositeMarketVolumeBasedCrossCrossTicksModel ticks) {
_threshold = threshold;
_ticks = ticks;
}
public override string display_name { get; } = string.Empty;
public override ParameterSection[] section_path { get; } = new[] { Sections.PostHedge, Subsections.OppositeMarketVolumeBasedCross };
public override bool get_value(LegSpreaderParamsTuple leg_tup) =>
leg_tup.leg_params.PostHedgeParams.OppositeMarketVolumeBasedForcedCross != null;
public override void set_value(LegSpreaderParamsTuple leg_tup, bool value) {
if (value) {
if (leg_tup.leg_params.PostHedgeParams.OppositeMarketVolumeBasedForcedCross == null) {
leg_tup.leg_params.PostHedgeParams.OppositeMarketVolumeBasedForcedCross = SyntheticDataHelper.Defaults.PostHedgeOppositeMarketVolumeBasedForcedCross;
_threshold.apply_value(leg_tup);
_ticks.apply_value(leg_tup);
}
} else {
leg_tup.leg_params.PostHedgeParams.OppositeMarketVolumeBasedForcedCross = null;
}
_threshold.set_enabled(leg_tup, value);
_ticks.set_enabled(leg_tup, value);
}
}
}
}
@@ -0,0 +1,41 @@
using bts.shell;
using bts.spark;
using mbts.collections.extensions;
using mbts.ui.spark;
using System.Collections.Generic;
namespace mbts.spark {
partial class SyntheticEditorVM {
class PostHedgeOppositeMarketVolumeBasedCrossThresholdModel : RowModelBase<QuantityMeasure> {
IDictionary<uint, QuantityMeasure> _value_store = new Dictionary<uint, QuantityMeasure>();
public override string display_name { get; } = "Threshold";
public override ParameterSection[] section_path { get; } = new[] { Sections.PostHedge, Subsections.OppositeMarketVolumeBasedCross };
public void apply_value(LegSpreaderParamsTuple leg_tup) =>
_get_omv_cross(leg_tup).QuantityThreshold = _value_from_store(leg_tup);
public override QuantityMeasure get_value(LegSpreaderParamsTuple leg_tup) =>
_get_omv_cross(leg_tup) is PostHedgeOppositeMarketVolumeBasedForcedCross omv_cross ?
omv_cross.QuantityThreshold :
_value_from_store(leg_tup);
public override void set_value(LegSpreaderParamsTuple leg_tup, QuantityMeasure value) {
_value_store[leg_tup.SecurityKey] = value;
if (_get_omv_cross(leg_tup) is PostHedgeOppositeMarketVolumeBasedForcedCross omv_cross)
omv_cross.QuantityThreshold = value;
}
public override ICell create_cell(LegSpreaderParamsTuple leg_tup) => new QuantityMeasureCell(this, leg_tup);
protected override bool _get_enabled(LegSpreaderParamsTuple leg_tup) =>
_get_omv_cross(leg_tup) != null;
PostHedgeOppositeMarketVolumeBasedForcedCross _get_omv_cross(LegSpreaderParamsTuple leg_tup) =>
leg_tup.leg_params.PostHedgeParams.OppositeMarketVolumeBasedForcedCross;
QuantityMeasure _value_from_store(LegSpreaderParamsTuple leg_tup) =>
_value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.PostHedgeOppositeMarketVolumeBasedForcedCross.QuantityThreshold);
}
}
}
@@ -123,6 +123,12 @@ namespace mbts.spark {
"forces legged hedge orders to automatically cross the market, if they are still " +
"working beyond a certain time period.If a hedge order is legged for 'Time(ms)', " +
"it is re-priced to cross the opposite inside market by 'Cross Ticks.'");
public static ParameterSection OppositeMarketVolumeBasedCross =>
new ParameterSection("Size Based Cross", true,
"forces legged hedging orders to automatically cross the market if the volume " +
"of the opposite inside market drops below the threhold. If opposite inside market volume drops below 'Threshold,' " +
"it is re-priced to cross the opposite inside market by 'Cross Ticks.'");
}
}
}
@@ -27,7 +27,7 @@ namespace mbts.spark {
readonly QuantityModel _quantity_model;
readonly PriceMultiplierModel _price_mult_model;
readonly List<IDisposable> _resources = new List<IDisposable>();
readonly Property<bool> _has_working_orders;
readonly Property<bool> _has_working_orders, _can_add_leg;
Security _synthetic;
bool _set_name_automatically, _set_ticks_automatically, _set_quantities_automatically, _set_price_mults_automatically, _is_setting_quantities, _is_setting_price_mults;
TickFactors _tick_factors;
@@ -173,6 +173,9 @@ namespace mbts.spark {
}
_is_setting_price_mults = false;
};
_can_add_leg = backing(nameof(can_add_leg), leg_tuples.ObserveSelf().Select(_ => leg_count < 2), leg_count < 2);
} else {
_can_add_leg = backing(nameof(can_add_leg), false);
}
var quote_throttle_outside_ticks = new QuoteThrottleOutsideTicksModel();
var quote_throttle_inside_ticks = new QuoteThrottleInsideTicksModel();
@@ -191,6 +194,9 @@ namespace mbts.spark {
var post_hedge_time_based_cross_ticks = new PostHedgeTimeBasedCrossMarketTicksModel();
var post_hedge_time_based_cross_time = new PostHedgeTimeBasedCrossTimeModel();
var post_hedge_opposite_market_based_cross_threshold = new PostHedgeOppositeMarketVolumeBasedCrossThresholdModel();
var post_hedge_opposite_market_based_cross_cross_ticks = new PostHedgeOppositeMarketVolumeBasedCrossCrossTicksModel();
rows = new IRowModel[] {
_quantity_model,
_price_mult_model,
@@ -214,7 +220,10 @@ namespace mbts.spark {
post_hedge_price_based_cross_market_ticks,
new PostHedgeTimeBasedCrossEnabledModel(post_hedge_time_based_cross_time, post_hedge_time_based_cross_ticks),
post_hedge_time_based_cross_time,
post_hedge_time_based_cross_ticks
post_hedge_time_based_cross_ticks,
new PostHedgeOppositeMarketVolumeBasedCrossEnabledModel(post_hedge_opposite_market_based_cross_threshold, post_hedge_opposite_market_based_cross_cross_ticks),
post_hedge_opposite_market_based_cross_threshold,
post_hedge_opposite_market_based_cross_cross_ticks
}.Select(m => new RowVM(m, leg_tuples)).ToList();
set_synthetic(synthetic, strategy);
}
@@ -243,6 +252,7 @@ namespace mbts.spark {
public bool has_working_orders => _has_working_orders.Value;
public bool is_new { get; }
public bool is_new_leg_popup_open { get; set; }
public bool can_add_leg => _can_add_leg.Value;
public SyntheticContract.Types.PriceCalc price_calc { get => _synthetic.Synthetic.PriceCalc; set => _synthetic.Synthetic.PriceCalc = value; }
public ObservableCollection<LegSpreaderParamsTuple> leg_tuples { get; } = new ObservableCollection<LegSpreaderParamsTuple>();
public int leg_count => leg_tuples.Count;
@@ -7,7 +7,7 @@ namespace bts.shell {
public static class ActivityLogCategory {
public static ILogViewerCategory order = new LogViewerCategory("Order", BTSColors.Orders.sent_brush);
public static ILogViewerCategory fill = new LogViewerCategory("Fill", BTSColors.Orders.filled_dark_brush);
public static ILogViewerCategory cancel => new LogViewerCategory("Cancel", BTSColors.Orders.working_cancel_brush);
public static ILogViewerCategory cancel = new LogViewerCategory("Cancel", BTSColors.Orders.working_cancel_brush);
public static ILogViewerCategory modify = new LogViewerCategory("Modify", BTSColors.Orders.modified_brush);
public static ILogViewerCategory warn = new LogViewerCategory("Warn", Brushes.Gold);
@@ -23,7 +23,7 @@ namespace mbts.spark {
FillsVM(IBus bus, OrdersModel model, IObservable<ITableUpdateTransform<FillTuple, string>> fills_source, IReadOnlyCollection<SortingCriteria> sorting_criteria, FilterStates filters)
: base(RXCollection.CreateTableUpdate(fills_source), sorting_criteria) {
_model = model;
account_filter = DiscreteValuesFilterVM.Create<Row, string>(_model.factory.accounts, r => r.account, nameof(Row.account));
account_filter = DiscreteValuesFilterVM.Create<Row, string>(_model.factory.accounts.ToArray(), r => r.account, nameof(Row.account));
user_filter = DiscreteValuesFilterVM.Create<Row, string>(_model.factory.users, r => r.user, nameof(Row.user));
var securities_source = fills_source
.Select(t => new HashSet<SecurityImmutable>(
@@ -118,7 +118,7 @@ namespace mbts.spark {
public OrderType order_type => _order.Def.CustomDef.CustomCase;
public OrderMetadata order_metadata => _model.factory.get_metadata(_order.Def.CustomDef.CustomCase);
public string account => _order.Def.Account;
public string user => _order.Def.Login;
public string user => _order.Def.User;
public Venue exchange => security.Exchange;
public Side side => _fill.Side;
public double price => _fill.LastPrice;
@@ -131,4 +131,4 @@ namespace mbts.spark {
public override int GetHashCode() => _fill.FillKey.GetHashCode() ^ _order.Key.GetHashCode();
}
}
}
}
@@ -1,5 +1,4 @@
using mbts.spark.filters;
using System.Windows.Controls;
using System.Windows.Controls;
namespace mbts.ui.spark {
/// <summary>
@@ -8,9 +7,7 @@ namespace mbts.ui.spark {
partial class FillsView : UserControl {
public enum Columns { FillTime, User, Account, Exchange, Security, TimeInForce, OrderType, Side, Price, Size, FillKey, OrderKey, SecurityKey, ExchangeOrderID }
public FillsView() {
public FillsView() =>
InitializeComponent();
DataGridFilterHelper.set_filter_key_event_hooks(this);
}
}
}
@@ -5,36 +5,35 @@ using mbts.ui;
using mbts.ui.spark;
using mbts.utils;
using System.Windows;
using StartupData = bts.shell.FillsWindowFactory.StartupData;
namespace mbts.spark {
class FillsWindow : SparkWindow<FillsWindowFactory.StartupData> {
const string _window_type = "Fills";
class FillsWindow : SparkWindow<StartupData>, ISharedWindow {
const string _window_type = "Fills", _thread_id = "Fills";
readonly AllowOnce _init_guard = new AllowOnce("Fills");
readonly OrdersModel _orders_model;
SingleValuePump<FillsVM> _vm = new SingleValuePump<FillsVM>();
FillsWindowFactory.StartupData _state;
FillsVM _vm;
FillsView _view;
StartupData _state;
public static FillsWindow create(FillsWindowFactory factory, IBus bus, OrdersModel orders_model, FillsWindowFactory.StartupData state) {
var window = new FillsWindow(factory, bus, orders_model);
window.initialize(state);
return window;
}
FillsWindow(FillsWindowFactory factory, IBus bus, OrdersModel orders_model) : base("Fills", bus, factory, SparkCommands.ShowFills.icon) =>
public FillsWindow(FillsWindowFactory factory, IBus bus, OrdersModel orders_model, StartupData state)
: base("Fills", bus, factory, SparkCommands.ShowFills.icon) {
_orders_model = orders_model;
public void initialize(FillsWindowFactory.StartupData state) {
Logger.notnull(state);
_state = state;
_vm.value = new FillsVM(_bus, _orders_model, state);
if (_view == null) _view = new FillsView { DataContext = _vm.value };
else _view.DataContext = _vm.value;
}
public override string window_type => _window_type;
public override UIElement Content => _view;
public override FillsWindowFactory.StartupData SaveState => _state = new FillsWindowFactory.StartupData(_state.orders, _vm.value.rows_view.GetSortingCriteria(), _vm.value.get_filters());
public override StartupData SaveState => _state = new StartupData(_state.orders, _vm.rows_view.GetSortingCriteria(), _vm.get_filters());
public override double MinWidth => 1050 + SPARK_MENU_COLLAPSED_WIDTH + LAUNCHER_BUTTON_BORDER_WIDTH;
public string thread_id => _thread_id;
public void thread_init() {
_init_guard.check_access();
Logger.notnull(_state);
_vm = new FillsVM(_bus, _orders_model, _state);
_view = new FillsView { DataContext = _vm };
}
public override void Dispose() => Disposable.dispose(ref _vm);
}
@@ -22,7 +22,7 @@ namespace bts.shell {
}
public override Task<IShellWindow> load(StartupData state) =>
Task.FromResult<IShellWindow>(FillsWindow.create(this, _bus, _orders_model, state));
Task.FromResult<IShellWindow>(new FillsWindow(this, _bus, _orders_model, state));
public async void show(StartupData state) =>
_bus.post(SparkTags.ShowWindow, await load(state));
@@ -1,6 +1,7 @@
using bts.api;
using bts.api;
using mbts;
using mbts.config;
using mbts.persist;
using mbts.spark;
using mbts.ui;
using ProtoBuf;
@@ -11,20 +12,23 @@ using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using LadderSettings = mbts.spark.LadderSettings;
namespace bts.shell {
class LadderWindowFactory : ShellWindowFactory<LadderSaveState> {
const string _window_type = "Ladder";
const string _window_type = "ladder";
readonly IBus _bus;
readonly IWindowManager _wm;
readonly UserSettingsHub _settings_hub;
readonly OrdersModel _orders_model;
readonly int _max_ladders_open;
IReadOnlyDictionary<uint, SecurityMD> _securities = new Dictionary<uint, SecurityMD>();
public LadderWindowFactory(IShellModule owner, IBus bus, IWindowManager wm, OrdersModel orders_model)
public LadderWindowFactory(IShellModule owner, IBus bus, IWindowManager wm, UserSettingsHub settings_hub, OrdersModel orders_model)
: base(owner, "SparkLadder") {
_bus = bus;
_wm = wm;
_settings_hub = settings_hub;
_orders_model = orders_model;
var window_props = Configuration.get<bts.config.IShellWindowProps>();
_max_ladders_open = (int)(window_props?.ladder?.max_total_open ?? 50);
@@ -38,7 +42,7 @@ namespace bts.shell {
public async override Task<IShellWindow> load(LadderSaveState state) {
await Wait.until_true(() => _securities.ContainsKey(state.security_key), TimeSpan.FromSeconds(15));
if (_securities.TryGetValue(state.security_key, out SecurityMD security)) {
return create_ladder_window(security, Observable.Return(state.settings));
return create_ladder_window(security, state.settings);
}
return null;
}
@@ -47,11 +51,15 @@ namespace bts.shell {
new LadderSaveState { security_key = vm.security.Id, settings = vm.get_save_state() };
int _ladder_count = 0;
IShellWindow create_ladder_window(SecurityMD md, IObservable<mbts.spark.LadderSettings> settings) {
IShellWindow create_ladder_window(SecurityMD md, LadderSettings state_settings) {
var id = Interlocked.Increment(ref _ladder_count) % Environment.ProcessorCount;
var view = new Lazy<UIElement>(() => {
var model = new LadderModel(md, _orders_model);
var vm = new LadderVM(_bus, model, settings);
var settings_manager = new WindowSettingsManager<LadderSettings>(
_settings_hub, state_settings,
us => sanitize_ladder_settings(us.ladder),
(us, v) => us.with(sanitize_ladder_settings(v)));
var vm = new LadderVM(_bus, model, settings_manager);
return new LadderView(vm);
});
string thread = Configuration.get<bts.config.toggles.LaddersOnThreads>().enabled ? $"Ladder{id:00}" : "";
@@ -60,6 +68,17 @@ namespace bts.shell {
(v,s) => save(_get_state(((LadderView)v).vm), s),
icon: Icons.Ladder,
thread_id: thread);
// if there are new props, make sure they are not null, invalid, etc.
LadderSettings sanitize_ladder_settings(LadderSettings s) {
// these MarketBreakLines are new settings props, ensure they are not null
if (s.bid_break_line == null)
s.bid_break_line = LadderSettings.Default.bid_break_line;
if (s.ask_break_line == null)
s.ask_break_line = LadderSettings.Default.ask_break_line;
if (s.mid_break_line == null)
s.mid_break_line = LadderSettings.Default.mid_break_line;
return s;
}
}
void show_windows(IReadOnlyCollection<SecurityMD> securities) {
@@ -71,8 +90,7 @@ namespace bts.shell {
BTSMessageBoxButtons.OK, MessageBoxImage.Exclamation, true, false, true);
break;
} else {
_bus.post(SparkTags.ShowWindow,
create_ladder_window(s, Observable.Return(_orders_model.factory.default_ladder_settings(s.security))));
_bus.post(SparkTags.ShowWindow, create_ladder_window(s, null));
}
}
}
@@ -1,5 +1,6 @@
using bts.api;
using bts.spark;
using mbts.persist;
using mbts.spark;
using mbts.ui;
using System.Collections.Generic;
@@ -9,9 +10,7 @@ using System.Threading.Tasks;
using System.Windows.Media;
using static mbts.ui.shell.ProtoBufSerializationHelper;
namespace bts.shell
{
namespace bts.shell {
[Export(typeof(IShellModule))]
class TradingShellModule : IShellModule {
LadderWindowFactory _lwf;
@@ -20,8 +19,8 @@ namespace bts.shell
PAndLWindowFactory _plwf;
[ImportingConstructor]
public TradingShellModule(IBus bus, IWindowManager wm, OrdersModel orders_model, PAndLModel pandl_model) {
_lwf = new LadderWindowFactory(this, bus, wm, orders_model);
public TradingShellModule(IBus bus, IWindowManager wm, UserSettingsHub settings_hub, OrdersModel orders_model, PAndLModel pandl_model) {
_lwf = new LadderWindowFactory(this, bus, wm, settings_hub, orders_model);
_obwf = new OrderBookWindowFactory(this, bus, orders_model);
_fwf = new FillsWindowFactory(this, bus, orders_model);
_plwf = new PAndLWindowFactory(this, bus, pandl_model);
@@ -57,5 +56,4 @@ namespace bts.shell
if (i != null) i.Dispose();
}
}
}
}
@@ -23,6 +23,8 @@ namespace bts.spark {
readonly IBus _bus;
IReadOnlyDictionary<uint, SecurityMD> _security = new Dictionary<uint, SecurityMD>();
IDisposable _dispose;
static readonly IEqualityComparer<OrderRecordImmutable> _id_comparer =
mbts.utils.EqualityComparer.Create<OrderRecordImmutable, uint>(a => a.Key);
public OrderActivitySummarizer(IBus bus, IObservable<TableUpdate<OrderRecordImmutable, uint>> orders) {
_bus = bus;
@@ -92,8 +94,8 @@ namespace bts.spark {
void orders_updated(TableUpdate<OrderRecordImmutable, uint> update) {
// Go though added and changed orders
var added = new HashSet<OrderRecordImmutable>(update.added);
var changed = new HashSet<OrderRecordImmutable>(update.added);
var added = new HashSet<OrderRecordImmutable>(update.added, _id_comparer);
var changed = new HashSet<OrderRecordImmutable>(update.added, _id_comparer);
var removed = update.removed.ToDictionary(o => o.Key);
added.ExceptWith(update.removed);
changed.ExceptWith(added);
+2 -2
View File
@@ -19,10 +19,10 @@ namespace mbts.ui.spark
_ask_pen.Freeze();
}
private static readonly Pen _bid_pen = new Pen(BTSColors.MarketData.bid_brush, 4), _ask_pen = new Pen(BTSColors.MarketData.ask_brush, 4);
private static readonly ConcurrentDictionary<uint, Brush> _algo_pallete = new ConcurrentDictionary<uint, Brush>();
private static readonly ConcurrentDictionary<uint, Brush> _algo_palette = new ConcurrentDictionary<uint, Brush>();
public static ImageSource Create(OrderMetadata metadata, Side side) {
Brush brush = _algo_pallete.GetOrAdd(metadata.Color, c => {
Brush brush = _algo_palette.GetOrAdd(metadata.Color, c => {
Brush b = new SolidColorBrush(c.rgb_color());
b.Freeze();
return b;
@@ -2,23 +2,22 @@
using bts.api.orderman;
using mbts.ui;
using mbts.ui.shell;
using mbts.ui.utility;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Reactive.Linq;
using System.Windows.Input;
using System.Reactive.Subjects;
namespace mbts.spark {
namespace mbts.spark {
class InlineOrderProperties {
public readonly InlineUserProperty<string> account;
public readonly InlineUserProperty<TimeInForce> time_in_force;
public readonly InlineUserProperty<CustomOrderDefinition> order_type_def;
public InlineOrderProperties(OrdersModel model, LadderSettings settings) : this(
new InlineUserProperty<string>(model.factory.default_account, true),
new InlineUserProperty<string>(model.factory.default_account, false),
new InlineUserProperty<TimeInForce>(settings.default_time_in_force, true),
new InlineUserProperty<CustomOrderDefinition>(model.factory.custom_order(settings.default_order_type), true)) { }
@@ -39,148 +38,104 @@ namespace mbts.spark {
class OrderPropertiesEditorVM : DisposableViewModelBase {
readonly OrdersModel _model;
readonly ObservableCollection<CustomOrderDefinition.CustomOneofCase> _order_types_model =
new ObservableCollection<CustomOrderDefinition.CustomOneofCase>(EnumHelper.get_values_except(CustomOrderDefinition.CustomOneofCase.None));
Property<string> _selected_account;
Property<TimeInForce> _selected_time_in_force;
IOrderTypeVM _selected_order_type;
readonly Property<SecurityImmutable> _security;
readonly SelectorProperty<string> _accounts;
readonly SelectorProperty<TimeInForce> _time_in_force;
readonly SelectorProperty<IOrderTypeVM> _order_type;
IDisposable _order_type_param_errors_sub;
public OrderPropertiesEditorVM(OrdersModel model, IObservable<SecurityImmutable> security_source, IObservable<InlineOrderProperties> order_properties) {
_model = model;
accounts = model.factory.accounts;
order_types = new ObservableAutoWrapper<IOrderTypeVM, CustomOrderDefinition.CustomOneofCase>(_order_types_model, ot => OrderTypeVMFactory.create(ot, model, security_source));
_selected_account = backing(nameof(selected_account), string.Empty, val => val != null && accounts.Contains(val));
_selected_time_in_force = backing(nameof(selected_time_in_force), TimeInForce.Undefined, time_in_forces.Contains);
InlineOrderProperties props = new InlineOrderProperties();
_dispose = Disposable.Create(
security_source.ObserveOnDispatcher().Subscribe(s => {
security = s;
_order_types_model.sync_with(model.factory.default_order_types(security));
if (props.order_type_def.has_value) {
if (props.order_type_def.force_override || selected_order_type == null || !order_types.Contains(selected_order_type)) {
if (order_types.TryGetFirst(ot => ot.order_type == props.order_type_def.value.CustomCase, out IOrderTypeVM match)) {
match.load_from(props.order_type_def.value);
selected_order_type = match;
}
} else if (selected_order_type == null || !order_types.Contains(selected_order_type))
selected_order_type = order_types.FirstOrDefault();
}
time_in_forces.sync_with(model.factory.default_time_in_forces(security));
auto_select_time_in_force();
security_changed?.Invoke(s);
RaisePropertyChanged(nameof(security));
}),
order_properties.ObserveOnDispatcher().Subscribe(p => {
props = p;
auto_select_account();
auto_select_time_in_force();
auto_select_order_type();
})
);
#region Auto Select
void auto_select_account() =>
auto_select_prop(props.account, _selected_account, accounts, () => model.factory.default_account);
void auto_select_time_in_force() =>
auto_select_prop(props.time_in_force, _selected_time_in_force, time_in_forces, () => model.factory.default_time_in_force(security));
void auto_select_prop<T>(InlineUserProperty<T> inline_prop, Property<T> prop, IReadOnlyList<T> choices, Func<T> get_default) {
if (inline_prop.has_value && choices.Contains(inline_prop.value)) {
if (inline_prop.force_override || has_errors(prop.name)) {
prop.Value = inline_prop.value;
}
} else if (has_errors(prop.name)) {
prop.Value = get_default();
}
_security = backing(nameof(security), security_source.ObserveOnDispatcher(), SecurityDataHelper.Defaults.SecurityImmutable);
// guarentee that "this.security" will always be set before observers are notified
// this is important bc some observers will reference "this.security" in their callbacks
// - namely the [SelectorProperty]order_type's "get_default" function,
// which may be called in response to its items changing, which are driven by the observable security
// (see 'get_default_order_type_vm')
security_source = _security.observe_current(true).Replay(1).RefCount();
_accounts = backing(
nameof(selected_account),
model.factory.subscribe_accounts(),
order_properties.Select(ops => ops.account),
() => string.Empty,
val => (!String.IsNullOrWhiteSpace(val) && accounts.Contains(val), "Please select an account"));
_time_in_force = backing(
nameof(selected_time_in_force),
security_source.Select(s => model.factory.default_time_in_forces(s)),
order_properties.Select(ops => ops.time_in_force),
() => model.factory.default_time_in_force(security),
tif => time_in_forces.Contains(tif));
_order_type = backing(
nameof(selected_order_type),
security_source.Select(s => model.factory.default_order_type_defs(s).Select(create_order_type_vm)),
order_properties.Select(get_order_type_vm_prop),
get_default_order_type_vm,
(a, b) => a.order_type == b.order_type);
_order_type.Changed += on_selected_order_type_changed;
_dispose = Disposable.Create(() => _order_type.Changed -= on_selected_order_type_changed);
// local methods
IOrderTypeVM create_order_type_vm(CustomOrderDefinitionImmutable cd) {
var vm = OrderTypeVMFactory.create(cd.CustomCase, model, security_source);
vm.load_from(cd);
return vm;
}
void auto_select_order_type() {
bool invalid = has_errors(nameof(selected_order_type));
if (props.order_type_def.has_value) {
if (invalid) {
if (try_select_type(props.order_type_def.value.CustomCase)) {
selected_order_type.load_from(props.order_type_def.value);
} else {
select_default_value();
}
} else if (props.order_type_def.force_override) {
try_select_type(props.order_type_def.value.CustomCase);
}
} else if (invalid) {
select_default_value();
}
void select_default_value() {
var ot = model.factory.default_order_type(security);
if (!try_select_type(ot))
selected_order_type = order_types.FirstOrDefault();
}
bool try_select_type(CustomOrderDefinition.CustomOneofCase type) {
if (order_types.TryGetFirst(ot => ot.order_type == type, out IOrderTypeVM result)) {
selected_order_type = result;
return true;
}
return false;
}
InlineUserProperty<IOrderTypeVM> get_order_type_vm_prop(InlineOrderProperties p) {
if (!p.order_type_def.has_value)
return new InlineUserProperty<IOrderTypeVM>();
return new InlineUserProperty<IOrderTypeVM>(create_order_type_vm(p.order_type_def.value), p.order_type_def.force_override);
}
#endregion
}
public event Action<SecurityImmutable> security_changed;
event Action<IOrderTypeVM> _selected_order_type_changed;
public SecurityImmutable security { get; private set; } = SecurityDataHelper.Defaults.SecurityImmutable;
public string[] accounts { get; }
public string selected_account { get => _selected_account.Value; set => _selected_account.Value = value; }
public ObservableCollection<TimeInForce> time_in_forces { get; } = new ObservableCollection<TimeInForce>();
public TimeInForce selected_time_in_force { get => _selected_time_in_force.Value; set => _selected_time_in_force.Value = value; }
public ObservableAutoWrapper<IOrderTypeVM, CustomOrderDefinition.CustomOneofCase> order_types { get; }
public IOrderTypeVM selected_order_type {
get => _selected_order_type;
set {
Disposable.dispose(ref _order_type_param_errors_sub);
_selected_order_type = value;
if (value == null) {
IOrderTypeVM get_default_order_type_vm() {
var ot = model.factory.default_order_type(security);
if (order_types.TryGetFirst(vm => vm.order_type == ot, out IOrderTypeVM result))
return result;
return order_types.FirstOrDefault();
}
void on_selected_order_type_changed(IOrderTypeVM old_val, IOrderTypeVM new_val) {
if (new_val == null) {
assert(false);
} else {
assert(order_types.Contains(value));
value.init();
if (value is INotifyDataErrorInfo ndei) {
assert(order_types.Contains(new_val));
new_val.init();
if (new_val is INotifyDataErrorInfo ndei) {
assert_no_param_errors();
_order_type_param_errors_sub = ndei.subscribe_errors_changed((s, e) => assert_no_param_errors());
void assert_no_param_errors() => assert(!ndei.HasErrors, "order type pararmeters invalid.");
}
}
RaisePropertyChanged();
_selected_order_type_changed?.Invoke(_selected_order_type);
}
}
public ICommand set_price_command { get; }
public SecurityImmutable security => _security.Value;
public ReadOnlyObservableCollection<string> accounts => _accounts.items;
public string selected_account { get => _accounts.selected_item; set => _accounts.selected_item = value; }
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 ReadOnlyObservableCollection<IOrderTypeVM> order_types => _order_type.items;
public IOrderTypeVM selected_order_type { get => _order_type.selected_item; set => _order_type.selected_item = value; }
public IObservable<string> observe_account(bool start_immediately = false) =>
_selected_account.observe_current(start_immediately);
_accounts.observe_current(start_immediately);
public IObservable<TimeInForce> observe_time_in_force(bool start_immediately = false) =>
_selected_time_in_force.observe_current(start_immediately);
_time_in_force.observe_current(start_immediately);
public IObservable<IOrderTypeVM> observe_order_type(bool start_immediately = false) {
var source = Observable.FromEvent<Action<IOrderTypeVM>, IOrderTypeVM>(cb => _selected_order_type_changed += cb, cb => _selected_order_type_changed -= cb);
if (start_immediately)
source = source.StartWith(_selected_order_type);
return source;
}
public IObservable<IOrderTypeVM> observe_order_type(bool start_immediately = false) =>
_order_type.observe_current(start_immediately);
public OrderDefinition create(Side side) {
if (HasErrors) throw new InvalidOperationException("Cannot create order when errors are present.");
var order = _model.factory.order(security);
order.Account = selected_account;
order.AccountId = _model.factory.get_account_id(selected_account);
order.TimeInForce = selected_time_in_force;
order.Side = side;
_selected_order_type.assign_to(order.CustomDef);
selected_order_type.assign_to(order.CustomDef);
return order;
}
protected override void Dispose(bool disposing) {
base.Dispose(disposing);
Disposable.dispose(ref _order_type_param_errors_sub);
}
}
}
@@ -18,7 +18,7 @@ namespace mbts.spark {
ExceptionAssert.InvalidOperation.That(child_order_types.Contains(selected_child_order_type), $"Child order type {selected_child_order_type} is not in child_order_types");
this.selected_child_order_type = new InlineUserProperty<CustomOneofCase>(selected_child_order_type, true);
this.child_order_types = new InlineUserProperty<IReadOnlyCollection<CustomOneofCase>>(child_order_types, true);
show_quantity = new InlineUserProperty<double>(0, true);
show_quantity = new InlineUserProperty<double>(1, true);
}
public readonly InlineUserProperty<CustomOneofCase> selected_child_order_type;
public readonly InlineUserProperty<IReadOnlyCollection<CustomOneofCase>> child_order_types;
+1
View File
@@ -15,6 +15,7 @@
<ResourceDictionary Source="/view/Controls/DragDropItemsControl/DraggableContentControl.xaml" />
<ResourceDictionary Source="/view/Controls/DragDropItemsControl/DragDropListBox.xaml" />
<ResourceDictionary Source="/view/Controls/DragDropItemsControl/DraggableListBoxItem.xaml" />
<ResourceDictionary Source="/view/Controls/DialogSkirts/DialogSkirt.xaml"/>
<ResourceDictionary Source="/view/Controls/DialogSkirts/DialogSkirtOKCancel.xaml" />
<ResourceDictionary Source="/view/Controls/DialogSkirts/DialogSkirtOKApplyCancel.xaml" />
<ResourceDictionary Source="/view/Controls/ComboCheckBox/ComboCheckBox.xaml" />
@@ -0,0 +1,80 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
namespace mbts.ui.controls {
class ObservableAggregateCollection<T> : ObservableCollection<T> {
readonly List<ObservableCollection<T>> _collections = new List<ObservableCollection<T>>();
public ObservableAggregateCollection(params ObservableCollection<T>[] collections) {
foreach (var c in collections)
add_collection(c);
}
public void add_collection(ObservableCollection<T> collection) {
this.AddRange(collection);
_collections.Add(collection);
collection.CollectionChanged += _on_collection_changed;
}
public void remove_collection(ObservableCollection<T> collection) {
_remove_collection_items(collection, out int _, out int collection_index);
_collections.RemoveAt(collection_index);
collection.CollectionChanged -= _on_collection_changed;
}
public void clear_collections() {
foreach (var c in _collections)
c.CollectionChanged -= _on_collection_changed;
Clear();
}
void _on_collection_changed(object sender, NotifyCollectionChangedEventArgs e) {
int offset = _get_collection_start(sender);
switch (e.Action) {
case NotifyCollectionChangedAction.Add: this.InsertRange(e.NewStartingIndex + offset, e.NewItems); break;
case NotifyCollectionChangedAction.Remove: this.RemoveRange(e.OldStartingIndex + offset, e.OldItems.Count); break;
case NotifyCollectionChangedAction.Move: Move(e.OldStartingIndex + offset, e.NewStartingIndex + offset); break;
case NotifyCollectionChangedAction.Replace:
this.RemoveRange(e.OldStartingIndex + offset, e.OldItems.Count);
this.InsertRange(e.NewStartingIndex + offset, e.NewItems);
break;
case NotifyCollectionChangedAction.Reset:
var c = (ObservableCollection<T>)sender;
_remove_collection_items(c, out int starting_index, out int _);
_add_items(c, starting_index);
break;
}
}
void _add_items(IList items, int index) {
foreach (T item in items)
Insert(index++, item);
}
void _remove_items(IList items, int index) {
foreach (var item in items)
RemoveAt(index);
}
void _remove_collection_items(ObservableCollection<T> collection, out int starting_index, out int collection_index) {
int ex_count = 0;
int i = 0;
for (; i < _collections.Count; i++) {
if (_collections[i] == collection)
break;
else ex_count += _collections[i].Count;
}
starting_index = ex_count;
collection_index = i;
for (++i; i < _collections.Count; i++)
ex_count += _collections[i].Count;
this.RemoveRange(starting_index, Count - ex_count);
}
int _get_collection_start(object sender) =>
_collections.TakeWhile(c => c != sender).Sum(c => c.Count);
}
}
@@ -6,21 +6,27 @@ namespace mbts.ui {
// Value = "{mbts:BTSColor X.y}"
// Some colos are also available as static resources in colors.xaml
public static class BTSColors {
static Brush _header_brush, _header_text_brush, _header_alternate_brush;
static Brush _header_brush, _header_text_brush, _header_alternate_brush, _header_error_text_brush;
static BTSColors() {
_header_brush = new SolidColorBrush(header);
_header_text_brush = new SolidColorBrush(header_text);
_header_alternate_brush = new SolidColorBrush(header_alternate);
_header_brush.Freeze();
_header_text_brush.Freeze();
_header_alternate_brush.Freeze();
_init_brush(header, out _header_brush);
_init_brush(header_text, out _header_text_brush);
_init_brush(header_alternate, out _header_alternate_brush);
_init_brush(header_error_text, out _header_error_text_brush);
}
// freezing brushes makes them thread-safe
static void _init_brush(BTSColor color, out Brush brush) {
brush = color;
brush.Freeze();
}
[DisplayInfo(name = "Default Header")]
public static BTSColor header { get { return BTSCoreColors.base_blue; } }
public static Brush header_brush { get { return _header_brush; } }
public static BTSColor header_text { get { return BTSCoreColors.white; } }
public static BTSColor header_error_text { get; } = new BTSColor(0xFE, 0x6A, 0x6E);
public static Brush header_error_text_brush => _header_error_text_brush;
public static BTSColor header_border { get { return new BTSColor(0x63,0x8A,0xCC); } }
public static Brush header_text_brush { get { return _header_text_brush; } }
public static BTSColor header_alternate { get { return BTSCoreColors.blue_grey; } }
@@ -312,6 +312,9 @@ namespace System.Collections.Generic {
}
#endregion
public static bool is_null_or_empty<T>(this IEnumerable<T> source) =>
source == null || !source.Any();
public static void DisposeAll(this IEnumerable<IDisposable> source) {
foreach (IDisposable d in source)
d.Dispose();
@@ -334,6 +337,38 @@ namespace System.Collections.Generic {
collection.Clear();
collection.AddRange(items);
}
public static bool within_range<T>(this ICollection<T> collection, int index) =>
index >= 0 && index < collection.Count;
public static bool within_range<T>(this T[] array, int index) =>
index >= 0 && index < array.Length;
public static T at_or_nearest<T>(this T[] array, int index) {
if (index < 0) {
return array.Length > 0 ? array[0] : default;
} else if (index >= array.Length) {
return array[array.Length - 1];
} else return array[index];
}
public static bool try_get_at_index<T>(this T[] array, int index, out T result) {
if (array.within_range(index)) {
result = array[index];
return true;
}
result = default;
return false;
}
public static bool TryGetItem<TKey, TItem>(this KeyedCollection<TKey, TItem> keyed_collection, TKey key, out TItem result) {
if (keyed_collection.Contains(key)) {
result = keyed_collection[key];
return true;
}
result = default;
return false;
}
}
public static class DictionaryExtensions
@@ -134,11 +134,17 @@ namespace mbts
return -1;
}
public static bool safe_equals<T>(this T a, T b, Func<T, T, bool> equals_func = null) where T : IEquatable<T> {
if (a == null && b == null) return true;
if (a == null || b == null) return false;
return equals_func != null ? equals_func(a, b) : a.Equals(b);
}
public static int safe_compare<T>(this T a, T b, Func<T, T, int> compare) =>
a == null ? (b == null ? 0 : -1) : (b == null ? 1 : compare(a, b));
public static int safe_compare<T>(this T a, T b) where T : IComparable<T> =>
a == null ? (b == null ? 0 : -1) : (b == null ? 1 : a.CompareTo(b));
public static bool safe_equals<T>(this T a, T b, Func<T, T, bool> equals) =>
a == null ? b == null : b != null && equals(a, b);
public static bool safe_equals<T>(this T a, T b) where T : IEquatable<T> =>
a == null ? b == null : b != null && a.Equals(b);
public static IDictionary<K, V> sync<K, V>(this IDictionary<K, V> data_map, IEnumerable<K> master_keys, bool remove_extra, Func<K, V> get_missing) {
HashSet<K> master_key_map = new HashSet<K>(master_keys);
@@ -43,5 +43,16 @@
public static T ValueOrDefault<T>(T? nullable) where T : struct => nullable.HasValue ? nullable.Value : default;
public static bool is_compatible<T>(object obj) { return obj is T || (obj == null && default(T) == null); }
public static bool try_convert_args<T1, T2>(object[] args, out T1 arg1, out T2 arg2) {
if (args == null || args.Length != 2) {
arg1 = default;
arg2 = default;
return false;
}
bool rv = try_convert(args[0], out arg1);
rv |= try_convert(args[1], out arg2);
return rv;
}
}
}
@@ -0,0 +1,30 @@
using ProtoBuf;
namespace mbts.spark {
/// <summary>
/// The settings Mothership. All window - and any other future user based - settings should have a corresponding default member here.
/// </summary>
[ProtoContract]
class UserSettings {
public static UserSettings factory_defaults =>
new UserSettings {
_ladder = LadderSettings.Default
};
[ProtoMember(1)]
LadderSettings _ladder;
public UserSettings() { }
public LadderSettings ladder => _ladder;
public UserSettings with(LadderSettings ladder) =>
new UserSettings {
_ladder = ladder
};
public static class FileExtensions {
public const string LADDER = "ladder";
}
}
}
@@ -0,0 +1,46 @@
using mbts.spark;
using System;
using System.ComponentModel.Composition;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Threading.Tasks;
namespace mbts.persist {
/// <summary>
/// Represents the top level of the persisted settings hierarchy.
/// One UserSettings object, which contains the defaults for every SparkWindow, can be read/written on the server by UISettingsHub.
/// </summary>
[Export(typeof(UserSettingsHub))]
class UserSettingsHub {
// do NOT CHANGE these consts, they represent a file path on the server
const string NAME_SPACE = "settings", DEFAULT_KEY = "default";
IUserPersist _persist;
UserSettings _default_settings;
readonly Subject<UserSettings> _default_settings_subject = new Subject<UserSettings>();
[ImportingConstructor]
public UserSettingsHub(IUserPersist persist) {
_persist = persist;
init();
async void init() =>
_set_and_notify(await _persist.get<UserSettings>(NAME_SPACE, DEFAULT_KEY));
}
/// Subscribing via _persist.subscribe may be cleaner in theory, however using a local event allows observers to be notified immediately.
/// Assuming there aren't any rogue agents saving UserSettings by themselves, there should never be any discrepancies.
public IObservable<UserSettings> subscribe_default_settings() => _default_settings_subject.AsObservable();
internal UserSettings current => _default_settings ?? UserSettings.factory_defaults;
public async Task save_default(UserSettings value) {
_set_and_notify(value);
await _persist.set(NAME_SPACE, DEFAULT_KEY, value);
}
void _set_and_notify(UserSettings value) {
_default_settings = value;
// notify observers before persisting so the changes are reflected immediately in the ui
_default_settings_subject.OnNext(value);
}
}
}
@@ -0,0 +1,66 @@
using mbts.spark;
using System;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
namespace mbts.persist {
interface IWindowSettingsManager<T> where T : class {
T instance_settings { get; set; }
T default_settings { get; }
event Action<T> instance_settings_changed;
IObservable<T> subscribe_default();
Task save_default_settings(T value);
}
class WindowSettingsManager<T> : IWindowSettingsManager<T> where T : class {
readonly UserSettingsHub _hub;
readonly Func<UserSettings, T> _get;
readonly Func<UserSettings, T, UserSettings> _set;
T _instance_settings;
public WindowSettingsManager(UserSettingsHub hub, T instance_settings, Func<UserSettings, T> get, Func<UserSettings, T, UserSettings> set) {
_hub = hub;
_instance_settings = instance_settings;
_get = get;
_set = set;
}
public T instance_settings {
get => _instance_settings;
set {
_instance_settings = value;
instance_settings_changed?.Invoke(value);
}
}
public T default_settings => _get(_hub.current);
public event Action<T> instance_settings_changed;
public async Task save_default_settings(T value) =>
await _hub.save_default(_set(_hub.current, value));
public IObservable<T> subscribe_default() =>
_hub.subscribe_default_settings().Select(_get).DistinctUntilChanged();
}
static class WindowSettingsManagerExtensions {
/// <summary>
/// Returns an observable sequence of the settings object used by a particular window.
/// <para/>Note: 'Instance' settings take priority over 'default' settings. While the former is present, any changes to the latter will be ignored.
/// </summary>
public static IObservable<T> subscribe_current<T>(this IWindowSettingsManager<T> wsm) where T : class =>
Observable.CombineLatest(
Observable.FromEvent<Action<T>, T>(cb => wsm.instance_settings_changed += cb, cb => wsm.instance_settings_changed -= cb)
.StartWith(wsm.instance_settings),
wsm.subscribe_default()
.StartWith(wsm.default_settings),
(i, d) => i ?? d
).Where(v => v != null)
.DistinctUntilChanged();
public static T current_settings<T>(this IWindowSettingsManager<T> wsm) where T : class =>
wsm.instance_settings ?? wsm.default_settings;
}
}
@@ -0,0 +1,18 @@
using System;
namespace mbts.utils {
public static class CompareUtils {
#region Equality
public static bool NullCheckEquals<T>(T x, T y) =>
NullCheckEquals(x, y, (_x, _y) => _x.Equals(_y));
public static bool NullCheckEquals<T>(T x, T y, Func<T, T, bool> never_null_equals) =>
x == null ? y == null : y == null ? false : never_null_equals(x, y);
#endregion
#region Comparison
public static Comparison<T> safe_comparison<T>(Func<T, T, int> compare) =>
(a, b) => a.safe_compare(b, compare);
#endregion
}
}
@@ -0,0 +1,22 @@
using System.Threading;
namespace mbts.utils {
class ThreadSafeCounter {
int _count = 0;
public int increment() => Interlocked.Increment(ref _count);
public int decrement() => Interlocked.Decrement(ref _count);
}
class AllowOnce {
readonly ThreadSafeCounter _counter = new ThreadSafeCounter();
readonly string _name;
public AllowOnce(string name) => _name = name;
/// <summary>
/// After this method is called once, subsequent calls will result in the Application being terminated via Logger.assert.
/// </summary>
public void check_access() =>
Logger.assert(_counter.increment() == 1, $"AllowOnce '{_name}' check_access was called twice.");
}
}
+217 -18
View File
@@ -8,6 +8,7 @@ using System.Reflection;
using System.Windows.Input;
using System.Linq.Expressions;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
namespace mbts.ui.shell
{
@@ -102,6 +103,7 @@ namespace mbts.ui.shell
#endregion
#region automatic property
protected delegate void PropertyChange<T>(T oldval, T newval);
// use nameof() to add compile time checks
protected Property<T> backing<T>(string name, T default_value = default(T)) {
@@ -113,8 +115,8 @@ namespace mbts.ui.shell
return new Property<T>(this, exp.Member.Name, default_value);
}
protected DelegateProperty<T> backing<T>(string name, Func<T> get_value) {
return new DelegateProperty<T>(this, name, get_value);
protected DelegateProperty<T> backing<T>(string name, Func<T> get_value, params string[] invalidating_props) {
return new DelegateProperty<T>(this, name, get_value, invalidating_props);
}
protected class Property<T> : IObservable<(T oldval,T newval)> {
@@ -128,9 +130,7 @@ namespace mbts.ui.shell
_value = default_value;
}
public delegate void PropertyChange(T oldval, T newval);
public event PropertyChange Changing;
public event PropertyChange Changed;
public event PropertyChange<T> Changing, Changed;
public string name => _propname;
@@ -145,11 +145,9 @@ namespace mbts.ui.shell
}
public IDisposable Subscribe(IObserver<(T oldval, T newval)> observer) {
PropertyChange pch = (o, n) => observer.OnNext((o, n));
Changed += pch;
return Disposable.Create(() => {
Changed -= pch;
});
return Disposable.Create(() => Changed -= pch);
void pch(T o, T n) => observer.OnNext((o, n));
}
public IObservable<T> observe_current(bool start_immediately = false) {
@@ -166,11 +164,19 @@ namespace mbts.ui.shell
}
protected class DelegateProperty<T> : Property<T> {
public DelegateProperty(ViewModelBase owner, string name, Func<T> get_value) : base(owner, name, get_value()) {
public DelegateProperty(ViewModelBase owner, string name, Func<T> get_value, params string[] invalidating_props)
: base(owner, name, get_value()) {
_get_value = get_value;
if (invalidating_props != null && invalidating_props.Length > 0) {
var iprop_set = new HashSet<string>(invalidating_props);
owner.PropertyChanged += (s, e) => {
if (iprop_set.Contains(e.PropertyName))
refresh();
};
}
}
private readonly Func<T> _get_value;
readonly Func<T> _get_value;
public void refresh() { set(_get_value()); }
}
@@ -312,17 +318,22 @@ namespace mbts.ui.shell
public IEnumerable<string> AllErrors { get { return _errors.Values; } }
#endregion
protected Property<T> backing<T>(string name, T default_value, params Func<T, bool>[] validation_steps) =>
backing(name, default_value, validation_steps.Select(v => new PropertyValidation<T>(v)).ToLArray());
protected Property<T> backing<T>(string name, T default_value, bool validate_now = false, params Func<T, bool>[] validation_steps) =>
backing(name, default_value, validation_steps.Select(v => new PropertyValidation<T>(v)).ToLArray(), validate_now);
protected Property<T> backing<T>(string name, T default_value, IEnumerable<PropertyValidation<T>> validation_steps) {
var prop = new Property<T>(this, name, default_value);
prop.Changed += (old_val, new_val) => {
protected Property<T> backing<T>(string name, T default_value, IEnumerable<PropertyValidation<T>> validation_steps, bool validate_now = false) {
void run_validation(T val) {
foreach (var pv in validation_steps) {
(bool valid, string msg) = pv.validate(new_val);
(bool valid, string msg) = pv.validate(val);
assert(valid, name, msg);
}
};
var prop = new Property<T>(this, name, default_value);
prop.Changed += (old_val, new_val) => run_validation(new_val);
if (validate_now) {
run_validation(prop.Value);
}
return prop;
}
@@ -350,7 +361,72 @@ namespace mbts.ui.shell
return prop;
}
/// <summary>
/// Use this generic overload when the [T]value must be created from the [TData]data on this thread, and a simple observable.Select() call will not work.
/// <para/>Note: UI settings in particular may find this useful, as brushes and other Freezable types are not inherently thread safe.
/// </summary>
protected Property<T> backing<T, TData>(string name, IObservable<TData> source, Func<TData, T> select, T default_value = default) {
if (_observable_properties == null) _observable_properties = new List<IDisposable>();
var prop = new ObservablePropertySink<T>(this, name, default_value);
_observable_properties.Add(source.ObserveOnDispatcher().Subscribe(d => prop.set(select(d))));
return prop;
}
/// <summary>
/// Returns a SelectorProperty&lt;T&gt; that observes an items source, and a desired item. When either observable ticks, it determines whether or not to assign the selected_item property.
/// <para/>Notes: If the user has selected an item (ie the selected_item has been assigned through the public setter), the desired item will be ignored unless force_override is true.
/// <para/>If the user has not selected an item, but the current items do not contain the desired item, it will re-evaluate whether or not to select the item when new items arrive.
/// </summary>
protected SelectorProperty<T> backing<T>(string name, IObservable<IEnumerable<T>> items, IObservable<InlineUserProperty<T>> desired_item, Func<T> select_default, params Func<T, bool>[] validation_steps) =>
backing(name, items, desired_item, select_default, validation_steps.Select(v => new PropertyValidation<T>(v)).ToList());
/// <summary>
/// Returns a SelectorProperty&lt;T&gt; that observes an items source, and a desired item. When either observable ticks, it determines whether or not to assign the selected_item property.
/// This overload makes it a little easier to access the overload where a message is supplied to the validation logic.
/// <para/>Notes: If the user has selected an item (ie the selected_item has been assigned through the public setter), the desired item will be ignored unless force_override is true.
/// <para/>If the user has not selected an item, but the current items do not contain the desired item, it will re-evaluate whether or not to select the item when new items arrive. /// </summary>
protected SelectorProperty<T> backing<T>(string name, IObservable<IEnumerable<T>> items, IObservable<InlineUserProperty<T>> desired_item, Func<T> select_default, params Func<T, (bool valid, string msg)>[] validation_steps) =>
backing(name, items, desired_item, select_default, validation_steps.Select(v => new PropertyValidation<T>(v)).ToList());
/// <summary>
/// Returns a SelectorProperty&lt;T&gt; that observes an items source, and a desired item. When either observable ticks, it determines whether or not to assign the selected_item property.
/// <para/>Notes: If the user has selected an item (ie the selected_item has been assigned through the public setter), the desired item will be ignored unless force_override is true.
/// <para/>If the user has not selected an item, but the current items do not contain the desired item, it will re-evaluate whether or not to select the item when new items arrive.
/// </summary>
protected SelectorProperty<T> backing<T>(string name, IObservable<IEnumerable<T>> items, IObservable<InlineUserProperty<T>> desired_item, Func<T> select_default, IReadOnlyList<PropertyValidation<T>> validation_steps) =>
backing(name, items, desired_item, select_default, null, validation_steps);
/// <summary>
/// Returns a SelectorProperty&lt;T&gt; that observes an items source, and a desired item. When either observable ticks, it determines whether or not to assign the selected_item property.
/// <para/>Notes: If the user has selected an item (ie the selected_item has been assigned through the public setter), the desired item will be ignored unless force_override is true.
/// <para/>If the user has not selected an item, but the current items do not contain the desired item, it will re-evaluate whether or not to select the item when new items arrive.
/// </summary>
/// <param name="name">The selected_item property name.</param>
/// <param name="items">The observable sequence of items.</param>
/// <param name="desired_item">The observable sequence of a desired item.</param>
/// <param name="select_default">The fallback function to select an item by default.</param>
/// <param name="items_match">The item-matching function used to preserve a selected item when new items arrive.</param>
protected SelectorProperty<T> backing<T>(string name, IObservable<IEnumerable<T>> items, IObservable<InlineUserProperty<T>> desired_item, Func<T> select_default, Func<T, T, bool> items_match) =>
backing(name, items, desired_item, select_default, items_match, new List<PropertyValidation<T>>(0));
/// <summary>
/// Returns a SelectorProperty&lt;T&gt; that observes an items source, and a desired item. When either observable ticks, it determines whether or not to assign the selected_item property.
/// <para/>Notes: If the user has selected an item (ie the selected_item has been assigned through the public setter), the desired item will be ignored unless force_override is true.
/// <para/>If the user has not selected an item, but the current items do not contain the desired item, it will re-evaluate whether or not to select the item when new items arrive.
/// </summary>
/// <param name="name">The selected_item property name.</param>
/// <param name="items">The observable sequence of items.</param>
/// <param name="desired_item">The observable sequence of a desired item.</param>
/// <param name="select_default">The fallback function to select an item by default.</param>
/// <param name="items_match">The item-matching function used to preserve a selected item when new items arrive.</param>
/// <param name="validation_steps">The validation steps to take when selected_item changes.</param>
protected SelectorProperty<T> backing<T>(string name, IObservable<IEnumerable<T>> items, IObservable<InlineUserProperty<T>> desired_item, Func<T> select_default, Func<T, T, bool> items_match, IReadOnlyList<PropertyValidation<T>> validation_steps) {
if (_observable_properties == null) _observable_properties = new List<IDisposable>();
var prop = new SelectorProperty<T>(this, name, select_default, items_match, validation_steps);
_observable_properties.Add(items.ObserveOnDispatcher().Subscribe(prop));
_observable_properties.Add(desired_item.ObserveOnDispatcher().Subscribe(prop));
return prop;
}
protected void set_dispose(IDisposable disposable) {
if (_dispose != null) throw new InvalidOperationException("Cannot set disposable twice");
@@ -366,6 +442,129 @@ namespace mbts.ui.shell
Disposable.dispose(_observable_properties);
Dispose(true);
}
/// <summary>
/// Designed to observe an items source, and a [settings-driven] desired item. When a new desired item is observed, it will evaluate it's current state and determine if it should be assigned to the selected_item.
/// <para/>Notes: If the user has selected an item (ie the selected_item has been assigned through the public setter), the desired item will be ignored unless force_override is true.
/// <para/>If the user has not selected an item, but the current items do not contain the desired item, it will re-evaluate whether or not to select the item when new items arrive.
/// </summary>
protected class SelectorProperty<T> : IObserver<InlineUserProperty<T>>, IObserver<IEnumerable<T>>, IObservable<(T oldval, T newval)> {
readonly DisposableViewModelBase _owner;
readonly string _prop_name;
readonly IReadOnlyList<PropertyValidation<T>> _validation_steps;
readonly ObservableCollection<T> _items = new ObservableCollection<T>();
readonly Func<T> _select_default;
readonly Func<T, T, bool> _items_match; // used to maintain selected_item through an items-change
T _selected_item;
InlineUserProperty<T> _desired_item;
bool _is_user_selected_item;
public SelectorProperty(DisposableViewModelBase owner, string prop_name, Func<T> select_default, Func<T, T, bool> items_match, IReadOnlyList<PropertyValidation<T>> validation_steps) {
_owner = owner;
_prop_name = prop_name;
_select_default = select_default;
_items_match = items_match;
_validation_steps = validation_steps;
items = new ReadOnlyObservableCollection<T>(_items);
}
public event PropertyChange<T> Changing;
public event PropertyChange<T> Changed;
public ReadOnlyObservableCollection<T> items { get; }
public T selected_item {
get => _selected_item;
set {
_is_user_selected_item = true;
_set_selected_item(value);
}
}
public IDisposable Subscribe(IObserver<(T oldval, T newval)> observer) {
Changed += pch;
return Disposable.Create(() => Changed -= pch);
void pch(T o, T n) => observer.OnNext((o, n));
}
public IObservable<T> observe_current(bool start_now = false) {
var source = this.Select(vals => vals.newval);
if (start_now)
source = source.StartWith(_selected_item);
return source;
}
void IObserver<InlineUserProperty<T>>.OnNext(InlineUserProperty<T> iup) {
_desired_item = iup;
_try_auto_select();
}
void IObserver<InlineUserProperty<T>>.OnError(Exception error) { }
void IObserver<InlineUserProperty<T>>.OnCompleted() { }
void IObserver<IEnumerable<T>>.OnNext(IEnumerable<T> value) {
if (_items_match != null && _is_user_selected_item) {
var curr_selected_item = selected_item;
_items.sync_with(value);
if (_try_match_item(curr_selected_item, out T match))
selected_item = match;
else {
_is_user_selected_item = false;
_try_auto_select();
}
} else {
_items.sync_with(value);
if (_is_user_selected_item)
_is_user_selected_item = _items.Contains(_selected_item);
_try_auto_select();
}
}
void IObserver<IEnumerable<T>>.OnError(Exception error) { }
void IObserver<IEnumerable<T>>.OnCompleted() { }
void _run_validation(T val) {
var invalid_steps = _validation_steps.Select(v => v.validate(val)).Where(r => !r.valid);
if (invalid_steps.Count() > 0) {
var error_msg = string.Join("\n", invalid_steps.Where(r => !string.IsNullOrEmpty(r.msg)).Select(r => r.msg));
_owner.set_error(_prop_name, error_msg, true);
} else _owner.clear_error(_prop_name);
}
void _try_auto_select() {
if (_is_user_selected_item) {
if (desired_item_valid() && _desired_item.force_override && _try_match_item(_desired_item.value, out T match)) {
_set_selected_item(match);
return;
}
} else if (desired_item_valid() && _try_match_item(_desired_item.value, out T match)) {
_set_selected_item(match);
return;
}
if (_try_match_item(_select_default(), out T default_match))
_set_selected_item(default_match);
else {
// the _set_selected_item has never been entered, so validation has never ran, force it here
// so that if some value is required, the valdiation logic will catch it
_run_validation(selected_item);
}
bool desired_item_valid() => (_desired_item?.has_value).GetValueOrDefault();
}
void _set_selected_item(T value) {
if (!Equals(value, _selected_item)) {
Changing?.Invoke(_selected_item, value);
var old = _selected_item;
_selected_item = value;
Changed?.Invoke(old, value);
_owner.RaisePropertyChanged(_prop_name);
_run_validation(value);
}
}
bool _try_match_item(T item, out T match) =>
_items_match != null ?
_items.TryGetFirst(i => _items_match(i, item), out match) :
_items.TryGetFirst(i => i.Equals(item), out match);
}
}
[Browsable(false)]
@@ -1,40 +0,0 @@
using System;
using System.Collections.Generic;
namespace mbts.utils {
public static class CompareUtils {
#region Equality
public static IEqualityComparer<T> NullCheckEqualityComparer<T>(Func<T, T, bool> never_null_equals, Func<T, int> get_hash_code) =>
EqualityComparer.Create(NullCheckEquality(never_null_equals), get_hash_code);
public static Func<T, T, bool> NullCheckEquality<T>(Func<T, T, bool> never_null_equals) =>
(x, y) => NullCheckEquals(x, y, never_null_equals);
public static bool NullCheckEquals<T>(T x, T y) =>
NullCheckEquals(x, y, (_x, _y) => _x.Equals(_y));
public static bool NullCheckEquals<T>(T x, T y, Func<T, T, bool> never_null_equals) =>
x == null ? y == null : y == null ? false : never_null_equals(x, y);
#endregion
#region Comparison
public static Comparison<T> NullCheckComparison<T>(Comparison<T> never_null_comparison) where T : class =>
new Comparison<T>((x, y) => NullCheckCompare(x, y, never_null_comparison));
public static IComparer<T> NullCheckComparer<T>(Comparison<T> never_null_comparison) where T : class =>
Comparer<T>.Create((x, y) => NullCheckCompare(x, y, never_null_comparison));
public static int NullCheckCompare<T>(T x, T y, Comparison<T> never_null_comparison) where T : class =>
x == null ? y == null ? 0 : -1 : y == null ? 1 : never_null_comparison(x, y);
public static IComparer<T> HierarchicalKeyComparer<T, TKey1, TKey2>(Func<T, TKey1> key1_selector, Func<T, TKey2> key2_selector)
where TKey1 : IComparable<TKey1>
where TKey2 : IComparable<TKey2> =>
Comparer<T>.Create((x, y) => {
int rv = key1_selector(x).CompareTo(key1_selector(y));
if (rv != 0) return rv;
return key2_selector(x).CompareTo(key2_selector(y));
});
#endregion
}
}
@@ -0,0 +1,71 @@
<c:PopupControl
x:Class="mbts.ui.controls.ActionMenu"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:c="clr-namespace:mbts.ui.controls"
Margin="1"
Background="Transparent"
BorderBrush="Transparent"
Padding="2"
PopupPlacement="Bottom"
ShowExpanderArrow="False"
Cursor="Hand"
>
<c:PopupControl.Resources>
<CollectionViewSource x:Key="ItemsSourceView" Source="{Binding ItemsSource, RelativeSource={RelativeSource AncestorType=c:ActionMenu}}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="group"/>
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
</c:PopupControl.Resources>
<c:PopupControl.Header>
<StackPanel>
<Rectangle Fill="Black" Height="2" Width="23"/>
<Rectangle Fill="Black" Height="2" Width="23" Margin="0,4,0,0"/>
<Rectangle Fill="Black" Height="2" Width="23" Margin="0,4,0,0"/>
</StackPanel>
</c:PopupControl.Header>
<Menu ItemsSource="{Binding Source={StaticResource ItemsSourceView}}">
<Menu.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</Menu.ItemsPanel>
<Menu.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="GroupItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GroupItem">
<StackPanel>
<ItemsPresenter/>
<Rectangle HorizontalAlignment="Stretch" Height="1" Margin="22,0,0,0" Fill="LightGray"/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</Menu.GroupStyle>
<Menu.ItemContainerStyle>
<Style TargetType="MenuItem" BasedOn="{StaticResource {x:Type MenuItem}}">
<!--NOTE: CommandParameter binding must be declared BEFORE Command,
otherwise, CanExecuted is called before the parameter value is realized...I know, it sucks...-->
<Setter Property="CommandParameter" Value="{Binding parameter}"/>
<Setter Property="Command" Value="{Binding command}"/>
<Setter Property="Header" Value="{Binding name}"/>
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding}" VerticalAlignment="Center"/>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="Icon" Value="{Binding icon, Converter={StaticResource IconConverter}}"/>
<Setter Property="MinWidth" Value="167"/>
</Style>
</Menu.ItemContainerStyle>
</Menu>
</c:PopupControl>
Loaded 100 of 424 files, more files were not shown because too many files have changed in this diff. Show more