@@ -63,14 +63,25 @@ namespace winrt::Microsoft::Windows::Storage::Pickers::implementation
6363 {
6464 m_defaultFileExtension = value;
6565 }
66- winrt::Windows::Storage::StorageFile FileSavePicker::SuggestedSaveFile ()
66+ hstring FileSavePicker::SuggestedSaveFilePath ()
6767 {
68- return m_suggestedSaveFile ;
68+ return m_suggestedSaveFilePath ;
6969 }
70- void FileSavePicker::SuggestedSaveFile (winrt::Windows::Storage::StorageFile const & value)
70+
71+ bool FileSavePicker::TrySetSuggestedSaveFilePath (hstring const & filePath)
7172 {
72- m_suggestedSaveFile = value;
73+ auto parseResult = PickerCommon::ParseFolderItemAndFileName (filePath);
74+ winrt::com_ptr<IShellItem> folderItem = parseResult.first ;
75+
76+ if (!folderItem)
77+ {
78+ return false ;
79+ }
80+
81+ m_suggestedSaveFilePath = filePath;
82+ return true ;
7383 }
84+
7485 hstring FileSavePicker::SuggestedFileName ()
7586 {
7687 return m_suggestedFileName;
@@ -87,6 +98,8 @@ namespace winrt::Microsoft::Windows::Storage::Pickers::implementation
8798 parameters.CommitButtonText = m_commitButtonText;
8899 parameters.SettingsIdentifierId = m_settingsIdentifier;
89100 parameters.PickerLocationId = m_suggestedStartLocation;
101+ parameters.SuggestedFileName = m_suggestedFileName;
102+ parameters.SuggestedSaveFilePath = m_suggestedSaveFilePath;
90103 parameters.CaptureFilterSpec (m_fileTypeChoices.GetView ());
91104 }
92105
@@ -103,7 +116,7 @@ namespace winrt::Microsoft::Windows::Storage::Pickers::implementation
103116 CaptureParameters (parameters);
104117
105118 auto defaultFileExtension = m_defaultFileExtension;
106- auto suggestedSaveFile = m_suggestedSaveFile ;
119+ auto suggestedSaveFilePath = m_suggestedSaveFilePath ;
107120 auto suggestedFileName = m_suggestedFileName;
108121 auto fileTypeChoices = m_fileTypeChoices;
109122
@@ -119,6 +132,7 @@ namespace winrt::Microsoft::Windows::Storage::Pickers::implementation
119132
120133 auto dialog = create_instance<IFileSaveDialog>(CLSID_FileSaveDialog, CLSCTX_INPROC_SERVER);
121134 parameters.ConfigureDialog (dialog);
135+ parameters.ConfigureFileSaveDialog (dialog);
122136
123137 if (!PickerCommon::IsHStringNullOrEmpty (defaultFileExtension))
124138 {
@@ -135,18 +149,6 @@ namespace winrt::Microsoft::Windows::Storage::Pickers::implementation
135149 check_hresult (dialog->GetOptions (&dialogOptions));
136150 check_hresult (dialog->SetOptions (dialogOptions | FOS_STRICTFILETYPES));
137151
138- if (!PickerCommon::IsHStringNullOrEmpty (suggestedFileName))
139- {
140- check_hresult (dialog->SetFileName (suggestedFileName.c_str ()));
141- }
142-
143- if (suggestedSaveFile != nullptr )
144- {
145- winrt::com_ptr<IShellItem> shellItem;
146- check_hresult (SHCreateItemFromParsingName (suggestedSaveFile.Path ().c_str (), nullptr , IID_PPV_ARGS (shellItem.put ())));
147- check_hresult (dialog->SetSaveAsItem (shellItem.get ()));
148- }
149-
150152 {
151153 auto hr = dialog->Show (parameters.HWnd );
152154 if (FAILED (hr))
@@ -185,4 +187,3 @@ namespace winrt::Microsoft::Windows::Storage::Pickers::implementation
185187 co_return result;
186188 }
187189}
188-
0 commit comments