settings dialogs title matches actual shell window titles

This commit is contained in:
John Colvin committed 2019-06-23 12:18:10 -05:00
1 parent 0b14b048e4
commit 049cc69a4f
29 files changed
+220 -168

No files matched your search

@@ -7,6 +7,7 @@ using bts.utils;
using mbts.persist;
using mbts.ui;
using mbts.ui.settings;
using mbts.ui.shell;
using mbts.ui.spark;
using mbts.ui.utility;
using mbts.utils;
@@ -135,6 +136,7 @@ namespace mbts.spark {
var show_synth_create_cmd_wrapper = new SparkCommandCommand(show_synth_create_actual_cmd.title, show_synth_create_actual_cmd.icon, show_synth_create_cmd, SparkCommands.KeyGestures.ShowSyntheticCreate);
var update_securities_cmd = SparkCommands.change_securities_callback(_window_type_display_name);
// commands
_commands = new List<SparkCommand> {
SparkCommands.ShowLadders(SparkCommands.KeyGestures.ShowLadder).complete(_vm.selected_security_mds_observable(), smds => smds.Count > 0),
SparkCommands.ShowOrderTicketFromSecurity(SparkCommands.KeyGestures.ShowOrderTicket).complete(_vm.current_security_md, md => md.HasValue, ConvertUtils.ValueOrDefault),
@@ -151,12 +153,11 @@ namespace mbts.spark {
s => _vm.grid_settings_manager.create_vm(
// we need to get the most up to date GridSettings when launching b/c users may
// have changed some settings on the grid directly, like column widths.
s.with(_vm.columns.Select( c => c.create())),
this.observe_title()
s.with(_vm.columns.Select(c => c.create()))
)
);
// TODO: bind to main window's Title
var dialog = new ShellSettingsDialog { Title = "Market View Grid Settings", DataContext = vm };
vm.SubscribeDisposed(literal_title_source.OnDispatcher().Subscribe(t => vm.title = t));
var dialog = new ShellSettingsDialog { DataContext = vm };
vm.RequestClose += (s, e) => WindowUtilities.force_close(dialog);
return dialog;
}))
@@ -7,6 +7,7 @@ using mbts.co2;
using mbts.persist;
using mbts.ui;
using mbts.ui.settings;
using mbts.ui.shell;
using mbts.ui.spark;
using mbts.ui.utility;
using mbts.utils;
@@ -17,7 +18,6 @@ using System.Reactive.Linq;
using System.Windows;
using System.Windows.Media;
using static bts.shell.TimeAndSalesWindowFactory;
using static mbts.ui.controls.DIYGrid;
namespace mbts.spark {
class TimeAndSalesWindow : SparkWindow<StartupData>, ISharedWindow {
@@ -77,12 +77,11 @@ namespace mbts.spark {
s => _vm.value.grid_settings_manager.create_vm(
// we need to get the most up to date GridSettings when launching b/c users may
// have changed some settings on the grid directly, like column widths.
s.with(_vm.value.columns.Select( c => c.create())),
this.observe_title()
s.with(_vm.value.columns.Select(c => c.create()))
)
);
// TODO: bind to main window's Title
var dialog = new ShellSettingsDialog { Title = "Time and Sales Grid Settings", DataContext = vm };
vm.SubscribeDisposed(literal_title_source.OnDispatcher().Subscribe(t => vm.title = t));
var dialog = new ShellSettingsDialog { DataContext = vm };
vm.RequestClose += (s, e) => WindowUtilities.force_close(dialog);
return dialog;
}))
@@ -82,11 +82,10 @@ namespace mbts.spark {
s => _vm.value.grid_settings_manager.create_vm(
// we need to get the most up to date GridSettings when launching b/c users may
// have changed some settings on the grid directly, like column widths.
s.with(_vm.value.columns.Select( c => c.create())),
this.observe_title()
s.with(_vm.value.columns.Select(c => c.create()))
)
);
// TODO: bind to main window's Title
vm.SubscribeDisposed(literal_title_source.OnDispatcher().Subscribe(t => vm.title = t));
var dialog = new ShellSettingsDialog { Title = "Synthetic Management Grid Settings", DataContext = vm };
vm.RequestClose += (s, e) => WindowUtilities.force_close(dialog);
return dialog;
@@ -1,14 +1,9 @@
using bts.api;
using mbts;
using mbts.config;
using mbts.spark;
using mbts.ui;
using ProtoBuf;
using mbts.ui.shell;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Threading.Tasks;
using System.Windows.Controls;
using mbts;
namespace bts.shell {
public class BrowserWindow : IShellWindow {
@@ -75,12 +70,15 @@ namespace bts.shell {
public string window_type => _window_type;
public IShellModule Owner {get; set; }
public ShellWindowUI GetContent() { return new ShellWindowUI(_browser); }
public void GetState(System.IO.Stream save_here) {
_isw.save(new BrowserWindowState() { uri = uri.ToString() }, save_here);
}
public void on_shell_window_vm(ShellWindowVM shell_window_vm) { }
public void Dispose() {
if (_browser != null) {
_browser.Dispose();
@@ -102,5 +100,4 @@ namespace bts.shell {
}
#endregion
}
}
}
@@ -6,6 +6,7 @@ using bts.spark;
using mbts.persist;
using mbts.ui;
using mbts.ui.settings;
using mbts.ui.shell;
using mbts.ui.spark;
using mbts.ui.utility;
using mbts.utils;
@@ -67,12 +68,11 @@ namespace mbts.spark {
s => _vm.grid_settings_manager.create_vm(
// we need to get the most up to date GridSettings when launching b/c users may
// have changed some settings on the grid directly, like column widths.
s.with(_vm.columns.Select( c => c.create())),
this.observe_title()
s.with(_vm.columns.Select(c => c.create()))
)
);
// TODO: bind to main window's Title
var dialog = new ShellSettingsDialog { Title = $"{window_type_name} Grid Settings", DataContext = vm };
vm.SubscribeDisposed(literal_title_source.OnDispatcher().Subscribe(t => vm.title = t));
var dialog = new ShellSettingsDialog { DataContext = vm };
vm.RequestClose += (s, e) => WindowUtilities.force_close(dialog);
return dialog;
}))
@@ -1,12 +1,12 @@
using bts.api;
using bts.md;
using bts.shell.orderbook;
using mbts;
using mbts.config;
using mbts.persist;
using mbts.spark;
using mbts.spark.utilities;
using mbts.ui;
using mbts.ui.shell;
using mbts.ui.spark;
using ProtoBuf;
using System;
@@ -82,6 +82,11 @@ namespace bts.shell {
IShellWindow create_ladder_window(SecurityMD md, LadderSettings state_settings, uint settings_id = 0) {
IDisposable active_settings_dialog = null;
var thread_id = Interlocked.Increment(ref _ladder_count) % Environment.ProcessorCount;
// on_shell_window_vm should behave like an event (do not set to null)
Action<ShellWindowVM> on_shell_window_vm = _ => { };
ShellWindowVM shell_window_vm = null;
IShellWindow shell_window = null;
var title_source = new LazyObservable<string>(() => ShellWindowExtensions.literal_title_source(shell_window, shell_window_vm));
var view = new Lazy<UIElement>(() => {
// resources
var model = new LadderModel(md, _orders_model, _mbo);
@@ -170,10 +175,8 @@ namespace bts.shell {
settings_id);
dialog_vm.applied += apply;
// dialog
var dialog = new ShellSettingsDialog {
DataContext = dialog_vm,
Title = $"Ladder Settings - '{vm.security}'"
};
var dialog = new ShellSettingsDialog { DataContext = dialog_vm };
dialog_vm.SubscribeDisposed(title_source.OnDispatcher().Subscribe(t => dialog_vm.title = t));
dialog.Resources[ShellSettingsDialog.SecurityMapKey] = _securities;
dialog_vm.RequestClose += on_request_close;
dialog.Closed += on_closed;
@@ -223,11 +226,15 @@ namespace bts.shell {
}
});
string thread = _ladder_conf.ladders_on_threads ? $"Ladder{thread_id:00}" : "";
return ShellWindow.create(
return shell_window = ShellWindow.create(
module, md.security.ToString(), _window_type, view,
(v,s) => save(_get_state(((LadderView)v).vm, settings_id), s),
icon: Icons.Ladder,
thread_id: thread);
(v, s) => save(_get_state(((LadderView)v).vm, settings_id), s),
icon: Icons.Ladder,
thread_id: thread,
vm => {
shell_window_vm = vm;
title_source.connect();
});
}
void show_windows(IReadOnlyCollection<SecurityMD> securities) {
@@ -293,7 +293,7 @@ namespace mbts.spark {
price_filter.minimum.value = real_price;
price_filter.maximum.value = real_price;
var obvm = new OrderBookVM(null, _owner.bus, null, _owner.model.order_gateway, null, true);
var obvm = new OrderBookVM(_owner.bus, null, _owner.model.order_gateway, null, true);
var state = new bts.shell.orderbook.OrderBookStartupData(
new bts.shell.orderbook.FilterStates {
security_criteria = new SecurityCriteria(_owner.security),
@@ -161,7 +161,7 @@ namespace mbts.spark {
}
public MarketSizeDisplayVM size_display { get; } = new MarketSizeDisplayVM();
public SimpleGridSettingsVM mini_ob { get; } = new SimpleGridSettingsVM(Observable.Return("Mini OrderBook"), OrderBookGridSettingsManager.hard_column_flags);
public SimpleGridSettingsVM mini_ob { get; } = new SimpleGridSettingsVM(OrderBookGridSettingsManager.hard_column_flags);
// price format
public LadderSettings.NetChangeTerms price_format { get => _price_format; set => Set(ref _price_format, value); }
public IEnumerable<LadderSettings.NetChangeTerms> price_format_options => EnumHelper.get_values<LadderSettings.NetChangeTerms>();
@@ -70,7 +70,6 @@ namespace mbts.spark {
Dictionary<uint, IDisposable> _on_updated_single_callback_gatekeeper = new Dictionary<uint, IDisposable>();
public OrderBookVM(
IObservable<string> owner_title,
IBus bus,
INotificationService notification_service,
OrdersModel model,
@@ -148,8 +147,7 @@ namespace mbts.spark {
s => fills_vm.value.grid_settings_manager.create_vm(
// we need to get the most up to date GridSettings when launching b/c users may
// have changed some settings on the grid directly, like column widths.
s.with(fills_vm.columns.Select(c => c.create())),
Observable.Return(title)
s.with(fills_vm.columns.Select(c => c.create()))
),
show_save_as_defaults: false);
// TODO: bind to main window's Title
@@ -157,7 +155,7 @@ namespace mbts.spark {
vm.RequestClose += (s, e) => WindowUtilities.force_close(dialog);
return dialog;
}));
grid_settings_manager = new OrderBookGridSettingsManager(owner_title, bus, notification_service, model, rows, columns);
grid_settings_manager = new OrderBookGridSettingsManager(bus, notification_service, model, rows, columns);
grid_settings_manager.algo_tree_display_mode_changed += _on_filter_changed;
IDisposable attach_vm_hooks = null;
begin_attaching += on_begin_attaching;
@@ -7,8 +7,8 @@ using bts.spark;
using bts.view;
using mbts.persist;
using mbts.ui;
using mbts.ui.converters;
using mbts.ui.extensions;
using mbts.ui.shell;
using mbts.ui.spark;
using mbts.ui.utility;
using mbts.utils;
@@ -17,10 +17,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using OrderBookGridSettingsVM = mbts.spark.GridSettingsVM<bts.api.orderman.OrderSecurity, mbts.OrderRecordTuplePredicate, bts.shell.orderbook.OrderBookGridSettings>;
namespace mbts.spark {
internal class OrderBookWindow : SparkWindow<OrderBookStartupData>, ISharedWindow {
@@ -65,7 +63,7 @@ namespace mbts.spark {
}
public void thread_init() {
_vm = new OrderBookVM(this.observe_title(), _bus, _notification_service, _model, _settings_manager);
_vm = new OrderBookVM(_bus, _notification_service, _model, _settings_manager);
_vm.load_from(_state);
_view = new OrderBookView(_vm);
@@ -171,14 +169,11 @@ namespace mbts.spark {
// we need to get the most up to date GridSettings when launching b/c users may
// have changed some settings on the grid directly, like column widths.
s.general = s.general.with(_vm.core_columns.Select(c => c.create()));
return _vm.grid_settings_manager.create_vm(s, this.observe_title());
return _vm.grid_settings_manager.create_vm(s);
}
);
// TODO: bind to main window's Title
gs_vm.SubscribeDisposed(literal_title_source.OnDispatcher().Subscribe(t => gs_vm.title = t));
var dialog = new ShellSettingsDialog { DataContext = gs_vm };
dialog.SetBinding(Window.TitleProperty, new Binding($"{nameof(gs_vm.instance_vm)}.{nameof(OrderBookGridSettingsVM.owner_title)}") {
Converter = ValueConverter.create<string, string>(str => (string.IsNullOrEmpty(str) ? _default_title : str) + " Settings")
});
gs_vm.RequestClose += (s, e) => WindowUtilities.force_close(dialog);
return dialog;
}));
@@ -34,14 +34,13 @@ namespace bts.shell.orderbook {
}
public OrderBookGridSettingsManager(
IObservable<string> owner_title,
IBus bus,
INotificationService notification_service,
OrdersModel model,
IEnumerable<OrderBookRowVM> rows,
ObservableCollection<DIYGrid.ColumnBase> columns) {
core_manager = new GridSettingsManager<OrderBookRowVM, OrderSecurity, OrderRecordTuplePredicate, OrderBookGridSettings>(
owner_title, bus, model, rows, columns,
bus, model, rows, columns,
() => new OrderRecordTuplePredicate(),
() => {
var pvm = PredicateVMWrapper.create<OrderSecurity, OrderRecordTuplePredicate, OrderRecordTuplePredicate.PredicateTypeOneofCase>(
@@ -90,8 +89,8 @@ namespace bts.shell.orderbook {
return gs;
}
public OrderBookSettingsVM create_vm(OrderBookGridSettings gs, IObservable<string> owner_title) =>
new OrderBookSettingsVM(core_manager.create_vm(gs.general, owner_title)) {
public OrderBookSettingsVM create_vm(OrderBookGridSettings gs) =>
new OrderBookSettingsVM(core_manager.create_vm(gs.general)) {
algo_tree_display_mode = gs.algo_tree_display_mode
};
@@ -17,7 +17,8 @@ namespace bts.shell.orderbook {
this.core_settings_vm = core_settings_vm;
public OrderBookSettingsVM(
IObservable<string> owner_title, IBus bus, OrdersModel orders_model,
IBus bus,
OrdersModel orders_model,
Func<OrderRecordTuplePredicate> predicate_data_factory,
Func<OrderRecordTuplePredicate, INotificationPredicate<OrderSecurity>> notification_predicate_factory,
Func<IPropertyWrapperVM<OrderRecordTuplePredicate>> create_predicate_vm,
@@ -25,7 +26,7 @@ namespace bts.shell.orderbook {
Func<GridSettings, IEnumerable<IPredicateAnimationsData<OrderSecurity, OrderRecordTuplePredicate>>, OrderBookGridSettings> create_settings_obj,
IReadOnlyDictionary<string, GridColumnSettingsFeatureFlags> column_flags = null) {
core_settings_vm = new GridSettingsVM<OrderSecurity, OrderRecordTuplePredicate, OrderBookGridSettings>(
owner_title, bus, orders_model, predicate_data_factory, notification_predicate_factory, create_predicate_vm, create_column_predicate_vm, create_settings_obj, column_flags);
bus, orders_model, predicate_data_factory, notification_predicate_factory, create_predicate_vm, create_column_predicate_vm, create_settings_obj, column_flags);
}
public GridSettingsVM<OrderSecurity, OrderRecordTuplePredicate, OrderBookGridSettings> core_settings_vm { get; }
@@ -1,14 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using mbts.ui.shell;
using System;
using System.Windows.Threading;
namespace mbts.ui.tests
{
class TestShellWindow : IShellWindow
{
namespace mbts.ui.tests {
class TestShellWindow : IShellWindow {
#region IShellWindow boilerplate
public string Title { get; set; }
public event Action TitleChanged = () => { };
@@ -20,6 +15,7 @@ namespace mbts.ui.tests
#endregion
public Dispatcher Dispatcher { get; private set; }
public ShellWindowUI GetContent() {
this.Dispatcher = Dispatcher.CurrentDispatcher;
var content = new System.Windows.Forms.Button() { Text = "Click Me!", Width = 100, Height = 100 };
@@ -27,10 +23,12 @@ namespace mbts.ui.tests
}
public bool IsDisposed { get; set; }
public void on_shell_window_vm(ShellWindowVM shell_window_vm) { }
public void Dispose() { IsDisposed = true; }
}
class TestSlowWindow : TestShellWindow, ISlowWindow {
public void thread_init() { }
}
}
}
@@ -27,6 +27,8 @@ namespace mbts.ui {
// module to ask to restore the window after app restart.
IShellModule Owner { get; }
void on_shell_window_vm(ShellWindowVM shell_window_vm);
// Return the UI controls which will be displayed
ShellWindowUI GetContent();
@@ -113,5 +115,28 @@ namespace mbts.ui {
return src.Subscribe(o);
});
}
/// <summary>
/// Returns an IObservable sequence of <see cref="ShellWindowVM.Title"/>.
/// </summary>
public static IObservable<string> literal_title_source(IShellWindow shell_window, ShellWindowVM shell_window_vm) {
return Observable.Create<string>(o => {
shell_window_vm.TitleOverrideChanged += on_title_override_changed;
shell_window.TitleChanged += notify;
notify();
connect();
return Disposable.Create(disconnect);
void connect() {
shell_window_vm.Model.TitleChanged += notify;
shell_window_vm.TitleOverrideChanged += on_title_override_changed;
}
void disconnect() {
shell_window_vm.Model.TitleChanged -= notify;
shell_window_vm.TitleOverrideChanged -= on_title_override_changed;
}
void on_title_override_changed(string value) => notify();
void notify() => o.OnNext(shell_window_vm.Title);
});
}
}
}
@@ -44,7 +44,6 @@ namespace mbts.ui {
IEnumerable<IPredicateAnimationsData<TRowData, TPredicateData>> _predicate_animations_data;
public GridSettingsManager(
IObservable<string> owner_title,
IBus bus,
OrdersModel orders_model,
IEnumerable<TRow> rows,
@@ -90,8 +89,8 @@ namespace mbts.ui {
public SolidColorBrush font_color => _font_color.Value;
public SolidColorBrush selection_highlight => _selection_highlight.Value;
public GridSettingsVM<TRowData, TPredicateData, TSettingsData> create_vm(GridSettings settings, IObservable<string> title) {
var vm = new GridSettingsVM<TRowData, TPredicateData, TSettingsData>(title, _bus, _orders_model, _predicate_data_factory, _notification_predicate_factory, _create_predicate_vm, _create_column_predicate_vm, _create_settings_obj, _column_flags.ToDictionary(kv => kv.Key, kv => kv.Value.flags));
public GridSettingsVM<TRowData, TPredicateData, TSettingsData> create_vm(GridSettings settings) {
var vm = new GridSettingsVM<TRowData, TPredicateData, TSettingsData>(_bus, _orders_model, _predicate_data_factory, _notification_predicate_factory, _create_predicate_vm, _create_column_predicate_vm, _create_settings_obj, _column_flags.ToDictionary(kv => kv.Key, kv => kv.Value.flags));
vm.load(_create_settings_obj(settings, _predicate_animations_data));
return vm;
}
@@ -54,14 +54,15 @@ namespace mbts.spark {
readonly Property<IColumnVM> _current_column;
readonly Property<FontFamily> _font_family;
readonly Property<FontWeight> _font_weight;
readonly Property<string> _font_display_name, _owner_title;
readonly Property<string> _font_display_name;
readonly Property<double> _font_size;
readonly Property<bool> _show_predicate_animations, _show_cell_predicate_animations;
readonly OrdersModel _orders_model;
readonly IReadOnlyDictionary<string, GridColumnSettingsFeatureFlags> _column_flags;
public GridSettingsVM(
IObservable<string> owner_title, IBus bus, OrdersModel orders_model,
IBus bus,
OrdersModel orders_model,
Func<TPredicateData> predicate_data_factory,
Func<TPredicateData, INotificationPredicate<TRowData>> notification_predicate_factory,
Func<IPropertyWrapperVM<TPredicateData>> create_predicate_vm,
@@ -69,7 +70,6 @@ namespace mbts.spark {
Func<GridSettings, IEnumerable<IPredicateAnimationsData<TRowData, TPredicateData>>, TSettingsData> create_settings_obj,
IReadOnlyDictionary<string, GridColumnSettingsFeatureFlags> column_flags = null) {
//
_owner_title = backing(nameof(owner_title), owner_title);
this.bus = bus;
_orders_model = orders_model;
_predicate_data_factory = predicate_data_factory;
@@ -92,7 +92,6 @@ namespace mbts.spark {
public event EventHandler RequestClose;
public event Action committed;
public string owner_title => _owner_title.Value;
public IBus bus { get; }
public ObservableCollection<IColumnVM> columns { get; } = new ObservableCollection<IColumnVM>();
public IColumnVM current_column { get => _current_column.Value; set => _current_column.set(value); }
@@ -45,8 +45,8 @@ namespace mbts.ui {
public SolidColorBrush font_color => _font_color.Value;
public SolidColorBrush selection_highlight => _selection_highlight.Value;
public SimpleGridSettingsVM create_vm(GridSettings settings, IObservable<string> title) {
var vm = new SimpleGridSettingsVM(title, _column_flags.ToDictionary(kv => kv.Key, kv => kv.Value.flags));
public SimpleGridSettingsVM create_vm(GridSettings settings) {
var vm = new SimpleGridSettingsVM(_column_flags.ToDictionary(kv => kv.Key, kv => kv.Value.flags));
vm.load_from(settings);
return vm;
}
@@ -34,15 +34,14 @@ namespace mbts.spark {
readonly Property<ISimpleColumnVM> _current_column;
readonly Property<FontFamily> _font_family;
readonly Property<FontWeight> _font_weight;
readonly Property<string> _font_display_name, _owner_title;
readonly Property<string> _font_display_name;
readonly Property<double> _font_size;
readonly Property<bool> _show_predicate_animations, _show_cell_predicate_animations;
readonly DeferrableActionWrapper _update;
readonly IReadOnlyDictionary<string, GridColumnSettingsFeatureFlags> _column_flags;
public SimpleGridSettingsVM(IObservable<string> owner_title, IReadOnlyDictionary<string, GridColumnSettingsFeatureFlags> column_flags = null) {
public SimpleGridSettingsVM(IReadOnlyDictionary<string, GridColumnSettingsFeatureFlags> column_flags = null) {
_column_flags = column_flags ?? new Dictionary<string, GridColumnSettingsFeatureFlags>();
_owner_title = backing(nameof(owner_title), owner_title);
_font_family = backing(nameof(font_family), TextUtils.StandardFontFamily);
_font_size = backing(nameof(font_size), FontSizes.Small);
_font_weight = backing(nameof(font_weight), FontWeights.Normal);
@@ -73,7 +72,6 @@ namespace mbts.spark {
public event EventHandler RequestClose;
public event Action committed, result_changed;
public string owner_title => _owner_title.Value;
public ObservableCollection<ISimpleColumnVM> columns { get; } = new ObservableCollection<ISimpleColumnVM>();
public ISimpleColumnVM current_column { get => _current_column.Value; set => _current_column.set(value); }
public string font_display_name => _font_display_name.Value;
@@ -1,23 +1,14 @@
using System;
using mbts.ui.shell;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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;
using mbts.ui;
using mbts.ui.shell;
namespace mbts.ui.controls
{
namespace mbts.ui.controls {
public partial class HierarchicalLaunchMenu : UserControl, IShellWindow
{
public HierarchicalLaunchMenu(object context) {
@@ -36,27 +27,7 @@ namespace mbts.ui.controls
public ShellWindowUI GetContent() {
return new ShellWindowUI(this);
}
//bool _tree_was_clicked = false;
//private async void _tree_clicked(object sender, RoutedEventArgs e)
//{
// e.Handled = true;
// if (_tree_was_clicked) return;
// _tree_was_clicked = true;
// DependencyObject source = e.OriginalSource as DependencyObject;
// while (source != null && !(source is TreeViewItem))
// source = VisualTreeHelper.GetParent(source);
// TreeViewItem tvi = source as TreeViewItem;
// if (tvi != null)
// tvi.IsExpanded = !tvi.IsExpanded;
// await Task.Delay(1000);
// _tree_was_clicked = false;
//}
public void on_shell_window_vm(ShellWindowVM shell_window_vm) { }
}
public class HierarchicalViewModel : ViewModelBase
@@ -1,26 +1,12 @@
using System;
using System.Collections.Generic;
using mbts.ui.shell;
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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;
using mbts.ui;
using mbts.ui.shell;
namespace mbts.ui.controls
{
public partial class MenuLaunchMenu : UserControl, IShellWindow
{
namespace mbts.ui.controls {
public partial class MenuLaunchMenu : UserControl, IShellWindow {
public ObservableCollection<MenuLaunchMenuViewModel> MenuItems { get; set; }
public MenuLaunchMenu(object context)
{
@@ -39,11 +25,10 @@ namespace mbts.ui.controls
public ShellWindowUI GetContent() {
return new ShellWindowUI(this);
}
public void on_shell_window_vm(ShellWindowVM shell_window_vm) { }
}
public class MenuLaunchMenuViewModel : ViewModelBase
{
public class MenuLaunchMenuViewModel : ViewModelBase {
public string Header { get; set; }
public ObservableCollection<MenuLaunchMenuViewModel> MenuItems { get; set; }
@@ -51,7 +36,5 @@ namespace mbts.ui.controls
public ICommand Command { get; set; }
public object Args { get; set; }
}
}
}
@@ -1,4 +1,5 @@
using System;
using mbts.ui.shell;
using System;
using System.IO;
using System.Windows;
using System.Windows.Media;
@@ -38,30 +39,36 @@ namespace mbts.ui {
public Lazy<UIElement> Content { get; set; }
public Action<ShellWindowVM> on_shell_window_vm { get; set; }
void IShellWindow.on_shell_window_vm(ShellWindowVM shell_window_vm) =>
on_shell_window_vm?.Invoke(shell_window_vm);
}
class LazyAnonShellWindow : AnonShellWindow, ISharedWindow {
public string thread_id { get; set; }
public void thread_init() { }
}
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) {
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, Action<ShellWindowVM> on_shell_window_vm = null) {
if (string.IsNullOrEmpty(thread_id)) {
return create<AnonShellWindow>(owner, title, window_type, content, get_state, icon);
return create<AnonShellWindow>(owner, title, window_type, content, get_state, icon, on_shell_window_vm);
}
else {
var res = create<LazyAnonShellWindow>(owner, title, window_type, content, get_state, icon);
var res = create<LazyAnonShellWindow>(owner, title, window_type, content, get_state, icon, on_shell_window_vm);
res.thread_id = thread_id;
return res;
}
}
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() {
static T create<T>(IShellModule owner, string title, string window_type, Lazy<UIElement> content, Action<UIElement,Stream> get_state=null, ImageSource icon=null, Action<ShellWindowVM> on_shell_window_vm = 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,
on_shell_window_vm = on_shell_window_vm,
Content = content,
Disposable = Disposable.Create(() => {
if (content.IsValueCreated) {
@@ -29,6 +29,8 @@ namespace mbts.ui.shell {
}
public void on_shell_window_vm(ShellWindowVM shell_window_vm) { }
public void Dispose() {
}
@@ -12,6 +12,7 @@
xmlns:sys="clr-namespace:System;assembly=mscorlib"
u:WindowStyle.AllowResize="True"
u:WindowStyle.SizeToContent="WidthAndHeight"
Title="{Binding title, StringFormat='{}{0} Settings'}"
Style="{StaticResource BTSWindow}"
UseLayoutRounding="True"
>
@@ -23,11 +23,12 @@ namespace mbts.spark {
T get_result();
}
class ShellSettingsDialogVM<T, TVM> : ViewModelBase, IRequestViewClose, IDisposable where T : class, IEquatable<T> where TVM : IWindowSettingsVM<T> {
class ShellSettingsDialogVM<T, TVM> : ViewModelBase, IRequestViewClose, IDisposable, IWillLetYouKnowWhenIDispose where T : class, IEquatable<T> where TVM : IWindowSettingsVM<T> {
readonly Property<bool> _use_default;
readonly DialogSkirtItem _ok_item, _apply_item, _cancel_item, _apply_to_defaults_item;
readonly DelegateProperty<IEnumerable<DialogSkirtItem>> _left_skirt_items;
readonly List<IDisposable> _resources = new List<IDisposable>(2); // initialize with 2 capacity bc the only potential disposables are the instance/default vms
string _title;
public ShellSettingsDialogVM(IWindowSettingsManager<T> settings_manager, Func<UserSettings, T> get_factory_settings, string settings_file_ext, Func<T, TVM> vm_factory, Func<T, T> merge_with_current = null, bool show_save_as_defaults = true) {
if (merge_with_current == null)
@@ -94,7 +95,9 @@ namespace mbts.spark {
}
public event EventHandler RequestClose;
public event Action<bool> OnDisposed;
public string title { get => _title; set => Set(ref _title, value); }
public TVM instance_vm { get; }
public TVM default_vm { get; }
public IReadOnlyCollection<IMenuItemVM> action_menu_items { get; }
@@ -111,8 +114,10 @@ namespace mbts.spark {
set => _use_default.Value = value;
}
public void Dispose() =>
public void Dispose() {
Disposable.dispose(_resources);
OnDisposed?.Invoke(true);
}
}
class ProfiledShellSettingsDialogVM<T, TVM, TProfile> : DisposableViewModelBase, IRequestViewClose where T : class, IEquatable<T> where TVM : class, IValueFactory<T>, IObservable<T> where TProfile : ISettingsProfile<T> {
@@ -120,6 +125,7 @@ namespace mbts.spark {
readonly Property<ProfileVM> _selected_profile;
readonly Func<T, TVM> _vm_factory;
readonly ProfileVM _local_profile;
string _title;
bool _is_copy_menu_open;
DialogSkirtItem _apply_item, _ok_item, _cancel_item;
MenuItemVM _import_item, _export_item, _load_factory_item;
@@ -271,6 +277,7 @@ namespace mbts.spark {
public event Action<SettingsProfile<T>> applied;
public event EventHandler RequestClose;
public string title { get => _title; set => Set(ref _title, value); }
public ObservableCollection<ProfileVM> profiles { get; } = new ObservableCollection<ProfileVM>();
public ProfileVM selected_profile {
get => _selected_profile.Value;
@@ -1,31 +1,20 @@
using System;
using mbts.ui;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Input;
using System.IO;
using System.Windows.Threading;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Controls;
using mbts.ui.settings;
using System.Windows.Interop;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using bts;
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
namespace mbts.ui.shell
{
public class ShellWindowVM : ViewModelBase, IDisposable
{
namespace mbts.ui.shell {
public class ShellWindowVM : ViewModelBase, IDisposable {
IShellWindow _model;
UIElement _ui;
IWindowManager _wm;
Dispatcher _dispatcher;
HwndContentHost _hwnd_host;
public ShellWindowVM(IShellWindow model, IWindowManager wm, IShellThreadFactory threads, string host = "") {
Log.assert(model != null);
_model = model;
@@ -44,6 +33,7 @@ namespace mbts.ui.shell
}
_edit_mode = backing(nameof(EditMode), false);
model.on_shell_window_vm(this);
}
void title_changed() {
@@ -56,6 +46,8 @@ namespace mbts.ui.shell
RaisePropertyChanged("Icon");
}
public event Action<string> TitleOverrideChanged;
public string host_id { get; set; }
public Dispatcher Dispatcher { get { return _dispatcher; } }
@@ -73,6 +65,7 @@ namespace mbts.ui.shell
}
RaisePropertyChanged(nameof(TitleOverride), nameof(Title), nameof(HasCustomTitle));
_edit_mode.set(false);
TitleOverrideChanged?.Invoke(_title_override);
}
}
public bool HasCustomTitle => !string.IsNullOrWhiteSpace(TitleOverride);
@@ -218,7 +211,6 @@ namespace mbts.ui.shell
public void Dispose() {
_model.TitleChanged -= title_changed;
_model.IconChanged -= icon_changed;
if (IsShared) {
// Shared threads continue running
_dispatcher.Invoke(() => Disposable.dispose(ref _model));
@@ -237,5 +229,4 @@ namespace mbts.ui.shell
}
}
}
@@ -9,6 +9,7 @@ using mbts.ui.utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Windows;
using System.Windows.Media;
@@ -64,12 +65,12 @@ namespace mbts.spark {
s => _vm.grid_settings_manager.create_vm(
// we need to get the most up to date GridSettings when launching b/c users may
// have changed some settings on the grid directly, like column widths.
s.with(_vm.columns.Select( c => c.create())),
this.observe_title()
s.with(_vm.columns.Select( c => c.create()))
)
);
vm.SubscribeDisposed(literal_title_source.OnDispatcher().Subscribe(t => vm.title = t));
// TODO: bind to main window's Title
var dialog = new ShellSettingsDialog { Title = "PnL Grid Settings", DataContext = vm };
var dialog = new ShellSettingsDialog { DataContext = vm };
vm.RequestClose += (s, e) => WindowUtilities.force_close(dialog);
return dialog;
}))
+24 -1
View File
@@ -3,10 +3,12 @@ using bts.shell;
using bts.view;
using mbts;
using mbts.ui;
using mbts.ui.shell;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
@@ -24,11 +26,12 @@ namespace bts.spark {
ABSOLUTE_MIN_HEIGHT = 230;
protected static readonly TimeSpan CONTENT_MEASURE_WAIT_PERIOD = TimeSpan.FromSeconds(0.3);
protected readonly IBus _bus;
readonly ISaveWindow<T> _save;
string _title;
ImageSource _icon;
ShellWindowVM _shell_window_vm;
IObservable<string> _literal_title_source;
public SparkWindow(string title, IBus bus, ISaveWindow<T> isw, ImageSource icon = null) {
_bus = bus;
@@ -39,6 +42,7 @@ namespace bts.spark {
public event Action TitleChanged;
public event Action IconChanged;
event Action _shell_window_arrived;
public string Title {
get => _title;
@@ -64,6 +68,20 @@ namespace bts.spark {
public virtual double MinWidth => 400;
public virtual double MinHeight => Math.Max(ABSOLUTE_MIN_HEIGHT, TITLE_PANEL_HEIGHT + COLUMN_HEADER_HEIGHT + GRID_FOOTER_HEIGHT + Commands.Count() * SPARK_MENU_ITEM_HEIGHT);
protected IObservable<string> literal_title_source {
get {
if (_literal_title_source == null) {
if (_shell_window_vm != null)
_literal_title_source = ShellWindowExtensions.literal_title_source(this, _shell_window_vm);
else {
var lazy_wrapper = new LazyObservable<string>(() => ShellWindowExtensions.literal_title_source(this, _shell_window_vm));
_shell_window_arrived += lazy_wrapper.connect;
}
}
return _literal_title_source;
}
}
public static SparkWindow<T> create(string window_type, string title, IBus bus, ISaveWindow<T> save_window, ImageSource icon, string thread_id, Func<(UIElement content, IEnumerable<SparkCommand> commands, Func<T> get_save_state, IDisposable dispose)> thread_init, double min_width = double.NaN, double min_height = double.NaN) =>
new AnonymousShared(window_type, title, bus, save_window, icon, thread_id, thread_init, min_width, min_height);
@@ -88,6 +106,11 @@ namespace bts.spark {
);
}
public void on_shell_window_vm(ShellWindowVM shell_window_vm) {
_shell_window_vm = shell_window_vm;
_shell_window_arrived?.Invoke();
}
public abstract void Dispose();
protected virtual void OnParentViewCreated(SparkWindowView parent_view) { }
@@ -0,0 +1,50 @@
using mbts;
using System;
using System.Reactive.Subjects;
namespace bts.api {
/// Similar to an <see cref="IConnectableObservable{T}"/>, except that the late-connection cannot be disposed (i.e., <see cref="connect"/> does not return an IDisposable).
class LazyObservable<T> : IObservable<T> {
readonly Func<IObservable<T>> _factory;
readonly object _lock = new object();
IObservable<T> _source;
public LazyObservable(Func<IObservable<T>> factory) =>
_factory = factory;
event Action _connected;
public void connect() {
// try once, without locking
if (_source != null)
return;
Action temp;
lock (_lock) {
// check if its non-null again (it may have been assigned on another thread since the first null check)
if (_source != null)
return;
_source = _factory();
temp = _connected;
}
temp?.Invoke();
}
public IDisposable Subscribe(IObserver<T> observer) {
// try once, without locking (source will only be assigned once, so no risk that it will transition from non-null to null)
if (_source != null)
return _source.Subscribe(observer);
LazySubscription sub;
lock (_lock) {
// check if its non-null again (it may have been assigned on another thread since the first null check)
if (_source != null)
return _source.Subscribe(observer);
sub = new LazySubscription(() => _source.Subscribe(observer));
_connected += sub.connect;
}
return Disposable.Create(() => {
_connected -= sub.connect;
sub?.Dispose();
});
}
}
}
@@ -1,3 +1,4 @@
using mbts;
using System;
namespace bts.api {