fdo#73773: Check if the *document* is closing, not the *app*.

Otherwise it would crash if the app has multiple document instances open
and only one of them is being closed.

Change-Id: Ib6e370037ab6097c9c6eff8035249663944b3a6c