document-undo.cpp revision 153bb1867986d6db392e2cfa711ad6231fce8abe
0N/A * Lauris Kaplinski <lauris@kaplinski.com> 919N/A * MenTaLguY <mental@rydia.net> 919N/A * Copyright (C) 2007 MenTaLguY <mental@rydia.net> 919N/A * Copyright (C) 1999-2003 authors 0N/A * Copyright (C) 2001-2002 Ximian, Inc. 919N/A * Released under GNU GPL, read the file 'COPYING' for more information 0N/A * Using the split document model gives sodipodi a very simple and clean 919N/A * undo implementation. Whenever mutation occurs in the XML tree, 919N/A * SPObject invokes one of the five corresponding handlers of its 919N/A * container document. This writes down a generic description of the 919N/A * given action, and appends it to the recent action list, kept by the 919N/A * document. There will be as many action records as there are mutation 919N/A * events, which are all kept and processed together in the undo 919N/A * stack. Two methods exist to indicate that the given action is completed: 0N/A void sp_document_done( SPDocument *document ); 0N/A void sp_document_maybe_done( SPDocument *document, const unsigned char *key ) \endverbatim 0N/A * Both move the recent action list into the undo stack and clear the 970N/A * list afterwards. While the first method does an unconditional push, 970N/A * the second one first checks the key of the most recent stack entry. If 970N/A * the keys are identical, the current action list is appended to the 0N/A * existing stack entry, instead of pushing it onto its own. This 0N/A * behaviour can be used to collect multi-step actions (like winding the 0N/A * Gtk spinbutton) from the UI into a single undoable step. 970N/A * For controls implemented by Sodipodi itself, implementing undo as a 493N/A * single step is usually done in a more efficent way. Most controls have 970N/A * the abstract model of grab, drag, release, and change user 0N/A * action. During the grab phase, all modifications are done to the 1003N/A * SPObject directly - i.e. they do not change XML tree, and thus do not 1003N/A * generate undo actions either. Only at the release phase (normally 1003N/A * associated with releasing the mousebutton), changes are written back 1003N/A * to the XML tree, thus generating only a single set of undo actions. 970N/A * as is shown above. Perhaps it makes sense to create new functions, 970N/A * undo_ignore, and undo_recall to replace the start and end parts of the above. 970N/A * The main complexity with this is that they have to nest, so you have to store 970N/A * the saved bools in a stack. Perhaps this is why the above solution is better. c-file-style:"stroustrup" c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :