Skip to content
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

File picker and bookmarks API #8303

Merged
merged 11 commits into from
Jul 5, 2022
Merged

File picker and bookmarks API #8303

merged 11 commits into from
Jul 5, 2022

Conversation

maxkatz6
Copy link
Member

@maxkatz6 maxkatz6 commented Jun 8, 2022

What does the pull request do?

Initial implementation of new file picker API.
API layer was also inspired by HTML5 browser File API and naming from UWP.
Xamarin Essentials, Qt, Electron and react-native-document-picker were used as a reference for implementation (aside from native API docs).

Current progress:

  • Open/save file and open folder dialogs API
  • Bookmark API (without required additions for WASM)
  • Implementation for main desktop OSes - win, osx, lin
  • iOS and Android implementation
  • Update managed file dialog to work with new interfaces
  • Folder picker support for Android.
  • FileAPI Browser support
  • Finalize the API and set it in stone

Out of this PR, but to be done in this release:

  • Fallback browser support with a ponyfil
  • macOS sandbox safe bookmarks implementation ([OSX] App Store Sandbox Bookmarks API #6540)
  • Export API. Or Share API, naming? I would prefer to keep it minimal. Required for iOS and WASM support, as there is no "Save" pickers (except newest new File API).

Potentially in the future:

  • StorageFile file type

Usage:

var folder = await window.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions());
var openedFile = await window.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions()
{
    SuggestedStartLocation = folder
});

// Open file to write.
var stream = await openedFile.OpenWrite();

// To save in local database.
var bookmarkId = openedFile.SaveBookmark();

var file = await window.StorageProvider.OpenFileBookmarkAsync(bookmarkId);

// Uri as it can be "file:" or "content:" or relative link depending on the platform. Following Qt API.
if (file.TryGetUri(out var uri) && uri.IsAbsoluteUri)
{
    var absolutePath = uri.LocalPath;
}

Checklist

Breaking changes

None

Obsoletions / Deprecations

SystemDialog and OpenFileDialog/SaveFileDialog/OpenFolderDialog are obsolete now.

Fixed issues

Fixes #7234
Fixes #7209

Questions

Q: Should I rename topLevel.StorageProvider to topLevel.FilePicker with related interface names? Or FileSystem? Or FileManager to match other *Manager classes.
Q: Should API be change in order to allow opening dialogs without window/toplevel at all? It's possible only on desktop.
Q: Replace bool properties with enum flags?

@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 0.10.999-cibuild0021086-beta. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]

@robloo
Copy link
Contributor

robloo commented Jun 8, 2022

Nice!

@Symbai
Copy link
Contributor

Symbai commented Jun 12, 2022

Does it finally support multi folder selection? #7209

@maxkatz6
Copy link
Member Author

maxkatz6 commented Jun 12, 2022

No. Main goal to have mobile/wasm compatible API.

@Symbai
Copy link
Contributor

Symbai commented Jun 13, 2022

If you rewrite the whole API and obsolete existing API, wouldn't it make sense to look at existing issues and make sure they don't exist in the new one too? When, if not now, is the best chance for that?

@maxkatz6
Copy link
Member Author

I don't think I have seen anywhere multi-folder picker API in xplat frameworks. And overall usefulness seems low.
But I will look which platforms actually support it. If it's more than one or two, than it's possible to do now.

@Symbai
Copy link
Contributor

Symbai commented Jun 13, 2022

No idea what xplat frameworks is. But multi folder picker is a common thing on Windows and MacOS and Linux (basically all desktop environments). Winforms support it therefore also WPF. WinUI currently seem to not support it, because it comes from UWP which also hasn't supported it but it was also requested. For mobile it might not make much sense but I have never used a mobile app that asked me to select a folder at all, because working with folders on mobile devices is quite uncommon.

@timunie
Copy link
Contributor

timunie commented Jun 13, 2022

I really think we will need some docs how to handle this once it is ready. What do you think @maxkatz6 ?

@maxkatz6
Copy link
Member Author

maxkatz6 commented Jun 19, 2022

Demo of file picker with bookmarks (reusing same file without opening picker again).
Currently uses HTML5 File API, which is available only in Chromium browsers. Fallback for older browsers is planned for the next PR. Unfortunately, bookmarks will work only and only with File API impl, and fallback will require service worker as well.

1.mp4

@maxkatz6
Copy link
Member Author

This PR can now be tested, if anybody wants to try.

I have to update macOS implementation to support file types. And test macos/ios once more.
And probably I can try to make "default name with extension" behavior more consistent across platforms in this PR. Somewhere extension is appended automatically, somewhere it's not.

@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 0.10.999-cibuild0021227-beta. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]

@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 0.10.999-cibuild0021285-beta. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]

@maxkatz6 maxkatz6 changed the title [WIP] File picker API File picker API Jun 24, 2022
@maxkatz6 maxkatz6 changed the title File picker API File picker and bookmarks API Jun 24, 2022
@maxkatz6 maxkatz6 marked this pull request as ready for review June 24, 2022 05:08
@maxkatz6 maxkatz6 requested review from kekekeks and a team June 24, 2022 05:08
@@ -76,21 +76,21 @@
<StackPanel Orientation="Vertical" Margin="10">
<Label Target="upDown" FontSize="14" FontWeight="Bold" VerticalAlignment="Center">Usage of decimal NumericUpDown:</Label>
<NumericUpDown Name="upDown" Minimum="0" Maximum="10" Increment="0.5"
CultureInfo="en-US" VerticalAlignment="Center" Value="{Binding DecimalValue}"
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed default culture info, as it was crashing control catalog in the browser.

@maxkatz6 maxkatz6 requested a review from danwalmsley June 24, 2022 05:16
@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 0.10.999-cibuild0021348-beta. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]

@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 0.10.999-cibuild0021548-beta. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]

@grokys
Copy link
Member

grokys commented Jul 4, 2022

Q: Should I rename topLevel.StorageProvider to topLevel.FilePicker with related interface names? Or FileSystem? Or FileManager to match other *Manager classes.

From what I understand, this API will also be used later to provide access to e.g. a Share dialog, which isn't a "file picker" or related to the "file system", so StorageProvider makes sense to me here.

@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 0.10.999-cibuild0021619-beta. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]

/// <summary>
/// Gets or sets the file name that the file save picker suggests to the user.
/// </summary>
public string? SuggestedFileName { get; set; }
Copy link
Member

Choose a reason for hiding this comment

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

I think it's valid for both save and open dialogs

Copy link
Member Author

Choose a reason for hiding this comment

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

For "open" dialog it should be "SelectedFile" or something of IStorageFile type. We can add it later on top of that api.

/// <summary>
/// Gets or sets the initial location where the file open picker looks for files to present to the user.
/// </summary>
public IStorageFolder? SuggestedStartLocation { get; set; }
Copy link
Member

Choose a reason for hiding this comment

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

Could we move Title and SuggestedStartLocation to a common base class?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep

@maxkatz6 maxkatz6 enabled auto-merge July 5, 2022 22:54
@maxkatz6 maxkatz6 merged commit 4a2b731 into master Jul 5, 2022
@maxkatz6 maxkatz6 deleted the file-picker branch July 5, 2022 23:15
@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 0.10.999-cibuild0021621-beta. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]

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

Successfully merging this pull request may close these issues.

New file picker API OpenFolderDialog - Support multi selection
8 participants