Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit fef4547

Browse files
committed
Merge pull request #1107 from adobe/glenn/close-and-quit
Add fail handler to close and quit command handlers
2 parents 1fe4e06 + a61fb69 commit fef4547

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

src/document/DocumentCommandHandlers.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ define(function (require, exports, module) {
637637
* Common implementation for close/quit/reload which all mostly
638638
* the same except for the final step
639639
*/
640-
function _handleWindowGoingAway(commandData, postCloseHandler) {
640+
function _handleWindowGoingAway(commandData, postCloseHandler, failHandler) {
641641
if (_windowGoingAway) {
642642
//if we get called back while we're closing, then just return
643643
return (new $.Deferred()).resolve().promise();
@@ -653,22 +653,46 @@ define(function (require, exports, module) {
653653
_windowGoingAway = true;
654654
PreferencesManager.savePreferences();
655655
postCloseHandler();
656+
})
657+
.fail(function () {
658+
if (failHandler) {
659+
failHandler();
660+
}
656661
});
657662
}
658663

659664
/** Confirms any unsaved changes, then closes the window */
660665
function handleFileCloseWindow(commandData) {
661-
return _handleWindowGoingAway(commandData, function () {
662-
window.close();
663-
});
666+
return _handleWindowGoingAway(
667+
commandData,
668+
function () {
669+
window.close();
670+
},
671+
function () {
672+
// if fail, tell the app to abort any pending quit operation.
673+
// TODO: remove this if statement when we move to the new CEF3 shell
674+
if (brackets.app.abortQuit) {
675+
brackets.app.abortQuit();
676+
}
677+
}
678+
);
664679
}
665680

666681
/** Closes the window, then quits the app */
667682
function handleFileQuit(commandData) {
668-
return _handleWindowGoingAway(commandData, function () {
669-
brackets.app.quit();
670-
});
671-
// if fail, don't exit: user canceled (or asked us to save changes first, but we failed to do so)
683+
return _handleWindowGoingAway(
684+
commandData,
685+
function () {
686+
brackets.app.quit();
687+
},
688+
function () {
689+
// if fail, don't exit: user canceled (or asked us to save changes first, but we failed to do so)
690+
// TODO: remove this if statement when we move to the new CEF3 shell
691+
if (brackets.app.abortQuit) {
692+
brackets.app.abortQuit();
693+
}
694+
}
695+
);
672696
}
673697

674698
/** Does a full reload of the browser window */

0 commit comments

Comments
 (0)