37 lines
1.2 KiB
C#
37 lines
1.2 KiB
C#
namespace mbts.spark {
|
|
using bts;
|
|
using bts.api;
|
|
using bts.shell;
|
|
|
|
using mbts.ui;
|
|
|
|
using System;
|
|
using System.Reactive.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
class VolSurfaceWindowFactory : ShellWindowFactory<VolSurfaceWindowSettings> {
|
|
readonly IBus _bus;
|
|
readonly UserTuple _user;
|
|
|
|
public VolSurfaceWindowFactory(IShellModule module, IBus bus, UserTuple user)
|
|
: base(module, "VolSurface") {
|
|
_bus = bus;
|
|
_user = user;
|
|
_dispose = bus.subscribe(SparkTags.ShowVolSurface).OnDispatcher().Subscribe(
|
|
async state => _bus.post(SparkTags.ShowWindow, await _create(state)));
|
|
}
|
|
|
|
public override Task<IShellWindow> load(VolSurfaceWindowSettings state) =>
|
|
_create(state);
|
|
|
|
async Task<IShellWindow> _create(VolSurfaceWindowSettings state) =>
|
|
new VolSurfaceWindow(this, _bus, await _lookup_vs_name(state.id), state, _user);
|
|
|
|
async Task<string> _lookup_vs_name(int vs_id) {
|
|
var (vol_surfaces, success) = await _bus.subscribe(SparkTags.VolSurfaceListTag).FirstAsyncTask(TimeSpan.FromSeconds(2));
|
|
return success && vol_surfaces != null && vol_surfaces.TryGetValue(vs_id, out var vs_name) ?
|
|
vs_name : "(...)";
|
|
}
|
|
}
|
|
}
|