From f0448ba231c55be7cdb82cbdb20b864c4ece6db4 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 17 May 2013 20:09:36 +0800 Subject: [PATCH] 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. --- src/app/window.coffee | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/app/window.coffee b/src/app/window.coffee index b387a0701..c8929ce21 100644 --- a/src/app/window.coffee +++ b/src/app/window.coffee @@ -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()