From 7eb8f32ff7c99585f0ae04f8fc8c7e2736d47646 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Fri, 13 Sep 2019 13:19:25 -0500 Subject: [PATCH] TradingShellModule hides new/old pnl menu items if disabled in config --- .../Modules/Trading/TradingShellModule.cs | 58 ++++++++++++++----- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/src/client/spark/Modules/Trading/TradingShellModule.cs b/src/client/spark/Modules/Trading/TradingShellModule.cs index 616a9c52d..c8ae2ad57 100644 --- a/src/client/spark/Modules/Trading/TradingShellModule.cs +++ b/src/client/spark/Modules/Trading/TradingShellModule.cs @@ -5,6 +5,7 @@ using bts.spark; using mbts.persist; using mbts.spark; using mbts.ui; +using System; using System.Collections.Generic; using System.ComponentModel.Composition; using System.IO; @@ -16,6 +17,7 @@ using static mbts.ui.shell.ProtoBufSerializationHelper; namespace bts.shell { [Export(typeof(IShellModule))] class TradingShellModule : IShellModule { + readonly PNLConfig _pnl_conf; LadderWindowFactory _lwf; OrderBookWindowFactory _obwf; FillsWindowFactory _fwf; @@ -23,6 +25,7 @@ namespace bts.shell { PNLWindowFactory _plwf; AlgoStudioWindowFactory _aswf; ManualFillsWindowFactory _mfwf; + List _actions; [ImportingConstructor] public TradingShellModule( @@ -34,13 +37,16 @@ namespace bts.shell { OrdersModel orders_model, md.MBOService mbo, ErrorReporter error_reporter) { + /// Unlike our members, members must be instantiated immediately, + /// as they are responsible for launching windows in response to a SparkTag being published to the bus. + /// The tags may be published by anything (i.e., not just the spark commands in ). _lwf = new LadderWindowFactory(this, bus, wm, settings_hub, orders_model, mbo); _obwf = new OrderBookWindowFactory(this, bus, notification_service, notification_service_data_cache, orders_model, settings_hub); _fwf = new FillsWindowFactory(this, bus, settings_hub, orders_model); - var pnl_conf = mbts.config.Configuration.get(); - if (pnl_conf.show_new_pnl) + _pnl_conf = new PNLConfig(mbts.config.Configuration.get()); + if (_pnl_conf.show_new_pnl) _plwf = new PNLWindowFactory(this, bus, settings_hub, orders_model); - if (pnl_conf.show_old_pnl) + if (_pnl_conf.show_old_pnl) _old_plwf = new PAndLWindowFactory(this, bus, settings_hub, orders_model); _aswf = new AlgoStudioWindowFactory(this, bus, orders_model, error_reporter); _mfwf = new ManualFillsWindowFactory(this, bus, orders_model); @@ -52,16 +58,27 @@ namespace bts.shell { public int priority => 20; - public IEnumerable actions => new [] { - SparkCommands.ShowOrders.complete(() => bts.shell.orderbook.OrderBookStartupData.Default), - SparkCommands.ShowFills(null).complete(() => new FillsSettings()), - SparkCommands.ShowPNL.complete(() => null), - SparkCommands.ShowPAndL.complete(() => new PAndLWindowFactory.PAndLStartupData()), - SparkCommands.PickLadder, - SparkCommands.PickOrderTicket, - SparkCommands.ShowAlgoStudio.complete(() => new AlgoStudioWindowFactory.StartupData()), - SparkCommands.ShowManualFills().complete(() => ManualFillsSettings.Default) - }; + public IEnumerable actions { + get { + if (_actions == null) { + _actions = new List { + SparkCommands.ShowOrders.complete(() => bts.shell.orderbook.OrderBookStartupData.Default), + SparkCommands.ShowFills(null).complete(() => new FillsSettings()), + }; + if (_pnl_conf.show_new_pnl) + _actions.Add(SparkCommands.ShowPNL.complete(() => null)); + if (_pnl_conf.show_old_pnl) + _actions.Add(SparkCommands.ShowPAndL.complete(() => new PAndLWindowFactory.PAndLStartupData())); + _actions.AddRange(new[] { + SparkCommands.PickLadder, + SparkCommands.PickOrderTicket, + SparkCommands.ShowAlgoStudio.complete(() => new AlgoStudioWindowFactory.StartupData()), + SparkCommands.ShowManualFills().complete(() => ManualFillsSettings.Default) + }); + } + return _actions; + } + } IEnumerable window_factories() { yield return _lwf; @@ -79,8 +96,23 @@ namespace bts.shell { dispatch_to_factory(load_stream, window_factories().ToArray()); public void Dispose() { + if (_actions != null) { + _actions.OfType().DisposeAll(); + _actions = null; + } foreach (var i in window_factories()) if (i != null) i.Dispose(); } + + readonly struct PNLConfig { + public readonly bool + show_new_pnl, + show_old_pnl; + + public PNLConfig(bts.config.PNLOptions options) { + show_new_pnl = options.show_new_pnl; + show_old_pnl = options.show_old_pnl; + } + } } } \ No newline at end of file