Make sure active tool is deactivated before closing the document
When a document is closed, its canvas gets destroyed. The problem is
that the tools get destroyed in active state. That might be not very
obvious from API point of view.
NOTE1: do *not* backport it to 4.2, the patch is too dangerous
NOTE2: this patch is *not* a fix for 407228, it is just related
CCBUG:407228