Merge pull request from yamgent/macos-open-save-panel

Support message, nameFieldLabel and showsTagField for macOS dialog
This commit is contained in:
Kevin Sawicki 2017-02-09 11:34:19 -08:00 committed by GitHub
commit 5bf60ad8e8
6 changed files with 59 additions and 4 deletions

View file

@ -45,10 +45,13 @@ struct Converter<file_dialog::DialogSettings> {
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));
return true;
}
};

View file

@ -40,10 +40,13 @@ typedef base::Callback<void(
struct DialogSettings {
atom::NativeWindow* parent_window = nullptr;
std::string title;
std::string message;
std::string button_label;
std::string name_field_label;
base::FilePath default_path;
Filters filters;
int properties = 0;
bool shows_tag_field = true;
};
bool ShowOpenDialog(const DialogSettings& settings,

View file

@ -51,6 +51,14 @@ void SetupDialog(NSSavePanel* dialog,
if (!settings.button_label.empty())
[dialog setPrompt:base::SysUTF8ToNSString(settings.button_label)];
if (!settings.message.empty())
[dialog setMessage:base::SysUTF8ToNSString(settings.message)];
if (!settings.name_field_label.empty())
[dialog setNameFieldLabel:base::SysUTF8ToNSString(settings.name_field_label)];
[dialog setShowsTagField:settings.shows_tag_field];
NSString* default_dir = nil;
NSString* default_filename = nil;
if (!settings.default_path.empty()) {

View file

@ -51,6 +51,8 @@ The `dialog` module has the following methods:
untouched on Windows. For example, a button label of `Vie&w` will be
converted to `Vie_w` on Linux and `View` on macOS and can be selected
via `Alt-W` on Windows and Linux.
* `message` String (optional) _macOS_ - Message to display above input
boxes.
* `callback` Function (optional)
* `filePaths` String[] - An array of file paths chosen by the user
@ -94,6 +96,11 @@ shown.
* `buttonLabel` String (optional) - Custom label for the confirmation button, when
left empty the default label will be used.
* `filters` [FileFilter[]](structures/file-filter.md) (optional)
* `message` String (optional) _macOS_ - Message to display above text fields.
* `nameFieldLabel` String (optional) _macOS_ - Custom label for the text
displayed in front of the filename text field.
* `showsTagField` Boolean (optional) _macOS_ - Show the tags input box,
defaults to `true`.
* `callback` Function (optional)
* `filename` String

View file

@ -81,7 +81,7 @@ module.exports = {
}
}
let {buttonLabel, defaultPath, filters, properties, title} = options
let {buttonLabel, defaultPath, filters, properties, title, message} = options
if (properties == null) {
properties = ['openFile']
@ -118,10 +118,16 @@ module.exports = {
filters = []
}
if (message == null) {
message = ''
} else if (typeof message !== 'string') {
throw new TypeError('Message must be a string')
}
const wrappedCallback = typeof callback === 'function' ? function (success, result) {
return callback(success ? result : void 0)
} : null
const settings = {title, buttonLabel, defaultPath, filters, window}
const settings = {title, buttonLabel, defaultPath, filters, message, window}
settings.properties = dialogProperties
return binding.showOpenDialog(settings, wrappedCallback)
},
@ -137,7 +143,7 @@ module.exports = {
}
}
let {buttonLabel, defaultPath, filters, title} = options
let {buttonLabel, defaultPath, filters, title, message, nameFieldLabel, showsTagField} = options
if (title == null) {
title = ''
@ -161,10 +167,26 @@ module.exports = {
filters = []
}
if (message == null) {
message = ''
} else if (typeof message !== 'string') {
throw new TypeError('Message must be a string')
}
if (nameFieldLabel == null) {
nameFieldLabel = ''
} else if (typeof nameFieldLabel !== 'string') {
throw new TypeError('Name field label must be a string')
}
if (showsTagField == null) {
showsTagField = true
}
const wrappedCallback = typeof callback === 'function' ? function (success, result) {
return callback(success ? result : void 0)
} : null
const settings = {title, buttonLabel, defaultPath, filters, window}
const settings = {title, buttonLabel, defaultPath, filters, message, nameFieldLabel, showsTagField, window}
return binding.showSaveDialog(settings, wrappedCallback)
},

View file

@ -19,6 +19,10 @@ describe('dialog module', () => {
assert.throws(() => {
dialog.showOpenDialog({defaultPath: {}})
}, /Default path must be a string/)
assert.throws(() => {
dialog.showOpenDialog({message: {}})
}, /Message must be a string/)
})
})
@ -35,6 +39,14 @@ describe('dialog module', () => {
assert.throws(() => {
dialog.showSaveDialog({defaultPath: {}})
}, /Default path must be a string/)
assert.throws(() => {
dialog.showSaveDialog({message: {}})
}, /Message must be a string/)
assert.throws(() => {
dialog.showSaveDialog({nameFieldLabel: {}})
}, /Name field label must be a string/)
})
})