Add atom.confirm, which displays a confirmation w/ buttons that fire callbacks

This communicates back to the browser process to display the confirmation, then the browser replies to the message with the index of the clicked button.
This commit is contained in:
Nathan Sobo
2012-08-29 18:31:49 -05:00
parent dfdcce9785
commit 725a6548fc
4 changed files with 57 additions and 7 deletions

View File

@@ -15,7 +15,9 @@ atom.sendMessageToBrowserProcess = (name, data, callback) ->
originalSendMessageToBrowserProcess(name, data)
atom.receiveMessageFromBrowserProcess = (name, data) ->
console.log "RECEIVE MESSAGE IN JS", name, data
if name is 'reply'
[messageId, callbackIndex] = data
@pendingBrowserProcessCallbacks[messageId]?[callbackIndex]?()
atom.open = (args...) ->
@sendMessageToBrowserProcess('open', args)
@@ -23,6 +25,14 @@ atom.open = (args...) ->
atom.newWindow = (args...) ->
@sendMessageToBrowserProcess('newWindow', args)
atom.confirm = (message, detailedMessage, buttonLabelsAndCallbacks...) ->
args = [message, detailedMessage]
callbacks = []
while buttonLabelsAndCallbacks.length
args.push(buttonLabelsAndCallbacks.shift())
callbacks.push(buttonLabelsAndCallbacks.shift())
@sendMessageToBrowserProcess('confirm', args, callbacks)
atom.getRootViewStateForPath = (path) ->
if json = localStorage[path]
JSON.parse(json)