TradingShellModule hides new/old pnl menu items if disabled in config

This commit is contained in:
John Colvin committed 2019-09-13 13:20:57 -05:00
1 parent 3bb473f62d
commit 7eb8f32ff7
1 file changed
+45 -13
@@ -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<SparkCommand> _actions;
[ImportingConstructor]
public TradingShellModule(
@@ -34,13 +37,16 @@ namespace bts.shell {
OrdersModel orders_model,
md.MBOService mbo,
ErrorReporter error_reporter) {
/// Unlike our <see cref="SparkCommand"/> members, <see cref="IShellWindowFactory"/> 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 <see cref="actions"/>).
_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<bts.config.PNLOptions>();
if (pnl_conf.show_new_pnl)
_pnl_conf = new PNLConfig(mbts.config.Configuration.get<bts.config.PNLOptions>());
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<SparkCommand> 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<SparkCommand> actions {
get {
if (_actions == null) {
_actions = new List<SparkCommand> {
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<IShellWindowFactory> 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<IDisposable>().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;
}
}
}
}