ModListMetadataVM FlowSwitch on exists check

This commit is contained in:
Justin Swanson 2020-01-13 23:17:54 -06:00
parent bc6580c846
commit 8ae8e28f67
6 changed files with 14 additions and 6 deletions

View File

@ -40,7 +40,7 @@ namespace Wabbajack
/// <param name="source">Source observable to subscribe to if on</param>
/// <param name="filterSwitch">On/Off signal of whether to subscribe to source observable</param>
/// <returns>Observable that publishes data from source, if the switch is on.</returns>
public static IObservable<T> FilterSwitch<T>(this IObservable<T> source, IObservable<bool> filterSwitch)
public static IObservable<T> FlowSwitch<T>(this IObservable<T> source, IObservable<bool> filterSwitch)
{
return filterSwitch
.DistinctUntilChanged()
@ -211,7 +211,7 @@ namespace Wabbajack
public static IObservable<T> DelayInitial<T>(this IObservable<T> source, TimeSpan delay)
{
return source.FilterSwitch(
return source.FlowSwitch(
Observable.Return(System.Reactive.Unit.Default)
.Delay(delay)
.Select(_ => true)
@ -220,7 +220,7 @@ namespace Wabbajack
public static IObservable<T> DelayInitial<T>(this IObservable<T> source, TimeSpan delay, IScheduler scheduler)
{
return source.FilterSwitch(
return source.FlowSwitch(
Observable.Return(System.Reactive.Unit.Default)
.Delay(delay, scheduler)
.Select(_ => true)

View File

@ -109,7 +109,7 @@ namespace Wabbajack
_exists = Observable.Interval(TimeSpan.FromSeconds(3), RxApp.TaskpoolScheduler)
// Only check exists on timer if desired
.FilterSwitch(doExistsCheck)
.FlowSwitch(doExistsCheck)
.Unit()
// Also check though, when fields change
.Merge(this.WhenAny(x => x.PathType).Unit())

View File

@ -25,12 +25,19 @@ namespace Wabbajack
public ViewModel NavigateBackTarget { get; set; }
public ReactiveCommand<Unit, Unit> BackCommand { get; protected set; }
private readonly ObservableAsPropertyHelper<bool> _IsActive;
public bool IsActive => _IsActive.Value;
public BackNavigatingVM(MainWindowVM mainWindowVM)
{
BackCommand = ReactiveCommand.Create(
execute: () => Utils.CatchAndLog(() => mainWindowVM.NavigateTo(NavigateBackTarget)),
canExecute: this.ConstructCanNavigateBack()
.ObserveOnGuiThread());
_IsActive = mainWindowVM.WhenAny(x => x.ActivePane)
.Select(x => object.ReferenceEquals(this, x))
.ToProperty(this, nameof(IsActive));
}
}

View File

@ -146,7 +146,7 @@ namespace Wabbajack
(this).WhenAny(x => x.Mo2Folder)
.DelayInitial(TimeSpan.FromMilliseconds(100))
.Where(x => Directory.Exists(x))
.FilterSwitch(
.FlowSwitch(
(this).WhenAny(x => x.DownloadLocation.Exists)
.Invert())
// A skip is needed to ignore the initial signal when the FilterSwitch turns on

View File

@ -107,6 +107,7 @@ namespace Wabbajack
_Exists = Observable.Interval(TimeSpan.FromSeconds(0.5))
.Unit()
.StartWith(Unit.Default)
.FlowSwitch(_parent.WhenAny(x => x.IsActive))
.Select(_ =>
{
try

View File

@ -60,7 +60,7 @@ namespace Wabbajack
// When filter switch enabled, fire an initial signal
.StartWith(Unit.Default)
// Only subscribe to slideshow triggers if enabled and installing
.FilterSwitch(
.FlowSwitch(
Observable.CombineLatest(
this.WhenAny(x => x.Enable),
this.WhenAny(x => x.Installer.Installing),