Proposed fix for the activedocument management.

Second try at a decent pull request.
We probably want an OnDocumentActivate event instead.