Added better undo grouping and handling.
Added dirty detection and warning on image open/prev/next.