Some code analysis fixes.
Undo manager refactoring: remove usage of undo buffer getter.
More undo manager refactoring.
Half-finalized refactoring and finally make undo for pasting images work.