2013-05-03 13:03:26 +00:00
|
|
|
binding = process.atomBinding 'dialog'
|
2013-09-24 10:01:12 +00:00
|
|
|
v8Util = process.atomBinding 'v8_util'
|
2013-05-30 12:16:54 +00:00
|
|
|
BrowserWindow = require 'browser-window'
|
2013-05-03 11:31:24 +00:00
|
|
|
|
2013-05-20 13:46:43 +00:00
|
|
|
fileDialogProperties =
|
|
|
|
openFile: 1, openDirectory: 2, multiSelections: 4, createDirectory: 8
|
2013-05-03 11:31:24 +00:00
|
|
|
|
2013-05-20 13:46:43 +00:00
|
|
|
messageBoxTypes = ['none', 'info', 'warning']
|
2013-05-03 11:31:24 +00:00
|
|
|
|
2013-05-20 13:46:43 +00:00
|
|
|
module.exports =
|
2013-09-23 08:36:33 +00:00
|
|
|
showOpenDialog: (window, options, callback) ->
|
2013-09-23 08:51:00 +00:00
|
|
|
unless window?.constructor is BrowserWindow
|
2013-09-23 08:36:33 +00:00
|
|
|
# Shift.
|
|
|
|
callback = options
|
|
|
|
options = window
|
|
|
|
window = null
|
|
|
|
|
2013-09-23 08:51:00 +00:00
|
|
|
options ?= title: 'Open', properties: ['openFile']
|
|
|
|
options.properties ?= ['openFile']
|
2013-05-20 13:46:43 +00:00
|
|
|
throw new TypeError('Properties need to be array') unless Array.isArray options.properties
|
2013-05-03 11:31:24 +00:00
|
|
|
|
2013-05-20 13:46:43 +00:00
|
|
|
properties = 0
|
|
|
|
for prop, value of fileDialogProperties
|
|
|
|
properties |= value if prop in options.properties
|
2013-05-05 12:24:20 +00:00
|
|
|
|
2013-09-23 08:51:00 +00:00
|
|
|
options.title ?= ''
|
|
|
|
options.defaultPath ?= ''
|
2013-05-18 02:41:43 +00:00
|
|
|
|
2013-09-23 08:51:00 +00:00
|
|
|
binding.showOpenDialog String(options.title),
|
|
|
|
String(options.defaultPath),
|
2013-09-23 08:36:33 +00:00
|
|
|
properties,
|
2013-09-23 11:23:49 +00:00
|
|
|
window,
|
|
|
|
callback
|
2013-05-05 12:24:20 +00:00
|
|
|
|
2013-09-23 11:59:00 +00:00
|
|
|
showSaveDialog: (window, options, callback) ->
|
|
|
|
unless window?.constructor is BrowserWindow
|
|
|
|
# Shift.
|
|
|
|
callback = options
|
|
|
|
options = window
|
|
|
|
window = null
|
2013-05-05 12:24:20 +00:00
|
|
|
|
2013-09-23 08:51:00 +00:00
|
|
|
options ?= title: 'Save'
|
|
|
|
options.title ?= ''
|
|
|
|
options.defaultPath ?= ''
|
2013-05-05 12:24:20 +00:00
|
|
|
|
2013-09-23 11:59:00 +00:00
|
|
|
binding.showSaveDialog String(options.title),
|
|
|
|
String(options.defaultPath),
|
|
|
|
window,
|
|
|
|
callback
|
2013-05-10 13:19:13 +00:00
|
|
|
|
2013-09-23 06:29:55 +00:00
|
|
|
showMessageBox: (window, options, callback) ->
|
2013-09-23 08:51:00 +00:00
|
|
|
unless window?.constructor is BrowserWindow
|
2013-09-23 06:29:55 +00:00
|
|
|
# Shift.
|
|
|
|
callback = options
|
2013-06-07 07:59:12 +00:00
|
|
|
options = window
|
|
|
|
window = null
|
|
|
|
|
2013-09-23 08:51:00 +00:00
|
|
|
options ?= type: 'none'
|
|
|
|
options.type ?= 'none'
|
2013-05-18 02:41:43 +00:00
|
|
|
options.type = messageBoxTypes.indexOf options.type
|
|
|
|
throw new TypeError('Invalid message box type') unless options.type > -1
|
2013-05-10 13:19:13 +00:00
|
|
|
|
|
|
|
throw new TypeError('Buttons need to be array') unless Array.isArray options.buttons
|
|
|
|
|
2013-09-23 08:51:00 +00:00
|
|
|
options.title ?= ''
|
|
|
|
options.message ?= ''
|
|
|
|
options.detail ?= ''
|
2013-05-10 13:19:13 +00:00
|
|
|
|
2013-06-07 07:59:12 +00:00
|
|
|
binding.showMessageBox options.type,
|
|
|
|
options.buttons,
|
2013-05-10 13:19:13 +00:00
|
|
|
String(options.title),
|
|
|
|
String(options.message),
|
2013-06-07 07:59:12 +00:00
|
|
|
String(options.detail),
|
2013-09-23 06:29:55 +00:00
|
|
|
window,
|
|
|
|
callback
|
2013-09-24 10:01:12 +00:00
|
|
|
|
|
|
|
# Mark standard asynchronous functions.
|
|
|
|
v8Util.setHiddenValue f, 'asynchronous', true for k, f of module.exports
|