restore "unsaved changes" warning on unload

Autosave is triggered at this event, but it seems to fail sometimes
(perhaps when it's too slow?).

closes #3475

This is only one commit, depends on #3450.