mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Added AbsolutePath converter to stock WPF systems. Added to FilePicker
This commit is contained in:
parent
eb2cd8342d
commit
964269de47
@ -1,11 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Windows.Data;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using Wabbajack.Common;
|
using Wabbajack.Common;
|
||||||
using Wabbajack.Lib.Downloaders;
|
|
||||||
|
|
||||||
namespace Wabbajack.Converters
|
namespace Wabbajack
|
||||||
{
|
{
|
||||||
public class PathToStringConverter : IBindingTypeConverter
|
public class AbsolutePathToStringConverter : IBindingTypeConverter, IValueConverter
|
||||||
{
|
{
|
||||||
public int GetAffinityForObjects(Type fromType, Type toType)
|
public int GetAffinityForObjects(Type fromType, Type toType)
|
||||||
{
|
{
|
||||||
@ -14,8 +15,6 @@ namespace Wabbajack.Converters
|
|||||||
if (toType == typeof(AbsolutePath)) return 1;
|
if (toType == typeof(AbsolutePath)) return 1;
|
||||||
if (toType == typeof(AbsolutePath?)) return 1;
|
if (toType == typeof(AbsolutePath?)) return 1;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryConvert(object @from, Type toType, object conversionHint, out object result)
|
public bool TryConvert(object @from, Type toType, object conversionHint, out object result)
|
||||||
@ -60,5 +59,21 @@ namespace Wabbajack.Converters
|
|||||||
result = default;
|
result = default;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
if (targetType != typeof(string))
|
||||||
|
throw new InvalidOperationException($"The target must be of type string");
|
||||||
|
if (value is AbsolutePath path)
|
||||||
|
{
|
||||||
|
return path.ToString();
|
||||||
|
}
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
return (AbsolutePath)(value as string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,7 +5,6 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using Splat;
|
using Splat;
|
||||||
using Wabbajack.Converters;
|
|
||||||
|
|
||||||
namespace Wabbajack
|
namespace Wabbajack
|
||||||
{
|
{
|
||||||
@ -26,7 +25,7 @@ namespace Wabbajack
|
|||||||
typeof(IBindingTypeConverter)
|
typeof(IBindingTypeConverter)
|
||||||
);
|
);
|
||||||
Locator.CurrentMutable.RegisterConstant(
|
Locator.CurrentMutable.RegisterConstant(
|
||||||
new PathToStringConverter(),
|
new AbsolutePathToStringConverter(),
|
||||||
typeof(IBindingTypeConverter));
|
typeof(IBindingTypeConverter));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
<local:IsNotNullVisibilityConverter x:Key="IsNotNullVisibilityConverter" />
|
<local:IsNotNullVisibilityConverter x:Key="IsNotNullVisibilityConverter" />
|
||||||
<local:EqualsToBoolConverter x:Key="EqualsToBoolConverter" />
|
<local:EqualsToBoolConverter x:Key="EqualsToBoolConverter" />
|
||||||
<local:IsTypeVisibilityConverter x:Key="IsTypeVisibilityConverter" />
|
<local:IsTypeVisibilityConverter x:Key="IsTypeVisibilityConverter" />
|
||||||
|
<local:AbsolutePathToStringConverter x:Key="AbsolutePathToStringConverter" />
|
||||||
|
|
||||||
<!-- Colors -->
|
<!-- Colors -->
|
||||||
<Color x:Key="WindowBackgroundColor">#121212</Color>
|
<Color x:Key="WindowBackgroundColor">#121212</Color>
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
Margin="5,1,-2,1"
|
Margin="5,1,-2,1"
|
||||||
VerticalContentAlignment="Center"
|
VerticalContentAlignment="Center"
|
||||||
Background="{StaticResource DarkBackgroundBrush}"
|
Background="{StaticResource DarkBackgroundBrush}"
|
||||||
Text="{Binding PickerVM.TargetPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
|
Text="{Binding PickerVM.TargetPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource AbsolutePathToStringConverter}}"
|
||||||
Visibility="{Binding PickerVM.ShowTextBoxInput, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
|
Visibility="{Binding PickerVM.ShowTextBoxInput, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
|
||||||
<Grid Grid.Column="1" HorizontalAlignment="Right">
|
<Grid Grid.Column="1" HorizontalAlignment="Right">
|
||||||
<Border
|
<Border
|
||||||
|
@ -7,7 +7,7 @@ namespace Wabbajack
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interaction logic for FilePicker.xaml
|
/// Interaction logic for FilePicker.xaml
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class FilePicker : UserControl
|
public partial class FilePicker
|
||||||
{
|
{
|
||||||
// This exists, as utilizing the datacontext directly seemed to bug out the exit animations
|
// This exists, as utilizing the datacontext directly seemed to bug out the exit animations
|
||||||
// "Bouncing" off this property seems to fix it, though. Could perhaps be done other ways.
|
// "Bouncing" off this property seems to fix it, though. Could perhaps be done other ways.
|
||||||
|
Loading…
Reference in New Issue
Block a user