add window_type property to IShellWindow

This commit is contained in:
John Colvin committed 2018-04-13 15:36:58 -04:00
1 parent d7186b7052
commit 9aeab69581
17 files changed
+59 -65

No files matched your search

@@ -1,7 +1,6 @@
using bts.api;
using bts.shell;
using bts.spark;
using mbts.config;
using mbts.ui;
using mbts.ui.spark;
using mbts.utils;
@@ -14,6 +13,7 @@ using System.Windows.Media;
namespace mbts.spark {
class MarketViewWindow : SparkWindow<MarketViewWindowFactory.StartupData> {
const string _window_type = "MarketView";
readonly MarketViewWindowFactory _factory;
readonly OrdersModel _orders_model;
@@ -61,6 +61,7 @@ namespace mbts.spark {
public void update_criteria(SecurityCriteria c) =>
_initialize(new MarketViewWindowFactory.StartupData(c, _vm.value.rows_view.GetSortingCriteria(), _vm.value.get_filter_states()));
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.value.rows_view.GetSortingCriteria(), _vm.value.get_filter_states());
@@ -15,6 +15,7 @@ using static bts.shell.TimeAndSalesWindowFactory;
namespace mbts.spark {
class TimeAndSalesWindow : SparkWindow<StartupData>, ISlowWindow {
const string _window_type = "TimeAndSales";
readonly MDConsumer _consumer;
readonly TimeAndSalesWindowFactory _factory;
SingleValuePump<TimeAndSalesVM> _vm;
@@ -31,6 +32,7 @@ namespace mbts.spark {
_state = state;
}
public override string window_type => _window_type;
public override IEnumerable<SparkCommand> Commands => _commands;
public override UIElement Content => _view;
public override double MinWidth => 444 + SPARK_MENU_COLLAPSED_WIDTH + LAUNCHER_BUTTON_BORDER_WIDTH;
@@ -13,6 +13,7 @@ using static bts.shell.SyntheticManagementWindowFactory;
namespace mbts.spark {
class SyntheticManagementWindow : SparkWindow<StartupData> {
const string _window_type = "SyntheticManagement";
SingleValuePump<SyntheticManagementDialogVM> _vm = new SingleValuePump<SyntheticManagementDialogVM>();
StartupData _state;
OrdersModel _orders_model;
@@ -60,6 +61,7 @@ namespace mbts.spark {
else _view.DataContext = _vm.value;
}
public override string window_type => _window_type;
public override UIElement Content => _view;
public override IEnumerable<SparkCommand> Commands { get; }
public override StartupData SaveState => _state = new StartupData(_vm.value.rows_view.GetSortingCriteria(), _vm.value.get_filter_states());
@@ -15,6 +15,7 @@ using System.Windows.Media;
namespace bts.shell
{
class ActivityLogWindow : SparkWindow<ActivityWindowState>, ISharedWindow {
const string _window_type = "ActivityLog";
readonly IObservable<LogViewerMessage> _message_src;
readonly LogViewerMessageCollection _messages = new LogViewerMessageCollection();
IDisposable _dispose;
@@ -25,6 +26,7 @@ namespace bts.shell
_message_src = messages;
}
public override string window_type => _window_type;
public override ActivityWindowState SaveState => new ActivityWindowState();
public override UIElement Content => _content;
@@ -6,9 +6,9 @@ using mbts.ui.spark;
using mbts.utils;
using System.Windows;
namespace mbts.spark
{
namespace mbts.spark {
class FillsWindow : SparkWindow<FillsWindowFactory.StartupData> {
const string _window_type = "Fills";
readonly OrdersModel _orders_model;
SingleValuePump<FillsVM> _vm = new SingleValuePump<FillsVM>();
FillsWindowFactory.StartupData _state;
@@ -31,6 +31,7 @@ namespace mbts.spark
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 double MinWidth => 1050 + SPARK_MENU_COLLAPSED_WIDTH + LAUNCHER_BUTTON_BORDER_WIDTH;
@@ -14,6 +14,7 @@ using System.Windows;
namespace bts.shell {
class LadderWindowFactory : ShellWindowFactory<LadderSaveState> {
const string _window_type = "Ladder";
readonly IBus _bus;
readonly IWindowManager _wm;
readonly OrdersModel _orders_model;
@@ -26,8 +27,7 @@ namespace bts.shell {
_wm = wm;
_orders_model = orders_model;
var window_props = Configuration.get<bts.config.IShellWindowProps>();
_max_ladders_open = window_props != null && window_props.ladder != null ?
(int)window_props.ladder.max_total_open : 50;
_max_ladders_open = (int)(window_props?.ladder?.max_total_open ?? 50);
_dispose = Disposable.Create(
bus.subscribe(SparkTags.SecuritiesTag).Subscribe(s => _securities = s),
bus.subscribe(SparkTags.ShowLadderTag).ObserveOnDispatcher().Subscribe(s => show_windows(new[] { s })),
@@ -46,7 +46,6 @@ namespace bts.shell {
static LadderSaveState _get_state(LadderVM vm) =>
new LadderSaveState { security_key = vm.security.Id, settings = vm.current_settings };
const string _thread_prefix = "Ladder";
int _ladder_count = 0;
IShellWindow create_ladder_window(SecurityMD md, IObservable<mbts.spark.LadderSettings> settings) {
var id = Interlocked.Increment(ref _ladder_count) % Environment.ProcessorCount;
@@ -55,18 +54,16 @@ namespace bts.shell {
var vm = new LadderVM(_bus, model, settings);
return new LadderView(vm);
});
string thread = Configuration.get<bts.config.toggles.LaddersOnThreads>().enabled ? $"{_thread_prefix}{id:00}" : "";
string thread = Configuration.get<bts.config.toggles.LaddersOnThreads>().enabled ? $"Ladder{id:00}" : "";
return ShellWindow.create(
module, md.security.ToString(), view,
module, md.security.ToString(), _window_type, view,
(v,s) => save(_get_state(((LadderView)v).vm), s),
icon: Icons.Ladder,
thread_id: thread);
}
void show_windows(IReadOnlyCollection<SecurityMD> securities) {
// This is not the most elegant way to count ladders, but I expect the window limits responsibility will eventually be moved to the IWindowManager.
// In the meantime, this will do the job (I considered making an actual LadderWindow Class, so OfType<LadderWindow>().Count() would work, but this is pretty much the same thing).
int n_allowed = _max_ladders_open - _wm.Windows.OfType<ISharedWindow>().Where(w => w.thread_id.StartsWith(_thread_prefix)).Count();
int n_allowed = _max_ladders_open - _wm.Windows.Where(w => w.window_type == _window_type).Count();
int n_opened = 0;
foreach (var s in securities) {
if (++n_opened > n_allowed) {
@@ -14,6 +14,7 @@ namespace mbts.ui.tests
public event Action TitleChanged = () => { };
public System.Windows.Media.ImageSource Icon { get { return null; } }
public event Action IconChanged = () => { };
public string window_type { get; }
public IShellModule Owner { get; set; }
public void GetState(System.IO.Stream save_here) { }
#endregion
@@ -1,20 +1,18 @@
using System;
using mbts.ui.shell;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Threading;
using mbts.ui.shell;
using mbts;
namespace mbts.ui
{
public interface IShellWindow : IDisposable
{
namespace mbts.ui {
public interface IShellWindow : IDisposable {
// Window title
string Title { get; set; }
// Window type (e.g Ladder, MarketView, etc)
string window_type { get; }
// Call this callback if you set the title property so the shell knows to update the display.
event Action TitleChanged;
@@ -99,4 +97,4 @@ namespace mbts.ui
}
}
}
}
}
@@ -1,19 +1,16 @@
using System;
using bts.api;
using mbts.config;
using mbts.spark;
using ProtoBuf;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using ProtoBuf;
using mbts.config;
using bts.api;
using mbts.spark;
namespace mbts.ui.controls
{
public class BrowserWindow : IShellWindow
{
namespace mbts.ui.controls {
public class BrowserWindow : IShellWindow {
const string _window_type = "Browser";
private WebBrowser _browser;
public BrowserWindow(Uri uri, IShellModule owner) {
@@ -71,6 +68,8 @@ namespace mbts.ui.controls
public System.Windows.Media.ImageSource Icon { get { return Icons.FavoriteWindow; } }
public event Action IconChanged = () => { };
public string window_type => _window_type;
public IShellModule Owner {get; set; }
public ShellWindowUI GetContent() { return new ShellWindowUI(_browser); }
@@ -28,6 +28,7 @@ namespace mbts.ui.controls
public event Action TitleChanged = () => { };
public ImageSource Icon { get; set; }
public event Action IconChanged = () => { };
public string window_type { get; set; }
public IShellModule Owner { get; set; }
public void Dispose() { }
public void GetState(System.IO.Stream save_here) { }
@@ -31,6 +31,7 @@ namespace mbts.ui.controls
public event Action TitleChanged = () => { };
public ImageSource Icon { get; set; }
public event Action IconChanged = () => { };
public string window_type { get; set; }
public IShellModule Owner { get; set; }
public void Dispose() { }
public void GetState(System.IO.Stream save_here) { }
@@ -1,16 +1,9 @@
using mbts;
using System;
using System.Collections;
using System.Collections.Generic;
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
namespace mbts.ui
{
namespace mbts.ui {
public static class ShellWindow {
private class AnonShellWindow : IShellWindow {
private ImageSource _icon;
@@ -24,6 +17,7 @@ namespace mbts.ui
get { return _title; }
set { _title = value; TitleChanged?.Invoke(); }
}
public string window_type { get; set; }
public event Action IconChanged;
public event Action TitleChanged;
@@ -51,19 +45,20 @@ namespace mbts.ui
public void thread_init() { }
}
public static IShellWindow create(IShellModule owner, string title, Lazy<UIElement> content, Action<UIElement, Stream> get_state = null, ImageSource icon = null, string thread_id=null) {
public static IShellWindow create(IShellModule owner, string title, string window_type, Lazy<UIElement> content, Action<UIElement, Stream> get_state = null, ImageSource icon = null, string thread_id=null) {
if (string.IsNullOrEmpty(thread_id)) {
return create<AnonShellWindow>(owner, title, content, get_state, icon);
return create<AnonShellWindow>(owner, title, window_type, content, get_state, icon);
}
else {
var res = create<LazyAnonShellWindow>(owner, title, content, get_state, icon);
var res = create<LazyAnonShellWindow>(owner, title, window_type, content, get_state, icon);
res.thread_id = thread_id;
return res;
}
}
static T create<T>(IShellModule owner, string title, Lazy<UIElement> content, Action<UIElement,Stream> get_state=null, ImageSource icon=null) where T : AnonShellWindow, new() {
static T create<T>(IShellModule owner, string title, string window_type, Lazy<UIElement> content, Action<UIElement,Stream> get_state=null, ImageSource icon=null) where T : AnonShellWindow, new() {
var result = new T() {
Title = title,
window_type = window_type,
Icon = icon ?? (owner != null ? owner.icon : Icons.Window),
Owner = owner,
get_state = get_state,
@@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace mbts.ui.shell
{
public class ErrorShellWindow : IShellWindow
{
namespace mbts.ui.shell {
public class ErrorShellWindow : IShellWindow {
const string _window_type = "Error";
public string Title { get; set; }
public event Action TitleChanged = () => { };
@@ -15,6 +12,8 @@ namespace mbts.ui.shell
public event Action IconChanged = () => { };
public string window_type => _window_type;
public IShellModule Owner {
get { return null; }
set { }
@@ -34,4 +33,4 @@ namespace mbts.ui.shell
}
}
}
}
@@ -1,19 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace mbts.ui.shell
{
namespace mbts.ui.shell {
public class ShellLaunchMenuItem
{
public string name { get; set; }
@@ -53,6 +43,8 @@ namespace mbts.ui.shell
public event Action IconChanged = () => { };
public string window_type { get; set; }
public mbts.ui.IShellModule Owner
{
get { return null; }
@@ -13,7 +13,7 @@ using System.Windows.Media;
namespace mbts.spark {
internal class PAndLWindow : SparkWindow<PAndLWindowFactory.PAndLStartupData>, ISharedWindow {
const string PNL_THREAD_ID = "PnL";
const string _window_type = "PAndL", PNL_THREAD_ID = "PnL";
PAndLWindowFactory.PAndLStartupData _state;
PAndLModel _model;
PAndLView _view;
@@ -25,6 +25,7 @@ namespace mbts.spark {
_state = state;
}
public override string window_type => _window_type;
public override PAndLWindowFactory.PAndLStartupData SaveState => _state =
new PAndLWindowFactory.PAndLStartupData();
public override UIElement Content => _view;
@@ -12,7 +12,7 @@ using System.Windows.Media;
namespace mbts.spark {
internal class OrderBookWindow : SparkWindow<OrderBookWindowFactory.OrderBookStartupData>, ISharedWindow {
const string ORDERBOOK_THREAD_ID = "OrderBook";
const string _window_type = "OrderBook", ORDERBOOK_THREAD_ID = "OrderBook";
OrderBookWindowFactory.OrderBookStartupData _state;
OrdersModel _model;
OrderBookVM _vm;
@@ -41,6 +41,7 @@ namespace mbts.spark {
_vm.get_filter_states()
);
public override string window_type => _window_type;
public override UIElement Content => _view;
public override IEnumerable<SparkCommand> Commands => _commands;
public override double MinWidth => 1577;
@@ -54,6 +54,7 @@ namespace bts.spark {
}
}
public IShellModule Owner => _save.module;
public abstract string window_type { get; }
public abstract T SaveState { get; }
public abstract UIElement Content { get; }
public virtual IEnumerable<SparkCommand> Commands => Enumerable.Empty<SparkCommand>();