2019-11-24 03:17:22 +00:00
|
|
|
|
using DynamicData;
|
2019-10-22 03:03:01 +00:00
|
|
|
|
using DynamicData.Binding;
|
|
|
|
|
using ReactiveUI;
|
2019-11-02 23:23:11 +00:00
|
|
|
|
using ReactiveUI.Fody.Helpers;
|
2019-10-22 02:12:55 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2019-10-22 03:03:01 +00:00
|
|
|
|
using System.Reactive.Disposables;
|
|
|
|
|
using System.Reactive.Linq;
|
|
|
|
|
using Wabbajack.Common;
|
2019-10-22 02:12:55 +00:00
|
|
|
|
using Wabbajack.Lib;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack
|
|
|
|
|
{
|
2019-10-23 04:15:42 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Main View Model for the application.
|
|
|
|
|
/// Keeps track of which sub view is being shown in the window, and has some singleton wiring like WorkQueue and Logging.
|
|
|
|
|
/// </summary>
|
2019-10-22 02:12:55 +00:00
|
|
|
|
public class MainWindowVM : ViewModel
|
|
|
|
|
{
|
2019-10-25 04:26:29 +00:00
|
|
|
|
public MainWindow MainWindow { get; }
|
2019-10-22 02:12:55 +00:00
|
|
|
|
|
2019-11-06 03:22:38 +00:00
|
|
|
|
public MainSettings Settings { get; }
|
|
|
|
|
|
2019-11-21 15:45:00 +00:00
|
|
|
|
private readonly ObservableAsPropertyHelper<ViewModel> _activePane;
|
|
|
|
|
public ViewModel ActivePane => _activePane.Value;
|
2019-10-22 02:12:55 +00:00
|
|
|
|
|
2019-10-23 04:15:42 +00:00
|
|
|
|
public ObservableCollectionExtended<string> Log { get; } = new ObservableCollectionExtended<string>();
|
|
|
|
|
|
2019-11-02 23:23:11 +00:00
|
|
|
|
[Reactive]
|
|
|
|
|
public RunMode Mode { get; set; }
|
2019-10-25 04:26:29 +00:00
|
|
|
|
|
2019-11-21 15:45:00 +00:00
|
|
|
|
private readonly Lazy<CompilerVM> _compiler;
|
|
|
|
|
private readonly Lazy<InstallerVM> _installer;
|
2019-11-02 22:21:05 +00:00
|
|
|
|
|
2019-11-06 03:22:38 +00:00
|
|
|
|
public MainWindowVM(RunMode mode, string source, MainWindow mainWindow, MainSettings settings)
|
2019-10-22 02:12:55 +00:00
|
|
|
|
{
|
2019-11-21 15:04:33 +00:00
|
|
|
|
Mode = mode;
|
|
|
|
|
MainWindow = mainWindow;
|
|
|
|
|
Settings = settings;
|
2019-11-21 15:45:00 +00:00
|
|
|
|
_installer = new Lazy<InstallerVM>(() => new InstallerVM(this, source));
|
|
|
|
|
_compiler = new Lazy<CompilerVM>(() => new CompilerVM(this));
|
2019-10-25 04:26:29 +00:00
|
|
|
|
|
2019-10-23 04:15:42 +00:00
|
|
|
|
// Set up logging
|
2019-11-05 04:14:31 +00:00
|
|
|
|
Utils.LogMessages
|
2019-11-10 23:43:27 +00:00
|
|
|
|
.ObserveOn(RxApp.TaskpoolScheduler)
|
2019-10-23 04:15:42 +00:00
|
|
|
|
.ToObservableChangeSet()
|
2019-11-10 23:43:27 +00:00
|
|
|
|
.Buffer(TimeSpan.FromMilliseconds(250), RxApp.TaskpoolScheduler)
|
2019-10-23 04:15:42 +00:00
|
|
|
|
.Where(l => l.Count > 0)
|
2019-11-24 03:17:22 +00:00
|
|
|
|
.ObserveOn(RxApp.MainThreadScheduler)
|
2019-10-23 04:15:42 +00:00
|
|
|
|
.FlattenBufferResult()
|
|
|
|
|
.Top(5000)
|
2019-11-21 15:04:33 +00:00
|
|
|
|
.Bind(Log)
|
2019-10-23 04:15:42 +00:00
|
|
|
|
.Subscribe()
|
2019-11-21 15:04:33 +00:00
|
|
|
|
.DisposeWith(CompositeDisposable);
|
2019-11-17 04:16:42 +00:00
|
|
|
|
|
2019-11-02 22:21:05 +00:00
|
|
|
|
// Wire mode to drive the active pane.
|
|
|
|
|
// Note: This is currently made into a derivative property driven by mode,
|
|
|
|
|
// but it can be easily changed into a normal property that can be set from anywhere if needed
|
2019-11-21 15:45:00 +00:00
|
|
|
|
_activePane = this.WhenAny(x => x.Mode)
|
2019-10-25 04:26:29 +00:00
|
|
|
|
.Select<RunMode, ViewModel>(m =>
|
|
|
|
|
{
|
|
|
|
|
switch (m)
|
|
|
|
|
{
|
|
|
|
|
case RunMode.Compile:
|
2019-11-21 15:45:00 +00:00
|
|
|
|
return _compiler.Value;
|
2019-10-25 04:26:29 +00:00
|
|
|
|
case RunMode.Install:
|
2019-11-21 15:45:00 +00:00
|
|
|
|
return _installer.Value;
|
2019-10-25 04:26:29 +00:00
|
|
|
|
default:
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
})
|
2019-11-21 15:04:33 +00:00
|
|
|
|
.ToProperty(this, nameof(ActivePane));
|
2019-10-23 04:15:42 +00:00
|
|
|
|
}
|
2019-10-22 02:12:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|