Repository navigation
feat: Implemented FileSavePicker on MacOS #4215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mergify
merged 9 commits into
unoplatform:master
from
snickler:dev/snickler/FileSavePickerMacOS
Nov 30, 2020
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a7b8e80
feat: Implemented FileSavePicker on MacOS
snickler cfecbe8
feat: Implemented FileSavePicker on MacOS
snickler 88114f5
fix: Re-added setter to FileTypeChoices
snickler 0e01a64
Merge branch 'master' into dev/snickler/FileSavePickerMacOS
snickler 779a1f2
fix: Use NSFileManager for proper folder paths
snickler 3a381c5
fix: FileTypeChoices prop to use a private setter
snickler f64fd65
fix: Added FileTypeChoices setter to PackageDiffIgnore
snickler 2da43f2
Merge remote-tracking branch 'upstream/master' into dev/snickler/File…
snickler 7e95c85
fix: Add proper encoding to lt/gt characters in PackageDiffIgnore
snickler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -40,4 +40,4 @@ public enum PickerLocationId | |
| #endif | ||
| } | ||
| #endif | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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,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; } | ||
| 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(); | ||
| } | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -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, | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SuggestedStartLocationshould be shared by all implementations. Please move toFileSavePicker.csThere was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).