# Undo/Redo System

All changes to a CongDocument should be done using CongCommand objects. Each `CongDocument` has a CongCommandHistory which stores all of the commands that have been applied to that command which can be undone, and all that can be redone.

In order to modify the document, you should do something like this:

    CongCommand *cmd = cong_document_begin_command (doc, _("User-visible name of command"), NULL);

    cong_command_add_modification_do_something (cmd, param1);
    cong_command_add_modification_do_something_else (cmd, param2, param3, param4);

    cong_document_end_command (doc, cmd);

All commands are built up of modifications, all of which break down into a small number of atomic modifications. Each type of modification corresponds to a subclass of CongModification, and contains enough information to be able to redo and undo the command

As the atomic modifications are done/undone, they call the appropriate `CongDocument` methods which have the word "private" in their names e.g. `cong_document_private_node_add_after`. These emit signals which are listened to by the various views, widgets etc. The CongDocument also handles the signal by calling a correspong cong_node_private function e.g. `cong_node_private_add_after`, which actual makes the change to the libxml2 representation of the document.