diff --git a/src/client/spark/Daemons/SecurityPickerDaemon.cs b/src/client/spark/Daemons/SecurityPickerDaemon.cs index 8d712c4aa..5b066f206 100644 --- a/src/client/spark/Daemons/SecurityPickerDaemon.cs +++ b/src/client/spark/Daemons/SecurityPickerDaemon.cs @@ -1,17 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using bts.api; +using bts.api; +using bts.spark; +using mbts; using mbts.spark; using mbts.ui; +using System; using System.ComponentModel.Composition; -using mbts; -using System.Windows; -using System.Windows.Input; -using bts.spark; using System.Reactive.Linq; +using System.Windows; namespace bts { [Export, Export(typeof(IShellDaemon))] @@ -29,102 +24,57 @@ namespace bts { bus.subscribe(SparkTags.ShowAndEditPickMultiple).OnDispatcher().Subscribe(show_and_edit_pick_multiple) ); } - - void show_pick_one(PartialCommand message) { - var vm = new ContractPickerModel(_bus, false, null); - var view = new ContractPickerView(vm); - - Window picker = new Window { - Content = view, - Title = $"Select a Security for {message.title}", - Icon = message.icon, - Height = view.Height, - Width = view.Width - }; - picker.Style = picker.TryFindResource("BTSWindow") as Style; - view.Height = Double.NaN; - view.Width = Double.NaN; - - vm.ok_action = () => { - picker.Close(); - message.complete(vm.result).execute(_bus); - }; - picker.move_to_mouse(); - picker.Show(); - } - - void show_filtered_pick_one((PartialCommand message, SecurityCriteria global_filter) message_and_filter) { - var vm = new ContractPickerModel(_bus, false, null, message_and_filter.global_filter); - var view = new ContractPickerView(vm); - - Window picker = new Window { - Content = view, - Title = $"Select a Security for {message_and_filter.message.title}", - Icon = message_and_filter.message.icon, - Height = view.Height, - Width = view.Width - }; - picker.Style = picker.TryFindResource("BTSWindow") as Style; - view.Height = Double.NaN; - view.Width = Double.NaN; - - vm.ok_action = () => { - picker.Close(); - message_and_filter.message.complete(vm.result).execute(_bus); - }; - picker.move_to_mouse(); - picker.Show(); - } - - void show_pick_multiple(PartialCommand message) { - var vm = new ContractPickerModel(_bus, true, null); - var view = new ContractPickerView(vm); - - Window picker = new Window - { - Content = view, - Title = $"Select Securities for {message.title}", - Icon = message.icon, - Height = view.Height, - Width = view.Width, - }; - picker.Style = picker.TryFindResource("BTSWindow") as Style; - view.Height = Double.NaN; - view.Width = Double.NaN; - - vm.ok_action = () => { - picker.Close(); - message.complete(vm.result_criteria).execute(_bus); - }; - picker.move_to_mouse(); - picker.Show(); - } - - void show_and_edit_pick_multiple((PartialCommand message, SecurityCriteria existing_criteria) message_and_data) { - var vm = new ContractPickerModel(_bus, true, message_and_data.existing_criteria); - var view = new ContractPickerView(vm); - - Window picker = new Window { - Content = view, - Title = $" {message_and_data.message.title} security selection", - Icon = message_and_data.message.icon, - Height = view.Height, - Width = view.Width, - }; - picker.Style = picker.TryFindResource("BTSWindow") as Style; - view.Height = Double.NaN; - view.Width = Double.NaN; - - vm.ok_action = () => { - picker.Close(); - message_and_data.message.complete(vm.result_criteria).execute(_bus); - }; - picker.move_to_mouse(); - picker.Show(); - } - - public void Dispose() { + + public void Dispose() => Disposable.dispose(ref _dispose); + + void show_pick_one(PartialCommand message) => + _show_picker(message, _fmt_pick_one_title, new ContractPickerModel(_bus, false, null), vm => vm.result); + + void show_filtered_pick_one((PartialCommand message, SecurityCriteria global_filter) message_and_filter) => + _show_picker(message_and_filter.message, _fmt_pick_one_title, new ContractPickerModel(_bus, false, null, message_and_filter.global_filter), vm => vm.result); + + void show_pick_multiple(PartialCommand message) => + _show_picker(message, _fmt_pick_multiple_title, new ContractPickerModel(_bus, true, null), vm => vm.result_criteria); + + void show_and_edit_pick_multiple((PartialCommand message, SecurityCriteria existing_criteria) message_and_data) => + _show_picker(message_and_data.message, _fmt_pick_multiple_title, new ContractPickerModel(_bus, true, message_and_data.existing_criteria), vm => vm.result_criteria); + + static string _fmt_pick_one_title(string message_title) => $"Select a Security for {message_title}"; + static string _fmt_pick_multiple_title(string message_title) => $"Select Securities for {message_title}"; + + void _show_picker(PartialCommand message, Func fmt_title, ContractPickerModel vm, Func select_result) { + var icon = message.icon; + if (icon == null) { + // not neccessary grind to hault just bc the icon is null, but it is most likely a dev-mistake that should be addressed. + handle_bad_icon("a null icon"); + } else if (!icon.IsFrozen) { + handle_bad_icon("an icon that wasn't frozen (not threadsafe)"); + } + // + void handle_bad_icon(string icon_error_desc) { + Log.Api.warn($"{nameof(SecurityPickerDaemon)} received a message '{message.title}' with {icon_error_desc}, will use {nameof(Icons.AdminFrozen)}."); + icon = Icons.AdminFrozen; + } + // + var cpv = new ContractPickerView(vm); + var window = new Window { + Content = cpv, + Title = fmt_title(message.title), + Icon = message.icon, + Height = cpv.Height, + Width = cpv.Width, + }; + window.Style = window.TryFindResource("BTSWindow") as Style; + cpv.Width = double.NaN; + cpv.Height = double.NaN; + + vm.ok_action = () => { + window.Close(); + message.complete(select_result(vm)).execute(_bus); + }; + window.move_to_mouse(); + window.Show(); } } -} +} \ No newline at end of file diff --git a/src/client/spark/Images/Icons.cs b/src/client/spark/Images/Icons.cs index 419d49708..cc9ebe874 100644 --- a/src/client/spark/Images/Icons.cs +++ b/src/client/spark/Images/Icons.cs @@ -1,5 +1,7 @@ -using System; +using bts; +using System; using System.Collections.Generic; +using System.Linq; using System.Windows; using System.Windows.Media; using System.Windows.Media.Imaging; @@ -8,10 +10,18 @@ namespace mbts.ui { public class Icons { public const string GearGeometryKey = nameof(GearGeometryKey), - PaymentGeometryKey = nameof(PaymentGeometryKey), OrdersGeometryKey = nameof(OrdersGeometryKey), + PaymentGeometryKey = nameof(PaymentGeometryKey), + PlayGeometryKey = nameof(PlayGeometryKey), ToolsGeometryKey = nameof(ToolsGeometryKey); + static Icons() { + // TODO: probably do this for all icons, only reason for holding back is the uncertainity of any unexpected impacts + AdminFrozen = Admin.frozen(); + } + + public static Geometry PlayGeometry => Geometry.Parse(_get_geometric_path(PlayGeometryKey).FirstOrDefault() ?? string.Empty); + static readonly string base_uri = "pack://application:,,,/Images/Icons/"; private static ResourceDictionary _resources = (ResourceDictionary)Application.LoadComponent(new Uri("/Images/Vector/Icons.xaml", UriKind.RelativeOrAbsolute)); @@ -27,6 +37,7 @@ namespace mbts.ui { #pragma warning disable CS0618 // Type or member is obsolete public static ImageSource Logo { get { return load_image("logo.ico"); } } public static ImageSource Admin { get { return (DrawingImage)_resources["Admin"]; } } + public static ImageSource AdminFrozen { get; } public static ImageSource Analytics { get { return (DrawingImage)_resources["Analytics"]; } } public static ImageSource Sheets { get { return (DrawingImage)_resources["Sheets"]; } } public static ImageSource Trades { get { return (DrawingImage)_resources["Trades"]; } } @@ -113,21 +124,15 @@ namespace mbts.ui { public static ImageSource Tools => create_icon(ToolsGeometryKey); public static ImageSource ViewSettings => (DrawingImage)_resources["ViewSettings"]; public static ImageSource Wrench { get { return (DrawingImage)_resources["Wrench"]; } } - public static ImageSource UpArrow { get { return (DrawingImage)_resources["UpArrow"]; } } - + public static ImageSource RightArrow { get { return ((DrawingImage)_resources["RightArrow"]); } } + public static ImageSource DownArrow { get { return ((DrawingImage)_resources["DownArrow"]); } } public static ImageSource Support => (DrawingImage)_resources["SupportIcon"]; - public static ImageSource create_icon(string geometric_path_key) => create_icon(geometric_path_key, Brushes.Black); - public static ImageSource create_icon(string geometric_path_key, Brush brush, Pen pen = null) { - object obj = _resources[geometric_path_key]; - if (obj is string path) { - if (string.IsNullOrEmpty(path)) - throw new ArgumentException($"Resource lookup of '{geometric_path_key}' did not return a valid string.", nameof(geometric_path_key)); - return _create_icon(new[] { path }, brush, pen); - } else if (obj is string[] paths) { - return _create_icon(paths, brush, pen); - } else return null; - } + public static ImageSource create_icon(string geometric_path_key) => + create_icon(geometric_path_key, Brushes.Black); + + public static ImageSource create_icon(string geometric_path_key, Brush brush, Pen pen = null) => + _create_icon(_get_geometric_path(geometric_path_key), brush, pen); static ImageSource _create_icon(IEnumerable paths, Brush brush, Pen pen = null) { var drawing_group = new DrawingGroup(); @@ -136,5 +141,18 @@ namespace mbts.ui { } return new DrawingImage(drawing_group); } + + static IEnumerable _get_geometric_path(string geometric_path_key) { + object obj = _resources[geometric_path_key]; + if (obj is string path) { + if (string.IsNullOrEmpty(path)) { + Log.Api.error($"Resource lookup of '{geometric_path_key}' did not return a valid string.", nameof(geometric_path_key)); + path = string.Empty; + } + return new[] { path }; + } else if (obj is string[] paths) { + return paths.Where(p => !string.IsNullOrEmpty(p)).ToArray(); + } else return null; + } } } \ No newline at end of file diff --git a/src/client/spark/Images/Vector/Icons.xaml b/src/client/spark/Images/Vector/Icons.xaml index ebc53742c..3fd3e8aa9 100644 --- a/src/client/spark/Images/Vector/Icons.xaml +++ b/src/client/spark/Images/Vector/Icons.xaml @@ -17,9 +17,17 @@ M28.000001,6.0000026L28.000001,15 6.0010006,15 6.0010006,17.000003 30.001,17.000003 30.001,6.0000026z M14.231,2.9540056L14.979999,2.9540056 14.979999,3.987005C15.704998,4.009005,16.200997,4.178005,16.550998,4.3600049L16.248998,5.0620046C15.994998,4.9340047 15.499998,4.7010047 14.725999,4.7010047 13.796,4.7010047 13.445001,5.1900046 13.445001,5.6160046 13.445001,6.1710043 13.893,6.4470041 14.943999,6.8310037 16.187998,7.2780037 16.816998,7.8320036 16.816998,8.7800031 16.816998,9.6210027 16.151998,10.409003 14.907999,10.591002L14.907999,11.698002 14.146,11.698002 14.146,10.622003C13.445001,10.611002,12.720001,10.420002,12.297002,10.154003L12.587001,9.4400029C13.022001,9.696003 13.651,9.8980026 14.328,9.8980026 15.185999,9.8980026 15.765998,9.4620028 15.765998,8.8540034 15.765998,8.2680035 15.293999,7.9060035 14.4,7.5870035 13.167001,7.1610038 12.406001,6.6710041 12.406001,5.7440041 12.406001,4.8600047 13.119,4.189005 14.231,4.0290052z M2,2.0000002L2,13 26.000001,13 26.000001,2.0000002z M0,0L28.000001,0 28.000001,4.0000031 32.001,4.0000031 32.001,19.000003 4.0010006,19.000003 4.0010006,15 0,15z + + M0,0L25.194,16 0,32z + + M4.9629898,25.440168C4.564003,25.440168 4.0650101,25.640182 3.7659989,25.939165 3.0680008,26.638176 3.0680008,27.635191 3.7659989,28.3342 4.4639969,29.032204 5.4620133,29.032204 6.1600113,28.3342 6.8589859,27.635191 6.8589859,26.638176 6.1600113,25.939165 5.760994,25.640182 5.3620072,25.440168 4.9629898,25.440168z M18.432014,18.457121L22.422005,22.447138 24.816994,22.946165 29.107002,29.431192 27.509987,31.027212 21.025002,26.737175 20.526985,24.343178 16.535988,20.352123z M8.1560135,18.357115L13.643013,23.84415C11.048988,26.638176 8.9539872,28.932196 7.9560013,29.930189 6.359993,31.526207 3.6659928,31.626215 2.070015,29.930189 0.47400668,28.3342 0.47400668,25.640182 2.070015,24.044165z M2.967995,6.7840408C2.768013,6.7840408 2.5690079,6.8840479 2.4690018,6.9840545 2.1699906,7.2830371 2.1699906,7.7820638 2.4690018,8.0810469L11.746986,17.359123C12.047005,17.659113 12.544991,17.659113 12.845009,17.359123 13.14399,17.06011 13.14399,16.561113 12.845009,16.2621L3.5659867,6.9840545C3.3670121,6.8840479,3.1669998,6.7840408,2.967995,6.7840408z M5.2620011,4.4890431C5.0629959,4.4890431 4.8630143,4.5890192 4.7640152,4.6890262 4.3649979,4.9880394 4.3649979,5.4870356 4.7640152,5.8860554L14.042,15.164101C14.341011,15.46409 14.840004,15.46409 15.139015,15.164101 15.439003,14.865087 15.439003,14.366092 15.139015,14.067109L5.8610001,4.6890262C5.661995,4.5890192,5.4620133,4.4890431,5.2620011,4.4890431z M4.3649979,2.3940283C5.4620133,2.3940281,6.5589981,2.7930175,7.3580094,3.5920337L19.328987,15.46409 13.342995,21.450153 1.2720107,9.6770657C-0.42400357,7.9810704 -0.42400357,5.2880291 1.2720107,3.6910337 2.1699906,2.7930175 3.267006,2.3940281 4.3649979,2.3940283z M24.217995,0C25.31501,-8.5992724E-08,26.312996,0.20001344,27.211006,0.59900296L23.021004,4.7890328C22.223,5.5870422,22.223,6.7840408,23.021004,7.4820436L24.617012,9.079069C25.414986,9.8770789,26.612007,9.8770789,27.311012,9.079069L31.501015,4.9880394C31.799995,5.8860554 32.000008,6.7840408 32.000008,7.7820638 32.000008,12.07207 28.508003,15.564097 24.217995,15.564097 19.927986,15.564097 16.436012,12.07207 16.436012,7.7820638 16.436012,3.4920272 19.927986,-8.5992724E-08 24.217995,0z + + + F1 M 78.1398,324.18L 52.5865,298.626C 51.6892,297.728 50.3385,297.459 49.1678,297.946C 47.9971,298.43 47.2305,299.574 47.2305,300.843L 60.6385,326.398L 47.2305,351.952C 47.2305,353.223 47.9971,354.364 49.1678,354.848C 49.5558,355.011 49.9638,355.09 50.3678,355.09C 51.1838,355.09 51.9852,354.77 52.5865,354.171L 78.1398,328.616C 78.7238,328.032 79.0598,327.224 79.0598,326.398C 79.0598,325.572 78.7238,324.764 78.1398,324.18 Z + @@ -492,17 +500,6 @@ M0,0L63.999001,0 63.999001,48.792999 0,48.792999z"> - - - - - - - - - - @@ -763,20 +760,39 @@ M0,0L63.999001,0 63.999001,48.792999 0,48.792999z"> - + - + + + + + + + + + + + + + + + + + + + + + + - - - - - + + - Play Sound - - + + + + + + Play + + + + - + diff --git a/src/client/spark/view/Controls/Order/OrderDetailsPopupControl.xaml b/src/client/spark/view/Controls/Order/OrderDetailsPopupControl.xaml index 5853f425a..d9a5c66b9 100644 --- a/src/client/spark/view/Controls/Order/OrderDetailsPopupControl.xaml +++ b/src/client/spark/view/Controls/Order/OrderDetailsPopupControl.xaml @@ -409,18 +409,21 @@ - Price Type - + > + Price Type + + @@ -440,21 +443,24 @@ - - Child - + - + > + + Child + + diff --git a/src/client/spark/view/Extensions/WPFExtensions.cs b/src/client/spark/view/Extensions/WPFExtensions.cs index 1c371bdec..5aa34a548 100644 --- a/src/client/spark/view/Extensions/WPFExtensions.cs +++ b/src/client/spark/view/Extensions/WPFExtensions.cs @@ -103,6 +103,11 @@ namespace mbts.ui { return pen; } + public static ImageSource frozen(this ImageSource image_source) { + image_source.Freeze(); + return image_source; + } + // Perform a breadth first traversal of all children returning any that match the predicate. // Matching children are *not* further traversed public static IEnumerable visual_children_where(this FrameworkElement v, Func match) { diff --git a/src/client/spark/view/Resources/Buttons.xaml b/src/client/spark/view/Resources/Buttons.xaml index bb439a758..bb74779f5 100644 --- a/src/client/spark/view/Resources/Buttons.xaml +++ b/src/client/spark/view/Resources/Buttons.xaml @@ -281,6 +281,62 @@ + + #40DD40 + #B8B8B8 + + + + +