Skip to content

Commit 72b095e

Browse files
author
Eain Chen
committed
Apply format and context suggestions
1 parent 06a199f commit 72b095e

1 file changed

Lines changed: 33 additions & 18 deletions

File tree

specs/ProgrammaticSaveAs.md

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,27 @@ Programmatic Save As API
33

44
# Background
55

6-
The context menu has the "Save as" item to manually save the html page, image, pdf, or other content through a save as dialog. We provide more flexiable ways to do the save as programmatically in WebView2. You can bring up the default save as dialog easily. And you will be able to block default dialog, save the content silently, by providing the path and save as type programmatically or even build your own save as UI.
6+
The context menu has the "Save as" item to manually save the html page, image,
7+
pdf, or other content through a save as dialog. We provide more flexiable ways
8+
to do the save as programmatically in WebView2. You can bring up the default
9+
save as dialog easily. And you will be able to block default dialog, save the
10+
content silently, by providing the path and save as type programmatically or
11+
even build your own save as UI.
712

813
In this document we describe the API. We'd appreciate your feedback.
914

1015
# Description
1116

12-
We propose the `SaveContentAs` method WebView2, which allows you to trigger the save as programmatically. By using this method alone, the system default will popup.
17+
We propose the `SaveContentAs` method WebView2, which allows you to trigger
18+
the save as programmatically. By using this method alone, the system default
19+
will popup.
1320

14-
Additionally, we propose the `SaveAsRequestedEvent`. You can register this event to block the default dialog and use the `SaveAsRequestedEventArgs` instead, to set your perferred save as path, save as type, and depulicate file replacement rule. In your clinet app, you can design your own UI to input these parameters. For html page, we support 3 save as types: HTML_ONLY, SINGLE_FILE and COMPLETE. For non-html page, the type is been set as DEFAULT, which will save the content as it is. This API also provides default values for all parameters, if you don't want to input anything.
21+
Additionally, we propose the `SaveAsRequested` event. You can register this
22+
event to block the default dialog and use the `SaveAsRequestedEventArgs`
23+
instead, to set your preferred save as path, save as type, and duplicate file replacement rule. In your client app, you can design your own UI to input
24+
these parameters. For HTML documents, we support 3 save as types: HTML_ONLY, SINGLE_FILE and COMPLETE. Non-HTML documents, must use DEFAULT, which will
25+
save the content as it is. This API has default values for all parameters,
26+
to perform the common save as operation.
1527

1628
# Examples
1729
## Win32 C++
@@ -49,9 +61,9 @@ bool ScenarioSaveAs::ToggleSilent()
4961
SaveAsDialog dialog(m_appWindow->GetMainWindow(), contentSaveTypes);
5062
if (dialog.confirmed)
5163
{
52-
// Set the ResultFilePath, SaveAsType, AllowReplace for the event
53-
// args from this customized dialog inputs, optional. If nothing
54-
// needs to input, the event args will provide default values.
64+
// Setting the ResultFilePath, SaveAsType, AllowReplace for the event
65+
// args from this customized dialog inputs is optional.
66+
// The event args has default values based on the document to save.
5567
CHECK_FAILURE(
5668
args->put_ResultFilePath((LPCWSTR)dialog.path.c_str()));
5769
CHECK_FAILURE(args->put_SaveAsType(dialog.selectedType));
@@ -144,15 +156,15 @@ bool ScenarioSaveAs::ProgrammaticSaveAs()
144156
[v1_enum] typedef enum COREWEBVIEW2_SAVE_CONTENT_AS_RESULTS {
145157
/// Programmatically open a system default save as dialog
146158
COREWEBVIEW2_SAVE_AS_OPEN_SYSTEM_DIALOG,
147-
/// Save as downloading not start as given an invalid path
159+
/// Could not perform Save As because the destination file path is an invalid path.
148160
COREWEBVIEW2_SAVE_AS_INVALID_PATH,
149-
/// Save as downloading not start as given a duplicate filename and
150-
/// replace file not allowed
161+
/// Could not perform Save As because the destination file path already exists and
162+
/// replacing files was not allowed by the AllowReplace property.
151163
COREWEBVIEW2_SAVE_AS_FILE_ALREADY_EXISTS,
152164
/// Save as downloading not start as the `SAVE_AS_TYPE` selection not
153165
/// supported because of the content MIME type or system limits
154166
COREWEBVIEW2_SAVE_AS_TYPE_NOT_SUPPORTED,
155-
/// Cancel the save as request
167+
/// Did not perform Save As because the client side decided to cancel.
156168
COREWEBVIEW2_SAVE_AS_CANCELLED,
157169
/// Save as request complete, the downloading started
158170
COREWEBVIEW2_SAVE_AS_STARTED
@@ -224,8 +236,8 @@ interface ICoreWebView2StagingSaveAsRequestedEventArgs : IUnknown {
224236
/// Get the `ConfrimToSave` for save as
225237
[propget] HRESULT ConfirmToSave ([out, retval] BOOL* confirmToSave);
226238

227-
/// Returns an `ICoreWebView2Deferral` object. Use this operation to complete
228-
/// the SaveAsRequestedEvent.
239+
/// Returns an `ICoreWebView2Deferral` object. This will defer showing the
240+
/// default Save As dialog and performing the Save As operation.
229241
HRESULT GetDeferral([out, retval] ICoreWebView2Deferral** deferral);
230242

231243
/// `ResultFilePath` is absolute full path of the location. It includes the
@@ -238,19 +250,22 @@ interface ICoreWebView2StagingSaveAsRequestedEventArgs : IUnknown {
238250
/// Get the `ResultFilePath` for save as
239251
[propget] HRESULT ResultFilePath ([out, retval] LPWSTR* resultFilePath);
240252

241-
/// `AllowReplace` gives the user an option to control when the file name
242-
/// duplicates with an existing file. TRUE allows the old file be replaced.
243-
/// FALSE denies when the file name duplicates, the download won’t start,
244-
/// will return COREWEBVIEW2_SAVE_AS_FILE_ALREADY_EXISTS.
253+
/// `AllowReplace` allows you to control what happens when a file already
254+
/// exists in the file path to which the Save As operation is saving.
255+
/// Setting this TRUE allows existing files to be replaced.
256+
/// Settings this FALSE will not replace existing files and will return
257+
/// COREWEBVIEW2_SAVE_AS_FILE_ALREADY_EXISTS.
245258
///
246259
/// Set if allowed to replace the old file if duplicate happens in the save as job
247260
[propput] HRESULT AllowReplace ([in] BOOL allowReplace);
248261

249262
/// Get the duplicates replace rule for save as
250263
[propget] HRESULT AllowReplace ([out, retval] BOOL* allowReplace);
251264

252-
/// `SaveAsType` is required, see the enum COREWEBVIEW2_SAVE_AS_TYPE, if the type
253-
/// doesn’t match, return COREWEBVIEW2_SAVE_AS_TYPE_NOT_SUPPORT
265+
/// How to save documents with different types. See the enum
266+
/// COREWEBVIEW2_SAVE_AS_TYPE for a description of the different options.
267+
/// If the type isn't allowed for the current document,
268+
/// COREWEBVIEW2_SAVE_AS_TYPE_NOT_SUPPORT will be returned from SaveContentAs.
254269
///
255270
/// Set the content save as type for save as job
256271
[propput] HRESULT SaveAsType ([in] COREWEBVIEW2_SAVE_AS_TYPE type);

0 commit comments

Comments
 (0)