mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user