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'] messageBoxTypes = ['none', 'info', 'warning']
module.exports = parseArgs = (window, options, callback) ->
showOpenDialog: (window, options, callback) -> unless window is null or window?.constructor is BrowserWindow
unless window?.constructor is BrowserWindow
# Shift. # Shift.
callback = options callback = options
options = window options = window
window = null window = null
if not callback? and typeof options is 'function'
# Shift.
callback = options
options = null
[window, options, callback]
module.exports =
showOpenDialog: (args...) ->
[window, options, callback] = parseArgs args...
options ?= title: 'Open', properties: ['openFile'] options ?= title: 'Open', properties: ['openFile']
options.properties ?= ['openFile'] options.properties ?= ['openFile']
@ -44,11 +52,7 @@ module.exports =
wrappedCallback wrappedCallback
showSaveDialog: (window, options, callback) -> showSaveDialog: (window, options, callback) ->
unless window?.constructor is BrowserWindow [window, options, callback] = parseArgs args...
# Shift.
callback = options
options = window
window = null
options ?= title: 'Save' options ?= title: 'Save'
options.title ?= '' options.title ?= ''
@ -68,11 +72,7 @@ module.exports =
wrappedCallback wrappedCallback
showMessageBox: (window, options, callback) -> showMessageBox: (window, options, callback) ->
unless window?.constructor is BrowserWindow [window, options, callback] = parseArgs args...
# Shift.
callback = options
options = window
window = null
options ?= type: 'none' options ?= type: 'none'
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. **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 * `browserWindow` BrowserWindow
* `options` Object * `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 `['openFile', 'openDirectory']` on these platforms, a directory selector would
be showed. be showed.
## dialog.showSaveDialog([browserWindow], options, [callback]) ## dialog.showSaveDialog([browserWindow], [options], [callback])
* `browserWindow` BrowserWindow * `browserWindow` BrowserWindow
* `options` Object * `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 If a `callback` is passed, the API call would be asynchronous and the result
would be passed via `callback(filename)` would be passed via `callback(filename)`
## dialog.showMessageBox([browserWindow], options, [callback]) ## dialog.showMessageBox([browserWindow], [options], [callback])
* `browserWindow` BrowserWindow * `browserWindow` BrowserWindow
* `options` Object * `options` Object