Fix crash when saving a modified document on closing the last window
If we close the last window, but are still saving a document, we'll
crash because the application will be quitting while the saving code
is still going on.
bug:294235
bug:292620
bug:293601