Make dialog API's parameters more flexible.

This commit is contained in:
Cheng Zhao 2014-09-06 18:55:01 +08:00
parent fd806f81ce
commit 19b25c0d83
2 changed files with 19 additions and 19 deletions

View file

@ -10,13 +10,21 @@ fileDialogProperties =
messageBoxTypes = ['none', 'info', 'warning']
parseArgs = (window, options, callback) ->
unless window is null or window?.constructor is BrowserWindow
# Shift.
callback = options
options = window
window = null
if not callback? and typeof options is 'function'
# Shift.
callback = options
options = null
[window, options, callback]
module.exports =
showOpenDialog: (window, options, callback) ->
unless window?.constructor is BrowserWindow
# Shift.
callback = options
options = window
window = null
showOpenDialog: (args...) ->
[window, options, callback] = parseArgs args...
options ?= title: 'Open', properties: ['openFile']
options.properties ?= ['openFile']
@ -44,11 +52,7 @@ module.exports =
wrappedCallback
showSaveDialog: (window, options, callback) ->
unless window?.constructor is BrowserWindow
# Shift.
callback = options
options = window
window = null
[window, options, callback] = parseArgs args...
options ?= title: 'Save'
options.title ?= ''
@ -68,11 +72,7 @@ module.exports =
wrappedCallback
showMessageBox: (window, options, callback) ->
unless window?.constructor is BrowserWindow
# Shift.
callback = options
options = window
window = null
[window, options, callback] = parseArgs args...
options ?= type: 'none'
options.type ?= 'none'

View file

@ -13,7 +13,7 @@ console.log(dialog.showOpenDialog({ properties: [ 'openFile', 'openDirectory', '
**Note for OS X**: If you want to present dialogs as sheets, the only thing you have to do is to provide a `BrowserWindow` reference in the `browserWindow` parameter.
## dialog.showOpenDialog([browserWindow], options, [callback])
## dialog.showOpenDialog([browserWindow], [options], [callback])
* `browserWindow` BrowserWindow
* `options` Object
@ -49,7 +49,7 @@ and directory selector at the same time, so if you set `properties` to
`['openFile', 'openDirectory']` on these platforms, a directory selector would
be showed.
## dialog.showSaveDialog([browserWindow], options, [callback])
## dialog.showSaveDialog([browserWindow], [options], [callback])
* `browserWindow` BrowserWindow
* `options` Object
@ -67,7 +67,7 @@ The `filters` specifies an array of file types that can be displayed, see
If a `callback` is passed, the API call would be asynchronous and the result
would be passed via `callback(filename)`
## dialog.showMessageBox([browserWindow], options, [callback])
## dialog.showMessageBox([browserWindow], [options], [callback])
* `browserWindow` BrowserWindow
* `options` Object