Add serialization/deserialization support for the state stack.

This commit also implements the persistent undo/redo feature in the editor.