made anonymous SparkWindow factory
This commit is contained in:
1 parent
ac76462f7e
commit
cc04e79f8b
1 file changed
+37
@@ -1,6 +1,7 @@
|
||||
using bts.api;
|
||||
using bts.shell;
|
||||
using bts.view;
|
||||
using mbts;
|
||||
using mbts.ui;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -63,6 +64,9 @@ 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);
|
||||
|
||||
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) =>
|
||||
new AnonymousShared(window_type, title, bus, save_window, icon, thread_id, thread_init);
|
||||
|
||||
public ShellWindowUI GetContent() {
|
||||
var parent_view = new SparkWindowView(_bus, Commands, Content);
|
||||
OnParentViewCreated(parent_view);
|
||||
@@ -87,5 +91,38 @@ namespace bts.spark {
|
||||
public abstract void Dispose();
|
||||
|
||||
protected virtual void OnParentViewCreated(SparkWindowView parent_view) { }
|
||||
|
||||
class AnonymousShared : SparkWindow<T>, ISharedWindow {
|
||||
Func<(UIElement content, IEnumerable<SparkCommand> commands, Func<T> get_save_state, IDisposable dispose)> _thread_init;
|
||||
Func<T> _get_save_state;
|
||||
IEnumerable<SparkCommand> _commands;
|
||||
UIElement _content;
|
||||
IDisposable _dispose;
|
||||
|
||||
public AnonymousShared(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)
|
||||
: base(title, bus, save_window, icon) {
|
||||
this.thread_id = thread_id;
|
||||
_thread_init = thread_init ?? throw new ArgumentNullException(nameof(thread_init));
|
||||
}
|
||||
|
||||
public override string window_type { get; }
|
||||
public override T SaveState => _get_save_state();
|
||||
public override UIElement Content => _content;
|
||||
public override IEnumerable<SparkCommand> Commands => _commands;
|
||||
|
||||
public string thread_id { get; }
|
||||
|
||||
public void thread_init() {
|
||||
Log.assert(_thread_init != null, "Thread init has already been executed.");
|
||||
var (content, commands, get_save_state, dispose) = _thread_init();
|
||||
_thread_init = null;
|
||||
_content = content;
|
||||
_commands = commands;
|
||||
_get_save_state = get_save_state;
|
||||
_dispose = dispose;
|
||||
}
|
||||
|
||||
public override void Dispose() => Disposable.dispose(ref _dispose);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user