🐛 FilePicker2

This commit is contained in:
Aigio Liu
2023-08-28 22:14:21 +08:00
parent f76005378c
commit bb2bb9fc26
6 changed files with 34 additions and 16 deletions
@@ -25,7 +25,13 @@ sealed class AvaloniaFilePickerPlatformService : BaseService, IServiceBase, IOpe
UTType.PNG, UTType.JPEG, "jpeg",
});
#else
FilePickerFileType.Parse(FileEx.Images);
FilePickerFileType.Parse(new[] {
FileEx.WebP,
FileEx.Png,
FileEx.JPG,
FileEx.JPEG,
//FileEx.Gif,
});
#endif
IFilePickerFileType IInternalFilePickerPlatformService.Png => FilePickerFileType.Parse(new string[] {
@@ -80,6 +86,22 @@ sealed class AvaloniaFilePickerPlatformService : BaseService, IServiceBase, IOpe
{
#if IOS || MACOS || MACCATALYST
AppleUniformTypeIdentifiers = extensions?.ToArray(),
#elif WINDOWS
Patterns = extensions?.Select(x =>
{
if (x.StartsWith('.'))
{
return $"*{x}";
}
else if (x.StartsWith('*'))
{
return x;
}
else
{
return $"*.{x}";
}
}).ToArray(),
#else
Patterns = IServiceBase.FormatExtensions(extensions, trimLeadingPeriod: true).ToArray(),
#endif
@@ -74,7 +74,7 @@ public sealed class CustomFilePicker : ContentControl
this.Tapped += CustomFilePicker_Tapped;
}
private async void CustomFilePicker_Tapped(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
private async void CustomFilePicker_Tapped(object? sender, RoutedEventArgs e)
{
//if (string.IsNullOrEmpty(FileExtensions) || FileExtensions == "*")
//{
@@ -41,11 +41,6 @@ public sealed partial class PlatformAccount
SetAccountAvatarCommand = ReactiveCommand.Create<IAccount>(async acc =>
{
FilePickerFileType fileTypes = new ValueTuple<string, string[]>[]
{
("Image Files", FileEx.Images.Select(s => $"*{s}").ToArray()),
};
await FilePicker2.PickAsync((path) =>
{
if (!string.IsNullOrEmpty(path) && !string.IsNullOrEmpty(acc.AccountName))
@@ -54,7 +49,7 @@ public sealed partial class PlatformAccount
File.Copy(path, imagePath, true);
acc.ImagePath = imagePath;
}
}, fileTypes);
}, IFilePickerFileType.Images());
});
EditRemarkCommand = ReactiveCommand.Create<IAccount>(async acc =>
{
@@ -41,12 +41,13 @@ public sealed partial class SettingsPageViewModel : TabItemViewModel
SelectImage_Click = ReactiveCommand.CreateFromTask(async () =>
{
FilePickerFileType fileTypes = new ValueTuple<string, string[]>[]
{
("Image Files", FileEx.Images.Select(s => $"*{s}").ToArray()),
//("All Files", new[] { "*", }),
};
await FilePicker2.PickAsync(SetBackgroundImagePath, fileTypes);
//FilePickerFileType fileTypes = new ValueTuple<string, string[]>[]
//{
// ("Image Files", FileEx.Images.Select(s => $"*{s}").ToArray()),
// //("All Files", new[] { "*", }),
//};
//await FilePicker2.PickAsync(SetBackgroundImagePath, fileTypes);
await FilePicker2.PickAsync(SetBackgroundImagePath, IFilePickerFileType.Images());
});
ResetImage_Click = ReactiveCommand.Create(() => SetBackgroundImagePath(null));