Skip to content
3 changes: 3 additions & 0 deletions build/PackageDiffIgnore.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3326,6 +3326,9 @@
<Member
fullName="System.Void Windows.UI.Xaml.Media.ImageSource..ctor(System.IO.Stream stream)"
reason="Not part of the UWP API"/>
<Member
fullName="System.Void Windows.Storage.Pickers.FileSavePicker.set_FileTypeChoices(System.Collections.Generic.IDictionary`2&lt;System.String,System.Collections.Generic.IList`1&lt;System.String&gt;&gt; value)"
reason="Not part of the UWP API"/>
</Methods>
</IgnoreSet>

Expand Down
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 FileSavePicker
{
#if __ANDROID__ || __IOS__ || NET461 || false || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
#if __ANDROID__ || __IOS__ || NET461 || false || __SKIA__ || __NETSTD_REFERENCE__ || false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__SKIA__", "__NETSTD_REFERENCE__")]
public global::Windows.Storage.Pickers.PickerLocationId SuggestedStartLocation
{
get
Expand Down Expand Up @@ -140,7 +140,7 @@ public string EnterpriseId
}
#endif

#if __ANDROID__ || __IOS__ || NET461 || false || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if __ANDROID__ || __IOS__ || NET461 || false || __SKIA__ || __NETSTD_REFERENCE__ || false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public FileSavePicker()
{
Expand Down Expand Up @@ -173,7 +173,7 @@ public void PickSaveFileAndContinue()
// Forced skipping of method Windows.Storage.Pickers.FileSavePicker.SuggestedFileName.get
// Forced skipping of method Windows.Storage.Pickers.FileSavePicker.SuggestedFileName.set

#if __ANDROID__ || __IOS__ || NET461 || false || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if __ANDROID__ || __IOS__ || NET461 || false || __SKIA__ || __NETSTD_REFERENCE__ || false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::Windows.Foundation.IAsyncOperation<global::Windows.Storage.StorageFile> PickSaveFileAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ public enum PickerLocationId
#endif
}
#endif
}
}
2 changes: 1 addition & 1 deletion src/Uno.UWP/Storage/Pickers/FileSavePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public partial class FileSavePicker

public string CommitButtonText { get; set; }

public IDictionary<string, IList<string>> FileTypeChoices { get; set; }
public IDictionary<string, IList<string>> FileTypeChoices { get; private set; } = new Dictionary<string, IList<string>>();
}
}
52 changes: 52 additions & 0 deletions src/Uno.UWP/Storage/Pickers/FileSavePicker.macOS.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using AppKit;
using Foundation;
using Windows.Foundation;

namespace Windows.Storage.Pickers
{
public partial class FileSavePicker
{
public PickerLocationId SuggestedStartLocation { get; set; }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SuggestedStartLocation should be shared by all implementations. Please move to FileSavePicker.cs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robloo Thanks not exactly the case here, as it is defined as not implemented in the generated APIs file. If this members ends up being implemented by all platforms, then it'll have to be moved.

@robloo robloo Oct 5, 2020 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, ok. I assumed it would be implemented on all as it is an enum property (and this PR adds the enum). Shouldn't we just flag it as implemented for all platforms at once? Of course the value can be ignored on a per platform basis.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably have some clearer directives on such implementations, but for now, properties have more weight than enum values (as enums could be used in different classes). Marking a property implemented just for the platform makes sense here, as it is only used for two platforms (and it's only an autoproperty).

public IAsyncOperation<StorageFile> PickSaveFileAsync() => PickFileTaskAsync().AsAsyncOperation();


private async Task<StorageFile> PickFileTaskAsync()
{
var savePicker = new NSSavePanel();
savePicker.DirectoryUrl = new NSUrl(GetStartPath(), true);
savePicker.AllowedFileTypes = GetFileTypes();
if (SuggestedFileName != null)
{
savePicker.NameFieldStringValue = SuggestedFileName;
}
if (savePicker.RunModal() == 1)
{
return await StorageFile.GetFileFromPathAsync(savePicker.Url.Path);
}
else
{
return null;
}
}

private string GetStartPath()
{
var specialFolder = SuggestedStartLocation switch
{
PickerLocationId.DocumentsLibrary => NSSearchPathDirectory.DocumentDirectory,
PickerLocationId.Desktop => NSSearchPathDirectory.DesktopDirectory,
PickerLocationId.MusicLibrary => NSSearchPathDirectory.MusicDirectory,
PickerLocationId.PicturesLibrary => NSSearchPathDirectory.PicturesDirectory,
PickerLocationId.VideosLibrary => NSSearchPathDirectory.MoviesDirectory,
_ => NSSearchPathDirectory.UserDirectory
};

return NSFileManager.DefaultManager.GetUrls(specialFolder, NSSearchPathDomain.User)[0].AbsoluteString;
}

private string[] GetFileTypes() => FileTypeChoices.SelectMany(x => x.Value.Select(val => val.TrimStart(new[] { '.' }))).ToArray();
}
}
32 changes: 16 additions & 16 deletions src/Uno.UWP/Storage/Pickers/PickerLocationId.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
namespace Windows.Storage.Pickers
{
public enum PickerLocationId
{
DocumentsLibrary,
ComputerFolder,
Desktop,
Downloads,
HomeGroup,
MusicLibrary,
PicturesLibrary,
VideosLibrary,
Objects3D,
Unspecified,
}
}
namespace Windows.Storage.Pickers
{
public enum PickerLocationId
{
DocumentsLibrary,
ComputerFolder,
Desktop,
Downloads,
HomeGroup,
MusicLibrary,
PicturesLibrary,
VideosLibrary,
Objects3D,
Unspecified,
}
}