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
feat: add methods to allow customization of save dialog during will-download event #15497
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bb6de99
feat: add method to DownloadItem that allows customization of dialog …
brenca 8996b4b
docs: add docs for get/setSaveDialogOptions
brenca 8c6dc66
add missing copy constructor for DialogSettings on mac and linux
brenca 537debd
fix: don't filter dialog options for mas build, don't return properties
brenca 4287bcc
test: add test for get/setSaveDialogOptions
brenca ae042aa
fix: remove openDevtools added for debugging
brenca 652afe6
test: fix failing test because of new event parameter
brenca 51a1c2c
docs: use SaveDialogOptions instead of Object
brenca File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
atom/common/native_mate_converters/file_dialog_converter.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright (c) 2015 GitHub, Inc. | ||
// Use of this source code is governed by the MIT license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "atom/common/native_mate_converters/file_dialog_converter.h" | ||
|
||
#include "atom/browser/api/atom_api_browser_window.h" | ||
#include "atom/browser/ui/file_dialog.h" | ||
#include "atom/common/native_mate_converters/file_path_converter.h" | ||
#include "native_mate/dictionary.h" | ||
|
||
namespace mate { | ||
|
||
bool Converter<file_dialog::Filter>::FromV8(v8::Isolate* isolate, | ||
v8::Local<v8::Value> val, | ||
file_dialog::Filter* out) { | ||
mate::Dictionary dict; | ||
if (!ConvertFromV8(isolate, val, &dict)) | ||
return false; | ||
if (!dict.Get("name", &(out->first))) | ||
return false; | ||
if (!dict.Get("extensions", &(out->second))) | ||
return false; | ||
return true; | ||
} | ||
|
||
v8::Local<v8::Value> Converter<file_dialog::Filter>::ToV8( | ||
v8::Isolate* isolate, | ||
const file_dialog::Filter& in) { | ||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); | ||
|
||
dict.Set("name", in.first); | ||
dict.Set("extensions", in.second); | ||
|
||
return dict.GetHandle(); | ||
} | ||
|
||
bool Converter<file_dialog::DialogSettings>::FromV8( | ||
v8::Isolate* isolate, | ||
v8::Local<v8::Value> val, | ||
file_dialog::DialogSettings* out) { | ||
mate::Dictionary dict; | ||
if (!ConvertFromV8(isolate, val, &dict)) | ||
return false; | ||
dict.Get("window", &(out->parent_window)); | ||
dict.Get("title", &(out->title)); | ||
dict.Get("message", &(out->message)); | ||
dict.Get("buttonLabel", &(out->button_label)); | ||
dict.Get("nameFieldLabel", &(out->name_field_label)); | ||
dict.Get("defaultPath", &(out->default_path)); | ||
dict.Get("filters", &(out->filters)); | ||
dict.Get("properties", &(out->properties)); | ||
dict.Get("showsTagField", &(out->shows_tag_field)); | ||
dict.Get("securityScopedBookmarks", &(out->security_scoped_bookmarks)); | ||
return true; | ||
} | ||
|
||
v8::Local<v8::Value> Converter<file_dialog::DialogSettings>::ToV8( | ||
v8::Isolate* isolate, | ||
const file_dialog::DialogSettings& in) { | ||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); | ||
|
||
dict.Set("window", atom::api::BrowserWindow::From(isolate, in.parent_window)); | ||
dict.Set("title", in.title); | ||
dict.Set("message", in.message); | ||
dict.Set("buttonLabel", in.button_label); | ||
dict.Set("nameFieldLabel", in.name_field_label); | ||
dict.Set("defaultPath", in.default_path); | ||
dict.Set("filters", in.filters); | ||
dict.Set("showsTagField", in.shows_tag_field); | ||
dict.Set("securityScopedBookmarks", in.security_scoped_bookmarks); | ||
|
||
return dict.GetHandle(); | ||
} | ||
|
||
} // namespace mate |
33 changes: 33 additions & 0 deletions
33
atom/common/native_mate_converters/file_dialog_converter.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) 2014 GitHub, Inc. | ||
// Use of this source code is governed by the MIT license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef ATOM_COMMON_NATIVE_MATE_CONVERTERS_FILE_DIALOG_CONVERTER_H_ | ||
#define ATOM_COMMON_NATIVE_MATE_CONVERTERS_FILE_DIALOG_CONVERTER_H_ | ||
|
||
#include "atom/browser/ui/file_dialog.h" | ||
#include "native_mate/converter.h" | ||
|
||
namespace mate { | ||
|
||
template <> | ||
struct Converter<file_dialog::Filter> { | ||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, | ||
const file_dialog::Filter& in); | ||
static bool FromV8(v8::Isolate* isolate, | ||
v8::Local<v8::Value> val, | ||
file_dialog::Filter* out); | ||
}; | ||
|
||
template <> | ||
struct Converter<file_dialog::DialogSettings> { | ||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, | ||
const file_dialog::DialogSettings& in); | ||
static bool FromV8(v8::Isolate* isolate, | ||
v8::Local<v8::Value> val, | ||
file_dialog::DialogSettings* out); | ||
}; | ||
|
||
} // namespace mate | ||
|
||
#endif // ATOM_COMMON_NATIVE_MATE_CONVERTERS_FILE_DIALOG_CONVERTER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,19 @@ Returns `String` - The save path of the download item. This will be either the p | |
set via `downloadItem.setSavePath(path)` or the path selected from the shown | ||
save dialog. | ||
|
||
#### `downloadItem.setSaveDialogOptions(options)` | ||
|
||
* `options` Object - Set the save file dialog options. This object has the same | ||
properties as the `options` parameter of [`dialog.showSaveDialog()`](dialog.md). | ||
|
||
This API allows the user to set custom options for the save dialog that opens | ||
for the download item by default. | ||
The API is only available in session's `will-download` callback function. | ||
|
||
#### `downloadItem.getSaveDialogOptions()` | ||
|
||
Returns `Object` - Returns the object previously set by `downloadItem.setSaveDialogOptions(options)`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this return the defaults if they haven't been previously set? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The defaults are only set after the JS callback actually runs AFAIK, so nope. |
||
|
||
#### `downloadItem.pause()` | ||
|
||
Pauses the download. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This can be more specific, it isn't
Object
ratherSaveDialogOptions