From 85e22c0709591896c7c5824fbe52d19d0962bb7e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 10 May 2013 21:19:13 +0800 Subject: [PATCH] Expose dialog.showMessageBox API. --- browser/api/lib/dialog.coffee | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/browser/api/lib/dialog.coffee b/browser/api/lib/dialog.coffee index 04e289eae31b..a5b2ecf85437 100644 --- a/browser/api/lib/dialog.coffee +++ b/browser/api/lib/dialog.coffee @@ -2,6 +2,7 @@ binding = process.atomBinding 'dialog' CallbacksRegistry = require 'callbacks_registry' EventEmitter = require('events').EventEmitter ipc = require 'ipc' +Window = require 'window' FileDialog = binding.FileDialog FileDialog.prototype.__proto__ = EventEmitter.prototype @@ -33,7 +34,7 @@ validateOptions = (options) -> true selectFileWrap = (window, options, callback, type, title) -> - throw new TypeError('Need Window object') unless window.constructor?.name is 'Window' + throw new TypeError('Need Window object') unless window.constructor is Window options = {} unless options? options.type = type @@ -64,3 +65,26 @@ module.exports = openMultiFiles: (args...) -> selectFileWrap args..., 4, 'Open Files' + + showMessageBox: (window, options) -> + throw new TypeError('Need Window object') unless window.constructor is Window + + options = {} unless options? + options.type = options.type ? module.exports.MESSAGE_BOX_NONE + throw new TypeError('Invalid message box type') unless 0 <= options.type <= 2 + + throw new TypeError('Buttons need to be array') unless Array.isArray options.buttons + + options.title = options.title ? '' + options.message = options.message ? '' + options.detail = options.detail ? '' + + binding.showMessageBox window, options.type, options.buttons, + String(options.title), + String(options.message), + String(options.detail) + + # Message box types: + MESSAGE_BOX_NONE: 0 + MESSAGE_BOX_INFORMATION: 1 + MESSAGE_BOX_WARNING: 2