Trigger 'window:close' command in the 'beforeunload' event handler.

When user wants to close the window, the 'beforeunload' event would be
called, then the closing would be cancelled and the 'window:close'
command would be triggered. In the 'window:close' handler, a confirm
dialog could be showed if there are unsaved contents, and if the window
is really meant to be closed, the window would be tried to be closed
again and this time 'beforeunload' handler wont't prevent it.
This commit is contained in:
Cheng Zhao
2013-05-17 20:09:36 +08:00
parent acf5e21f50
commit f0448ba231

View File

@@ -110,6 +110,11 @@ window.unloadConfigWindow = ->
$(window).off('focus blur before')
window.handleEvents = ->
$(window).on 'beforeunload', ->
unless windowIsClosing?
$(window).trigger 'window:close'
false
$(window).command 'window:toggle-full-screen', => atom.toggleFullScreen()
$(window).on 'focus', -> $("body").removeClass('is-blurred')
$(window).on 'blur', -> $("body").addClass('is-blurred')
@@ -271,7 +276,11 @@ window.profile = (description, fn) ->
# Public: Shows a dialog asking if the window was _really_ meant to be closed.
confirmClose = ->
if rootView?
rootView.confirmClose().done -> window.close()
else
close = ->
window.windowIsClosing = true
window.close()
if rootView?
rootView.confirmClose().done -> close()
else
close()