Skip to content

feat: Implemented FileSavePicker on MacOS - #4215

Merged
mergify[bot] merged 9 commits into
unoplatform:masterfrom
snickler:dev/snickler/FileSavePickerMacOS
Nov 30, 2020
Merged

mergify[bot] merged 9 commits into
unoplatform:masterfrom
snickler:dev/snickler/FileSavePickerMacOS

Conversation

@snickler

@snickler snickler commented Oct 3, 2020

Copy link
Copy Markdown
Contributor

GitHub Issue (If applicable): #3215

PR Type

What kind of change does this PR introduce?

  • Feature

What is the current behavior?

Not implemented

What is the new behavior?

Implemented

PR Checklist

Please check if your PR fulfills the following requirements:

Other information

Internal Issue (If applicable):

@snickler
snickler requested a review from a team October 3, 2020 16:35
@gitpod-io

gitpod-io Bot commented Oct 3, 2020 •

Copy link
Copy Markdown

public string CommitButtonText { get; set; }

public IDictionary<string, IList<string>> FileTypeChoices { get; set; }
public IDictionary<string, IList<string>> FileTypeChoices { get; set; } = new Dictionary<string, IList<string>>();

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.

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.

Indeed. This will introduce a breaking change that will need to be flagged in PackageDiffIgnore.xml, and is not supposed to be valid anyways as it can't be used by any UWP compatible codebase.

@weitzhandler weitzhandler Oct 7, 2020 •

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.

Alternatively make the setter obsolete (C# 8) as follows:

private IDictionary<string, IList<string>> fileTypeChoices;
public IDictionary<string, IList<string>> FileTypeChoices
{
  get => fileTypeChoices ?? = new Dictionary<string, IList<string>>(); //or initialize backing field
  [Obsolete("This setter will be removed in future versions.")]
  set = fileTypeChoices =  value;
}

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.

@weitzhandler This change may not be acceptable without nullable references, as FileTypeChoices may be null and must be validated at all uses sites. If #nullable enable is added, then yes, it's useful.

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.

@jeromelaban are you talking about the ??= operator?

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.

Yes, if the fileTypeChoices member is used elsewhere in the class, it may fail because of a null reference exception.

@weitzhandler weitzhandler Oct 8, 2020 •

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.

Even with nullable reference, the issue still exists, if FileTypeChoices is set to null externally (via the property).
Unless we also ensure initialized in setter.

@weitzhandler weitzhandler Oct 8, 2020 •

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.

Alternatively

private readonly IDictionary<string, IList<string>> fileTypeChoices =
  new Dictionary<string, IList<string>>();

public IDictionary<string, IList<string>> FileTypeChoices
{
  get => fileTypeChoices;
  [Obsolete("This setter will be removed in future versions.")]
  set
  {
    if(value?.Any())
    {
      fileTypeChoices.Clear();
      foreach(var kv in value)
      {
        fileTypeChoices.Add(kv);
      }
    }
  }
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jeromelaban - I'm assuming I need to merge the PackageDiffIgnore.xml from master into my branch and add the setter in and try this the CI again?

var savePicker = new NSSavePanel();
savePicker.DirectoryUrl = new NSUrl(GetStartPath(), true);
savePicker.AllowedFileTypes = GetFileTypes();
if(SuggestedFileName != null)

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.

nit: missing space after if

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.

I'm always puzzled by this. It could be that VS4mac does not support the .editorconfig file properly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I THINK it is. I just found documentation for it, but it was my fault for not executing a Format Document on everything before committing.

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.

No worries at all, coding guidelines evolved a bit over the course of time, though reformatting a whole document when modifying an existing one is generally not a good idea for a feature PR as it makes reviewing more complicated. For new files, it's a good idea! (Along with #nullable enable)

{
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).

PickerLocationId.PicturesLibrary => Environment.SpecialFolder.MyPictures,
PickerLocationId.VideosLibrary => Environment.SpecialFolder.MyVideos,
_ => Environment.SpecialFolder.Personal

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.

nit: extra new line

@@ -0,0 +1,39 @@
namespace Windows.Storage.Pickers

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.

nit: might want to remove all extra new lines in this file

@jeromelaban

Copy link
Copy Markdown
Member

Thanks for your contribution @snickler !

@snickler

snickler commented Oct 5, 2020

Copy link
Copy Markdown
Contributor Author

Thanks everyone! I haven't interacted with the Code Suggestions in GitHub before, I'm assuming that Resolve Conversation will apply the suggestions as it would in Azure DevOps?

@robloo

robloo commented Oct 5, 2020

Copy link
Copy Markdown
Contributor

Thanks everyone! I haven't interacted with the Code Suggestions in GitHub before, I'm assuming that Resolve Conversation will apply the suggestions as it would in Azure DevOps?

Not for my comments, I didnt make any code edits to be applied.

@snickler

snickler commented Oct 5, 2020

Copy link
Copy Markdown
Contributor Author

Thanks everyone! I haven't interacted with the Code Suggestions in GitHub before, I'm assuming that Resolve Conversation will apply the suggestions as it would in Azure DevOps?

Not for my comments, I didnt make any code edits to be applied.

Ah, I confused myself. When I first clicked on the comment, the popup help made me think these were code review changes rather than the code I updated.

@weitzhandler

Copy link
Copy Markdown
Member

Thanks everyone! I haven't interacted with the Code Suggestions in GitHub before, I'm assuming that Resolve Conversation will apply the suggestions as it would in Azure DevOps?

In DevOps you'd also need to click "Apply Change"

@robloo robloo mentioned this pull request Oct 9, 2020
2 of 6 tasks
@MartinZikmund

Copy link
Copy Markdown
Member

@snickler There are conflicts now, as PickerLocationId was merged, can you resolve them please :-) ? Also - have you been able to find a way to fix the "Documents" picker location? I remember we didn't resolve that during the live coding :-)

@snickler

Copy link
Copy Markdown
Contributor Author

@snickler There are conflicts now, as PickerLocationId was merged, can you resolve them please :-) ? Also - have you been able to find a way to fix the "Documents" picker location? I remember we didn't resolve that during the live coding :-)

I haven't done that yet. I'll actually see if I can fix that in this PR.

@jeromelaban jeromelaban left a comment

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.

This is looking good! The only thing left is https://github.com/unoplatform/uno/pull/4215/files#r499267336, where the set should be private. Then we'll be able to merge.

@snickler snickler closed this Nov 29, 2020
@snickler snickler reopened this Nov 29, 2020
@gitpod-io

gitpod-io Bot commented Nov 29, 2020

Copy link
Copy Markdown

@MartinZikmund MartinZikmund added the ready-to-merge Automatically merge the PR once all '.mergify.yml' policies are met label Nov 30, 2020
@mergify
mergify Bot merged commit a90b808 into unoplatform:master Nov 30, 2020
@welcome

welcome Bot commented Nov 30, 2020

Copy link
Copy Markdown

Congrats on your first pull-request! We ❤ the people who are involved in this project, and we’d love to pay it forward by sending you some swag. If you have any feedback (or ideas how to improve Uno as a open-source project) please open a feedback issue.
giphy
Merci beaucoup 👋

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge Automatically merge the PR once all '.mergify.yml' policies are met

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants