2020-01-17 04:48:54 +00:00
|
|
|
|
using System;
|
2020-01-05 02:33:38 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2020-01-07 05:44:05 +00:00
|
|
|
|
using System.Reactive;
|
2020-01-05 02:33:38 +00:00
|
|
|
|
using System.Reactive.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using ReactiveUI;
|
|
|
|
|
using ReactiveUI.Fody.Helpers;
|
|
|
|
|
using Wabbajack.Common;
|
|
|
|
|
using Wabbajack.Lib;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack
|
|
|
|
|
{
|
2020-01-05 03:06:34 +00:00
|
|
|
|
public interface IBackNavigatingVM : IReactiveObject
|
|
|
|
|
{
|
|
|
|
|
ViewModel NavigateBackTarget { get; set; }
|
2020-01-07 05:44:05 +00:00
|
|
|
|
ReactiveCommand<Unit, Unit> BackCommand { get; }
|
2020-01-05 03:06:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class BackNavigatingVM : ViewModel, IBackNavigatingVM
|
2020-01-05 02:33:38 +00:00
|
|
|
|
{
|
|
|
|
|
[Reactive]
|
|
|
|
|
public ViewModel NavigateBackTarget { get; set; }
|
2020-01-07 05:44:05 +00:00
|
|
|
|
public ReactiveCommand<Unit, Unit> BackCommand { get; protected set; }
|
2020-01-05 02:33:38 +00:00
|
|
|
|
|
2020-01-14 05:17:54 +00:00
|
|
|
|
private readonly ObservableAsPropertyHelper<bool> _IsActive;
|
|
|
|
|
public bool IsActive => _IsActive.Value;
|
|
|
|
|
|
2020-01-05 02:33:38 +00:00
|
|
|
|
public BackNavigatingVM(MainWindowVM mainWindowVM)
|
|
|
|
|
{
|
|
|
|
|
BackCommand = ReactiveCommand.Create(
|
2020-02-09 20:04:40 +00:00
|
|
|
|
execute: () => Utils.CatchAndLog(() =>
|
|
|
|
|
{
|
|
|
|
|
mainWindowVM.NavigateTo(NavigateBackTarget);
|
|
|
|
|
Unload();
|
|
|
|
|
}),
|
2020-01-05 03:06:34 +00:00
|
|
|
|
canExecute: this.ConstructCanNavigateBack()
|
2020-01-05 02:33:38 +00:00
|
|
|
|
.ObserveOnGuiThread());
|
2020-01-14 05:17:54 +00:00
|
|
|
|
|
2020-01-16 03:19:00 +00:00
|
|
|
|
_IsActive = this.ConstructIsActive(mainWindowVM)
|
2020-01-17 04:48:54 +00:00
|
|
|
|
.ToGuiProperty(this, nameof(IsActive));
|
2020-01-05 02:33:38 +00:00
|
|
|
|
}
|
2020-02-09 20:04:40 +00:00
|
|
|
|
|
|
|
|
|
public virtual void Unload()
|
|
|
|
|
{
|
|
|
|
|
}
|
2020-01-05 02:33:38 +00:00
|
|
|
|
}
|
2020-01-05 03:06:34 +00:00
|
|
|
|
|
|
|
|
|
public static class IBackNavigatingVMExt
|
|
|
|
|
{
|
|
|
|
|
public static IObservable<bool> ConstructCanNavigateBack(this IBackNavigatingVM vm)
|
|
|
|
|
{
|
|
|
|
|
return vm.WhenAny(x => x.NavigateBackTarget)
|
|
|
|
|
.Select(x => x != null);
|
|
|
|
|
}
|
2020-01-16 03:19:00 +00:00
|
|
|
|
|
|
|
|
|
public static IObservable<bool> ConstructIsActive(this IBackNavigatingVM vm, MainWindowVM mwvm)
|
|
|
|
|
{
|
|
|
|
|
return mwvm.WhenAny(x => x.ActivePane)
|
|
|
|
|
.Select(x => object.ReferenceEquals(vm, x));
|
|
|
|
|
}
|
2020-01-05 03:06:34 +00:00
|
|
|
|
}
|
2020-01-05 02:33:38 +00:00
|
|
|
|
}
|