mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
FilePicker.AdditionalError systems
Lets you specify when there's other problems besides the file not existing
This commit is contained in:
@ -29,8 +29,8 @@
|
|||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Foreground="{StaticResource WarningBrush}"
|
Foreground="{StaticResource WarningBrush}"
|
||||||
Kind="Circle"
|
Kind="Circle"
|
||||||
ToolTip="Path does not exist"
|
ToolTip="{Binding ErrorTooltip, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
|
||||||
Visibility="{Binding Exists, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource bool2VisibilityConverter}, ConverterParameter=False}" />
|
Visibility="{Binding InError, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource bool2VisibilityConverter}}" />
|
||||||
<Button
|
<Button
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
Command="{Binding SetTargetPathCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
|
Command="{Binding SetTargetPathCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
|
||||||
|
@ -97,6 +97,20 @@ namespace Wabbajack
|
|||||||
public static readonly DependencyProperty FilterProperty = DependencyProperty.Register(nameof(Filter), typeof(string), typeof(FilePicker),
|
public static readonly DependencyProperty FilterProperty = DependencyProperty.Register(nameof(Filter), typeof(string), typeof(FilePicker),
|
||||||
new FrameworkPropertyMetadata(default(string)));
|
new FrameworkPropertyMetadata(default(string)));
|
||||||
|
|
||||||
|
public IErrorResponse AdditionalError
|
||||||
|
{
|
||||||
|
get => (IErrorResponse)GetValue(AdditionalErrorProperty);
|
||||||
|
set => SetValue(AdditionalErrorProperty, value);
|
||||||
|
}
|
||||||
|
public static readonly DependencyProperty AdditionalErrorProperty = DependencyProperty.Register(nameof(AdditionalError), typeof(IErrorResponse), typeof(FilePicker),
|
||||||
|
new FrameworkPropertyMetadata(default(IErrorResponse), WireNotifyPropertyChanged));
|
||||||
|
|
||||||
|
private readonly ObservableAsPropertyHelper<bool> _InError;
|
||||||
|
public bool InError => _InError.Value;
|
||||||
|
|
||||||
|
private readonly ObservableAsPropertyHelper<string> _ErrorTooltip;
|
||||||
|
public string ErrorTooltip => _ErrorTooltip.Value;
|
||||||
|
|
||||||
public FilePicker()
|
public FilePicker()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -175,6 +189,28 @@ namespace Wabbajack
|
|||||||
.ObserveOn(RxApp.MainThreadScheduler)
|
.ObserveOn(RxApp.MainThreadScheduler)
|
||||||
.Subscribe(exists => this.Exists = exists)
|
.Subscribe(exists => this.Exists = exists)
|
||||||
.DisposeWith(this.CompositeDisposable);
|
.DisposeWith(this.CompositeDisposable);
|
||||||
|
|
||||||
|
this._InError = Observable.CombineLatest(
|
||||||
|
this.WhenAny(x => x.Exists),
|
||||||
|
this.WhenAny(x => x.AdditionalError)
|
||||||
|
.Select(err => !err?.Succeeded ?? true),
|
||||||
|
resultSelector: (exist, err) => !exist || err)
|
||||||
|
.ToProperty(this, nameof(this.InError));
|
||||||
|
|
||||||
|
this._ErrorTooltip = Observable.CombineLatest(
|
||||||
|
this.WhenAny(x => x.Exists)
|
||||||
|
.Select(exists => exists ? default(string) : "Path does not exist"),
|
||||||
|
this.WhenAny(x => x.AdditionalError),
|
||||||
|
resultSelector: (exists, err) =>
|
||||||
|
{
|
||||||
|
if ((!err?.Succeeded ?? false)
|
||||||
|
&& !string.IsNullOrWhiteSpace(err.Reason))
|
||||||
|
{
|
||||||
|
return err.Reason;
|
||||||
|
}
|
||||||
|
return exists;
|
||||||
|
})
|
||||||
|
.ToProperty(this, nameof(this.ErrorTooltip));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user