forked from unoplatform/uno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Initial implementation of FolderPicker for Gtk
chore: Update picker docs to indicate newly supported target
- Loading branch information
1 parent
2d77f9d
commit d35733f
Showing
5 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/Uno.UI.Runtime.Skia.Gtk/Extensions/Storage/Pickers/FolderPickerExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters