Skip to content

Commit d35733f

Browse files
committed
feat: Initial implementation of FolderPicker for Gtk
chore: Update picker docs to indicate newly supported target
1 parent 2d77f9d commit d35733f

File tree

5 files changed

+59
-4
lines changed

5 files changed

+59
-4
lines changed

doc/articles/features/windows-storage-pickers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Legend
1313
|----------------|-----|-------------|---------|-----|-------|-----|-----|
1414
| FileOpenPicker || ✅ (1) ||||||
1515
| FileSavePicker || ✅ (1) ||||| 🚫 |
16-
| FolderPicker |||| ⏸️ (2)|| 🚫 | 🚫 |
16+
| FolderPicker |||| ⏸️ (2)|| 🚫 | |
1717

1818
(1) - Multiple implementations supported - see WebAssembly section below
1919
(2) - See iOS section below

src/SamplesApp/UITests.Shared/Windows_Storage/Pickers/FolderPickerTests.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace UITests.Windows_Storage.Pickers
1313
{
1414
[Sample("Windows.Storage", ViewModelType = typeof(FolderPickerTestsViewModel), IsManualTest = true,
15-
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")]
15+
Description = "Allows testing all features of FolderPicker. Currently not supported on Android, iOS, and macOS. Not selecting a folder should not cause an exception")]
1616
public sealed partial class FolderPickerTests : Page
1717
{
1818
public FolderPickerTests()

src/Uno.UI.Runtime.Skia.Gtk/Extensions/Storage/Pickers/FileOpenPickerExtension.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Linq;
7-
using System.Text;
87
using System.Threading;
98
using System.Threading.Tasks;
109
using Uno.UI.Runtime.Skia;
11-
using Windows.ApplicationModel.Resources;
1210
using Windows.Storage;
1311
using Windows.Storage.Pickers;
1412

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#nullable enable
2+
3+
using Gtk;
4+
using System;
5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
using Uno.UI.Runtime.Skia;
8+
using Windows.Storage;
9+
using Windows.Storage.Pickers;
10+
11+
namespace Uno.Extensions.Storage.Pickers
12+
{
13+
internal class FolderPickerExtension : IFolderPickerExtension
14+
{
15+
private readonly FolderPicker _picker;
16+
17+
public FolderPickerExtension(FolderPicker owner)
18+
{
19+
_picker = owner ?? throw new ArgumentNullException(nameof(owner));
20+
}
21+
22+
public async Task<StorageFolder?> PickSingleFolderAsync(CancellationToken token)
23+
{
24+
string commitText = "Select Folder";
25+
if (!string.IsNullOrWhiteSpace(_picker.CommitButtonText))
26+
{
27+
commitText = _picker.CommitButtonText;
28+
}
29+
30+
FileChooserDialog dialog = new FileChooserDialog(
31+
"Select Folder",
32+
GtkHost.Window,
33+
FileChooserAction.SelectFolder,
34+
"Cancel", ResponseType.Cancel,
35+
commitText, ResponseType.Accept);
36+
37+
dialog.SelectMultiple = false;
38+
39+
if (!_picker.FileTypeFilter.Contains("*"))
40+
{
41+
throw new ArgumentNullException();
42+
}
43+
44+
dialog.SetCurrentFolder(PickerHelpers.GetInitialDirectory(_picker.SuggestedStartLocation));
45+
46+
StorageFolder folder = null;
47+
if (dialog.Run() == (int)ResponseType.Accept)
48+
{
49+
folder = await StorageFolder.GetFolderFromPathAsync(dialog.Filename);
50+
}
51+
52+
dialog.Destroy();
53+
return folder;
54+
}
55+
}
56+
}

src/Uno.UI.Runtime.Skia.Gtk/GtkHost.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public void Run()
5858
ApiExtensibility.Register<TextBoxView>(typeof(ITextBoxViewExtension), o => new TextBoxViewExtension(o, _window));
5959
ApiExtensibility.Register(typeof(ILauncherExtension), o => new LauncherExtension(o));
6060
ApiExtensibility.Register<FileOpenPicker>(typeof(IFileOpenPickerExtension), o => new FileOpenPickerExtension(o));
61+
ApiExtensibility.Register<FolderPicker>(typeof(IFolderPickerExtension), o => new FolderPickerExtension(o));
6162

6263
_isDispatcherThread = true;
6364
_window = new Gtk.Window("Uno Host");

0 commit comments

Comments
 (0)