Skip to content

Commit

Permalink
feat: Initial implementation of FolderPicker for Gtk
Browse files Browse the repository at this point in the history
chore: Update picker docs to indicate newly supported target
  • Loading branch information
lukeblevins committed Jun 15, 2021
1 parent 2d77f9d commit d35733f
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
2 changes: 1 addition & 1 deletion doc/articles/features/windows-storage-pickers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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<StorageFolder?> 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;
}
}
}
1 change: 1 addition & 0 deletions src/Uno.UI.Runtime.Skia.Gtk/GtkHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public void Run()
ApiExtensibility.Register<TextBoxView>(typeof(ITextBoxViewExtension), o => new TextBoxViewExtension(o, _window));
ApiExtensibility.Register(typeof(ILauncherExtension), o => new LauncherExtension(o));
ApiExtensibility.Register<FileOpenPicker>(typeof(IFileOpenPickerExtension), o => new FileOpenPickerExtension(o));
ApiExtensibility.Register<FolderPicker>(typeof(IFolderPickerExtension), o => new FolderPickerExtension(o));

_isDispatcherThread = true;
_window = new Gtk.Window("Uno Host");
Expand Down

0 comments on commit d35733f

Please sign in to comment.