Skip to content

Commit

Permalink
feat: FolderPicker on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Aug 19, 2020
1 parent f76368f commit ea28b8d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#pragma warning disable 114 // new keyword hiding
namespace Windows.Storage.Pickers
{
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || false
[global::Uno.NotImplemented]
#endif
public partial class FolderPicker
{
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__")]
public global::Windows.Storage.Pickers.PickerViewMode ViewMode
{
get
Expand Down Expand Up @@ -93,8 +93,8 @@ public string CommitButtonText
}
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__")]
public FolderPicker()
{
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.Storage.Pickers.FolderPicker", "FolderPicker.FolderPicker()");
Expand All @@ -118,8 +118,8 @@ public void PickFolderAndContinue()
// Forced skipping of method Windows.Storage.Pickers.FolderPicker.CommitButtonText.get
// Forced skipping of method Windows.Storage.Pickers.FolderPicker.CommitButtonText.set
// Forced skipping of method Windows.Storage.Pickers.FolderPicker.FileTypeFilter.get
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__")]
public global::Windows.Foundation.IAsyncOperation<global::Windows.Storage.StorageFolder> PickSingleFolderAsync()
{
throw new global::System.NotImplementedException("The member IAsyncOperation<StorageFolder> FolderPicker.PickSingleFolderAsync() is not implemented in Uno.");
Expand Down
38 changes: 38 additions & 0 deletions src/Uno.UWP/Storage/Pickers/FolderPicker.macOS.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#if __MACOS__
using System;
using System.Threading.Tasks;
using AppKit;
using Windows.Foundation;

namespace Windows.Storage.Pickers
{
public partial class FolderPicker
{
public FolderPicker()
{
}

public IAsyncOperation<StorageFolder> PickSingleFolderAsync() =>
PickSingleFolderImplAsync().AsAsyncOperation();

private async Task<StorageFolder> PickSingleFolderImplAsync()
{
var openPanel = new NSOpenPanel();
openPanel.AllowedFileTypes = new[] { "none" };
openPanel.AllowsOtherFileTypes = false;
openPanel.CanChooseDirectories = true;
openPanel.CanChooseFiles = false;
var response = openPanel.RunModal();
if (response == 1 && openPanel.Urls.Length > 0)
{
var path = openPanel.Urls[0]?.Path;
if (path != null)
{
return new StorageFolder(path);
}
}
return null;
}
}
}
#endif

0 comments on commit ea28b8d

Please sign in to comment.