Implemented IBackNavigatingVM various places

This commit is contained in:
Justin Swanson 2020-01-04 21:06:34 -06:00
parent 907a5a2da1
commit 43aca88879
6 changed files with 48 additions and 18 deletions

View File

@ -12,19 +12,33 @@ using Wabbajack.Lib;
namespace Wabbajack
{
public class BackNavigatingVM : ViewModel
public interface IBackNavigatingVM : IReactiveObject
{
ViewModel NavigateBackTarget { get; set; }
IReactiveCommand BackCommand { get; }
}
public class BackNavigatingVM : ViewModel, IBackNavigatingVM
{
[Reactive]
public ViewModel NavigateBackTarget { get; set; }
public ICommand BackCommand { get; }
public IReactiveCommand BackCommand { get; protected set; }
public BackNavigatingVM(MainWindowVM mainWindowVM)
{
BackCommand = ReactiveCommand.Create(
execute: () => Utils.CatchAndLog(() => mainWindowVM.NavigateTo(NavigateBackTarget)),
canExecute: this.WhenAny(x => x.NavigateBackTarget)
.Select(x => x != null)
canExecute: this.ConstructCanNavigateBack()
.ObserveOnGuiThread());
}
}
public static class IBackNavigatingVMExt
{
public static IObservable<bool> ConstructCanNavigateBack(this IBackNavigatingVM vm)
{
return vm.WhenAny(x => x.NavigateBackTarget)
.Select(x => x != null);
}
}
}

View File

@ -18,13 +18,16 @@ using Wabbajack.Lib;
namespace Wabbajack
{
public class CompilerVM : ViewModel
public class CompilerVM : ViewModel, IBackNavigatingVM
{
public MainWindowVM MWVM { get; }
private readonly ObservableAsPropertyHelper<BitmapImage> _image;
public BitmapImage Image => _image.Value;
[Reactive]
public ViewModel NavigateBackTarget { get; set; }
[Reactive]
public ModManager SelectedCompilerType { get; set; }
@ -143,8 +146,12 @@ namespace Wabbajack
StartedCompilation = false;
Completed = null;
},
canExecute: this.WhenAny(x => x.Compiling)
.Select(x => !x));
canExecute: Observable.CombineLatest(
this.WhenAny(x => x.Compiling)
.Select(x => !x),
this.ConstructCanNavigateBack(),
resultSelector: (i, b) => i && b)
.ObserveOnGuiThread());
// Compile progress updates and populate ObservableCollection
Dictionary<int, CPUDisplayVM> cpuDisplays = new Dictionary<int, CPUDisplayVM>();

View File

@ -20,10 +20,11 @@ using DynamicData.Binding;
using Wabbajack.Common.StatusFeed;
using System.Reactive;
using System.Collections.Generic;
using System.Windows.Input;
namespace Wabbajack
{
public class InstallerVM : ViewModel
public class InstallerVM : ViewModel, IBackNavigatingVM
{
public SlideShow Slideshow { get; }
@ -37,6 +38,9 @@ namespace Wabbajack
public FilePickerVM ModListLocation { get; }
[Reactive]
public ViewModel NavigateBackTarget { get; set; }
private readonly ObservableAsPropertyHelper<ISubInstallerVM> _installer;
public ISubInstallerVM Installer => _installer.Value;
@ -184,8 +188,12 @@ namespace Wabbajack
Completed = null;
mainWindowVM.NavigateTo(mainWindowVM.ModeSelectionVM);
},
canExecute: this.WhenAny(x => x.Installing)
.Select(x => !x));
canExecute: Observable.CombineLatest(
this.WhenAny(x => x.Installing)
.Select(x => !x),
this.ConstructCanNavigateBack(),
resultSelector: (i, b) => i && b)
.ObserveOnGuiThread());
_percentCompleted = this.WhenAny(x => x.Installer.ActiveInstallation)
.StartWith(default(AInstaller))

View File

@ -1,4 +1,4 @@
using DynamicData;
using DynamicData;
using DynamicData.Binding;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
@ -43,7 +43,6 @@ namespace Wabbajack
public ICommand CopyVersionCommand { get; }
public ICommand ShowLoginManagerVM { get; }
public ICommand GoBackCommand { get; }
public string VersionDisplay { get; }
public MainWindowVM(MainWindow mainWindow, MainSettings settings)
@ -153,7 +152,8 @@ namespace Wabbajack
ActivePane = vm;
}
public void NavigateTo(BackNavigatingVM vm)
public void NavigateTo<T>(T vm)
where T : ViewModel, IBackNavigatingVM
{
vm.NavigateBackTarget = ActivePane;
ActivePane = vm;

View File

@ -15,22 +15,20 @@ using Wabbajack.Lib.ModListRegistry;
namespace Wabbajack
{
public class ModListGalleryVM : ViewModel
public class ModListGalleryVM : BackNavigatingVM
{
public MainWindowVM MWVM { get; }
public ObservableCollectionExtended<ModListMetadataVM> ModLists { get; } = new ObservableCollectionExtended<ModListMetadataVM>();
public IReactiveCommand BackCommand { get; }
public IReactiveCommand RefreshCommand { get; }
private int missingHashFallbackCounter;
public ModListGalleryVM(MainWindowVM mainWindowVM)
: base(mainWindowVM)
{
MWVM = mainWindowVM;
BackCommand = ReactiveCommand.Create(
execute: () => mainWindowVM.NavigateTo(mainWindowVM.ModeSelectionVM));
RefreshCommand = ReactiveCommand.Create(() => { });
RefreshCommand.StartingExecution()

View File

@ -13,7 +13,7 @@ using Wabbajack.Lib.WebAutomation;
namespace Wabbajack
{
public class WebBrowserVM : ViewModel
public class WebBrowserVM : ViewModel, IBackNavigatingVM
{
[Reactive]
public string Instructions { get; set; }
@ -21,6 +21,9 @@ namespace Wabbajack
public IWebBrowser Browser { get; } = new ChromiumWebBrowser();
public CefSharpWrapper Driver => new CefSharpWrapper(Browser);
[Reactive]
public ViewModel NavigateBackTarget { get; set; }
[Reactive]
public IReactiveCommand BackCommand { get; set; }