The class DocumentUndoGuard is a scope guard to protect a document's
Undo manager state.
For instance, if some external script code is called which operates on
a document, and potentially tampers with the document's Undo Manager,
then it is possible that the manager is left inconsistent. The
DocumentUndoGuard protects the Undo Manager (to some extent), by at
least ensuring that XUndoManager::enterUndoContext calls are matched
by respective XUndoManager::leaveUndoContext calls.
All places which today call an external script, and where this is
reasonable (which excludes, for instance, execution of Basic scripts
from with cell formulas), have been pampered with an
DocumentUndoGuard. If you introduce new such places in the future,
please consider using the guard as well.