Skip to content

Commit

Permalink
update js preparsing
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Feb 15, 2019
1 parent b45ae74 commit f0169e8
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 58 deletions.
19 changes: 17 additions & 2 deletions docs/api/dialog.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ The `dialog` module has the following methods:
boxes.
* `securityScopedBookmarks` Boolean (optional) _masOS_ _mas_ - Create [security scoped bookmarks](https://developer.apple.com/library/content/documentation/Security/Conceptual/AppSandboxDesignGuide/AppSandboxInDepth/AppSandboxInDepth.html#//apple_ref/doc/uid/TP40011183-CH3-SW16) when packaged for the Mac App Store.

Returns `undefined`.

The `browserWindow` argument allows the dialog to attach itself to a parent window, making it modal.

The `filters` specifies an array of file types that can be displayed or
Expand All @@ -79,6 +77,12 @@ and a directory selector, so if you set `properties` to
`['openFile', 'openDirectory']` on these platforms, a directory selector will be
shown.

```js
dialog.showOpenDialogSync(mainWindow, {
properties: ['openFile', 'openDirectory']
})
```

### `dialog.showOpenDialog([browserWindow, ]options)`

* `browserWindow` [BrowserWindow](browser-window.md) (optional)
Expand Down Expand Up @@ -140,6 +144,17 @@ and a directory selector, so if you set `properties` to
`['openFile', 'openDirectory']` on these platforms, a directory selector will be
shown.

```js
dialog.showOpenDialog(mainWindow, {
properties: ['openFile', 'openDirectory']
}).then(result => {
console.log(result.canceled)
console.log(result.filePaths)
}).catch(err => {
console.log(err)
})
```

### `dialog.showSaveDialog([browserWindow, ]options[, callback])`

* `browserWindow` [BrowserWindow](browser-window.md) (optional)
Expand Down
97 changes: 41 additions & 56 deletions lib/browser/api/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,70 +70,55 @@ const checkAppInitialized = function () {
}
}

module.exports = {
showOpenDialog: function (...args) {
checkAppInitialized()

let [window, options, callback] = parseArgs(...args)

if (options == null) {
options = {
title: 'Open',
properties: ['openFile']
}
}

let { buttonLabel, defaultPath, filters, properties, title, message, securityScopedBookmarks = false } = options

if (properties == null) {
properties = ['openFile']
} else if (!Array.isArray(properties)) {
throw new TypeError('Properties must be an array')
}

let dialogProperties = 0
for (const prop in fileDialogProperties) {
if (properties.includes(prop)) {
dialogProperties |= fileDialogProperties[prop]
}
}

if (title == null) {
title = ''
} else if (typeof title !== 'string') {
throw new TypeError('Title must be a string')
const openDialog = (async, window, options) => {
checkAppInitialized()

if (window.constructor !== BrowserWindow) options = window
if (options == null) {
options = {
title: 'Open',
properties: ['openFile']
}
}

if (buttonLabel == null) {
buttonLabel = ''
} else if (typeof buttonLabel !== 'string') {
throw new TypeError('Button label must be a string')
const {
buttonLabel = '',
defaultPath = '',
filters = [],
properties = ['openFile'],
title = '',
message = '',
securityScopedBookmarks = false
} = options

if (!Array.isArray(properties)) throw new TypeError('Properties must be an array')

let dialogProperties = 0
for (const prop in fileDialogProperties) {
if (properties.includes(prop)) {
dialogProperties |= fileDialogProperties[prop]
}
}

if (defaultPath == null) {
defaultPath = ''
} else if (typeof defaultPath !== 'string') {
throw new TypeError('Default path must be a string')
}
if (typeof title !== 'string') throw new TypeError('Title must be a string')
if (typeof buttonLabel !== 'string') throw new TypeError('Button label must be a string')
if (typeof defaultPath !== 'string') throw new TypeError('Default path must be a string')
if (typeof message !== 'string') throw new TypeError('Message must be a string')

if (filters == null) {
filters = []
}
const settings = { title, buttonLabel, defaultPath, filters, message, securityScopedBookmarks, window }
settings.properties = dialogProperties

if (message == null) {
message = ''
} else if (typeof message !== 'string') {
throw new TypeError('Message must be a string')
}
if (async) return binding.showOpenDialog(settings)
binding.showOpenDialog(settings)
}

const wrappedCallback = typeof callback === 'function' ? function (success, result, bookmarkData) {
return success ? callback(result, bookmarkData) : callback()
} : null
const settings = { title, buttonLabel, defaultPath, filters, message, securityScopedBookmarks, window }
settings.properties = dialogProperties
return binding.showOpenDialog(settings, wrappedCallback)
module.exports = {
showOpenDialog: function (window, options) {
return openDialog(true, window, options)
},
showOpenDialogSync: function (window, options) {
return openDialog(false, window, options)
},

showSaveDialog: function (...args) {
checkAppInitialized()

Expand Down

0 comments on commit f0169e8

Please sign in to comment.