-
Notifications
You must be signed in to change notification settings - Fork 367
FileSavePicker.SuggestedSaveFilePath #5547
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
base: main
Are you sure you want to change the base?
FileSavePicker.SuggestedSaveFilePath #5547
Conversation
test/DynamicDependency/data/Microsoft.WindowsAppRuntime.Framework/appxmanifest.xml
Outdated
Show resolved
Hide resolved
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.
Pull Request Overview
This pull request refactors the FileSavePicker implementation to use a lightweight string property for the suggested save file path, updates the related API contracts, and introduces enhanced dialog configuration along with comprehensive tests.
- Replaces StorageFile SuggestedSaveFile with hstring SuggestedSaveFilePath
- Introduces the ConfigureFileSaveDialog method in PickerCommon
- Updates tests to verify the new behavior in both FileSavePicker and PickerCommon
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
test/StoragePickersTests/StoragePickersTests.cpp | Adds tests for the new SuggestedSaveFilePath property. |
test/StoragePickersTests/PickerCommonTests.cpp | Provides unit tests covering dialog configuration and precedence of SuggestedSaveFilePath over SuggestedFileName. |
dev/Interop/StoragePickers/PickerCommon.h | Updates internal structure and adds declaration for ConfigureFileSaveDialog. |
dev/Interop/StoragePickers/PickerCommon.cpp | Implements ConfigureFileSaveDialog using std::filesystem to set the starting directory and file name based on the new property. |
dev/Interop/StoragePickers/Microsoft.Windows.Storage.Pickers.idl | Reflects the API changes by replacing SuggestedSaveFile with SuggestedSaveFilePath and adding API contract definitions. |
dev/Interop/StoragePickers/FileSavePicker.h | Updates the public interface to use hstring for suggested save file paths. |
dev/Interop/StoragePickers/FileSavePicker.cpp | Refactors implementation and integrates the new ConfigureFileSaveDialog for a cleaner dialog setup. |
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.
Just the remaining question about how to handle failure from SHCreateItemFromParsingName(). I'm not sure it is good to just ignore the failure. I expect at least some failures would have previously been caught in app code, such as if the string doesn't have valid path syntax. Would the old model have also required that the path exist?
I wonder if we should throw an invalid argument error (with an error string to explain which arg is invalid). What does the old syntax or the UWP picker do with an invalid path syntax or missing path?
Hi @codendone , Thanks for raising this! In most cases, the old model (the UWP FileSavePicker) wouldn't encounter this issue, because the UWP picker APIs typically take a That said, it is possible to simulate this scenario in UWP with a specifically designed code and steps:
In this case, the save file dialog will still launch successfully because the original After having launched, the dialog will show an error message : "Location is not available", because the folder that previous existed is gone. Please note that this message box doesn't block the user from continuing to use the save dialog. The user can dismiss the message box and proceed. @asklar , in summary a similar messagebox is shown in the UWP pickers. And the SuggestedSaveFile's file name is still automatically filled in the file name input box. In contrast, the new picker model uses a string path to set Even if the folder item creation fails (e.g., the folder doesn't exist), as a suggested value, it should not block users from using the dialog - that's the reason why we initially chose to ignore the error and only to set the folder when it exists. On second thought, we could show a message box before launching the dialog - similar to how UWP shows an error after launch. This would inform the user about the non-existing but expected folder, without blocking user from using the dialog
How do you like this update? Here's a demo of the latest iteration: |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
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.
Follow-up is still happening on the handling of invalid/missing path, but if you'd like to open a separate issue for follow-up on that, I'm okay with completing this PR and handling that follow-up before the API goes stable.
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Description
This PR changes the property of
FileSavePicker.SuggestedSaveFile
into a light-weight string propertyFileSavePicker.SuggestedSaveFilePath
, which is the implementation of design spec: #5538This PR also adds contract for the storage pickers, and excludes the unnecessary property (FolderPicker.FileTypeFilter) from the contract.
Code Details
This pull request introduces several changes to the
StoragePickers
module, focusing on enhancing theFileSavePicker
functionality by replacingSuggestedSaveFile
withSuggestedSaveFilePath
, removing theFileTypeFilter
fromFolderPicker
, and adding new API contracts for better versioning. Additionally, it includes updates to test cases and internal configurations for improved functionality and reliability.Enhancements to
FileSavePicker
:SuggestedSaveFile
withSuggestedSaveFilePath
inFileSavePicker
to allow specifying file paths directly, including updates to both the implementation (FileSavePicker.cpp
) and header (FileSavePicker.h
). [1] [2]PickerParameters::ConfigureFileSaveDialog
to handleSuggestedSaveFilePath
for setting the starting directory and file name in the save dialog, with fallback toSuggestedFileName
..idl
file to reflect theSuggestedSaveFilePath
change in theFileSavePicker
runtime class.Simplifications to
FolderPicker
:FileTypeFilter
property fromFolderPicker
, simplifying its API and associated logic in both the implementation (FolderPicker.cpp
) and header (FolderPicker.h
). [1] [2]API Versioning and Contracts:
StoragePickersContract
(version 1.8) in the.idl
file to enable better API versioning and feature gating forStoragePickers
.Test Suite Updates:
PickerParameters::ConfigureFileSaveDialog
to verify behavior whenSuggestedSaveFilePath
is set and its precedence overSuggestedFileName
.FileSavePicker
to validate theSuggestedSaveFilePath
property.Internal Configuration Updates:
PickerCommon.cpp
with additional includes (shellapi.h
,shobjidl_core.h
, etc.) to support new functionality for file path handling.