diff --git a/doc/articles/features/windows-storage-pickers.md b/doc/articles/features/windows-storage-pickers.md index 10afb4f09f69..3d68c0550c66 100644 --- a/doc/articles/features/windows-storage-pickers.md +++ b/doc/articles/features/windows-storage-pickers.md @@ -13,7 +13,7 @@ Legend |----------------|-----|-------------|---------|-----|-------|-----|-----| | FileOpenPicker | ✅ | ✅ (1) | ✅ | ✅ | ✅ | ✅ | ✅ | | FileSavePicker | ✅ | ✅ (1) | ✅ | ✅ | ✅ | ✅ | 🚫 | -| FolderPicker | ✅ | ✅ | ✅ | ⏸️ (2)|✅ | 🚫 | 🚫 | +| FolderPicker | ✅ | ✅ | ✅ | ⏸️ (2)|✅ | 🚫 | ✅ | (1) - Multiple implementations supported - see WebAssembly section below (2) - See iOS section below diff --git a/src/SamplesApp/UITests.Shared/Windows_Storage/Pickers/FolderPickerTests.xaml.cs b/src/SamplesApp/UITests.Shared/Windows_Storage/Pickers/FolderPickerTests.xaml.cs index 8eb7857c29f2..e6643685eebb 100644 --- a/src/SamplesApp/UITests.Shared/Windows_Storage/Pickers/FolderPickerTests.xaml.cs +++ b/src/SamplesApp/UITests.Shared/Windows_Storage/Pickers/FolderPickerTests.xaml.cs @@ -12,7 +12,7 @@ namespace UITests.Windows_Storage.Pickers { [Sample("Windows.Storage", ViewModelType = typeof(FolderPickerTestsViewModel), IsManualTest = true, - Description = "Allows testing all features of FolderPicker. Currently not supported on Android, iOS, macOS and GTK. Not selecting a folder should not cause an exception")] + Description = "Allows testing all features of FolderPicker. Currently not supported on Android, iOS, and macOS. Not selecting a folder should not cause an exception")] public sealed partial class FolderPickerTests : Page { public FolderPickerTests() diff --git a/src/Uno.UI.Runtime.Skia.Gtk/Extensions/Storage/Pickers/FileOpenPickerExtension.cs b/src/Uno.UI.Runtime.Skia.Gtk/Extensions/Storage/Pickers/FileOpenPickerExtension.cs index 784d573e9887..80d10b0e469d 100644 --- a/src/Uno.UI.Runtime.Skia.Gtk/Extensions/Storage/Pickers/FileOpenPickerExtension.cs +++ b/src/Uno.UI.Runtime.Skia.Gtk/Extensions/Storage/Pickers/FileOpenPickerExtension.cs @@ -4,11 +4,9 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; using Uno.UI.Runtime.Skia; -using Windows.ApplicationModel.Resources; using Windows.Storage; using Windows.Storage.Pickers; diff --git a/src/Uno.UI.Runtime.Skia.Gtk/Extensions/Storage/Pickers/FolderPickerExtension.cs b/src/Uno.UI.Runtime.Skia.Gtk/Extensions/Storage/Pickers/FolderPickerExtension.cs new file mode 100644 index 000000000000..60267913fed9 --- /dev/null +++ b/src/Uno.UI.Runtime.Skia.Gtk/Extensions/Storage/Pickers/FolderPickerExtension.cs @@ -0,0 +1,56 @@ +#nullable enable + +using Gtk; +using System; +using System.Threading; +using System.Threading.Tasks; +using Uno.UI.Runtime.Skia; +using Windows.Storage; +using Windows.Storage.Pickers; + +namespace Uno.Extensions.Storage.Pickers +{ + internal class FolderPickerExtension : IFolderPickerExtension + { + private readonly FolderPicker _picker; + + public FolderPickerExtension(FolderPicker owner) + { + _picker = owner ?? throw new ArgumentNullException(nameof(owner)); + } + + public async Task PickSingleFolderAsync(CancellationToken token) + { + string commitText = "Select Folder"; + if (!string.IsNullOrWhiteSpace(_picker.CommitButtonText)) + { + commitText = _picker.CommitButtonText; + } + + FileChooserDialog dialog = new FileChooserDialog( + "Select Folder", + GtkHost.Window, + FileChooserAction.SelectFolder, + "Cancel", ResponseType.Cancel, + commitText, ResponseType.Accept); + + dialog.SelectMultiple = false; + + if (!_picker.FileTypeFilter.Contains("*")) + { + throw new ArgumentNullException(); + } + + dialog.SetCurrentFolder(PickerHelpers.GetInitialDirectory(_picker.SuggestedStartLocation)); + + StorageFolder folder = null; + if (dialog.Run() == (int)ResponseType.Accept) + { + folder = await StorageFolder.GetFolderFromPathAsync(dialog.Filename); + } + + dialog.Destroy(); + return folder; + } + } +} diff --git a/src/Uno.UI.Runtime.Skia.Gtk/GtkHost.cs b/src/Uno.UI.Runtime.Skia.Gtk/GtkHost.cs index ebcd2605735f..34d54d4fbc69 100644 --- a/src/Uno.UI.Runtime.Skia.Gtk/GtkHost.cs +++ b/src/Uno.UI.Runtime.Skia.Gtk/GtkHost.cs @@ -58,6 +58,7 @@ public void Run() ApiExtensibility.Register(typeof(ITextBoxViewExtension), o => new TextBoxViewExtension(o, _window)); ApiExtensibility.Register(typeof(ILauncherExtension), o => new LauncherExtension(o)); ApiExtensibility.Register(typeof(IFileOpenPickerExtension), o => new FileOpenPickerExtension(o)); + ApiExtensibility.Register(typeof(IFolderPickerExtension), o => new FolderPickerExtension(o)); _isDispatcherThread = true; _window = new Gtk.Window("Uno Host");