Add FolderProvider
This commit is contained in:
@@ -11,21 +11,21 @@ public class FileProvider(ITopLevelProvider topLevelProvider) :
|
||||
{
|
||||
if (topLevelProvider.Get() is TopLevel topLevel)
|
||||
{
|
||||
IReadOnlyList<IStorageFile> storageFiles = await topLevel.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions()
|
||||
IReadOnlyList<IStorageFile> files = await topLevel.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions()
|
||||
{
|
||||
AllowMultiple = filter.AllowMultiple,
|
||||
FileTypeFilter = new List<FilePickerFileType>
|
||||
{
|
||||
FileTypeFilter =
|
||||
[
|
||||
new(filter.Name)
|
||||
{
|
||||
Patterns = filter.Extensions is { Count: > 0 } ? filter.Extensions.Select(x => $"*.{x}").ToList() : ["*.*"]
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
return storageFiles.Select(file => file.Path.LocalPath).ToList();
|
||||
return files.Select(x => x.Path.LocalPath).ToList();
|
||||
}
|
||||
|
||||
return Array.Empty<string>();
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Platform.Storage;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Toolkit.Avalonia;
|
||||
|
||||
public class FolderProvider(ITopLevelProvider topLevelProvider) :
|
||||
IFolderProvider
|
||||
{
|
||||
public async Task<IReadOnlyCollection<string>> SelectFolders(FolderFilter filter)
|
||||
{
|
||||
if (topLevelProvider.Get() is TopLevel topLevel)
|
||||
{
|
||||
IReadOnlyList<IStorageFolder> folders = await topLevel.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions()
|
||||
{
|
||||
AllowMultiple = filter.AllowMultiple
|
||||
});
|
||||
|
||||
|
||||
return folders.Select(x => x.Path.LocalPath).ToList();
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -126,6 +126,7 @@ public static class IServiceCollectionExtensions
|
||||
{
|
||||
services.AddTransient<ITopLevelProvider, TopLevelProvider>();
|
||||
services.AddTransient<IFileProvider, FileProvider>();
|
||||
services.AddTransient<IFolderProvider, FolderProvider>();
|
||||
|
||||
services.AddTransient<IClipboardWriter, ClipboardWriter>();
|
||||
|
||||
@@ -139,6 +140,7 @@ public static class IServiceCollectionExtensions
|
||||
services.AddTransient<INavigationRegion, NavigationRegion>();
|
||||
|
||||
services.AddHandler<WriteClipboardHandler>();
|
||||
services.AddHandler<SelectFoldersHandler>();
|
||||
|
||||
services.AddHandler<ClassicDesktopStyleApplicationHandler>(nameof(IClassicDesktopStyleApplicationLifetime));
|
||||
services.AddHandler<SingleViewApplicationHandler>(nameof(ISingleViewApplicationLifetime));
|
||||
@@ -157,6 +159,7 @@ public static class IServiceCollectionExtensions
|
||||
{
|
||||
services.AddTransient<ITopLevelProvider, TopLevelProvider>();
|
||||
services.AddTransient<IFileProvider, FileProvider>();
|
||||
services.AddTransient<IFolderProvider, FolderProvider>();
|
||||
|
||||
services.AddTransient<IClipboardWriter, ClipboardWriter>();
|
||||
|
||||
@@ -170,6 +173,7 @@ public static class IServiceCollectionExtensions
|
||||
services.AddTransient<INavigationRegion, NavigationRegion>();
|
||||
|
||||
services.AddHandler<WriteClipboardHandler>();
|
||||
services.AddHandler<SelectFoldersHandler>();
|
||||
|
||||
services.AddHandler<ContentControlHandler>(nameof(ContentControl));
|
||||
services.AddHandler<FrameHandler>(nameof(Frame));
|
||||
|
||||
Reference in New Issue
Block a user