2 Copyright (C) 2001 Brett Viren & Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <pbd/xml++.h>
31 UndoTransaction::UndoTransaction ()
35 UndoTransaction::UndoTransaction (const UndoTransaction& rhs)
39 actions.insert(actions.end(),rhs.actions.begin(),rhs.actions.end());
43 UndoTransaction::operator= (const UndoTransaction& rhs)
45 if (this == &rhs) return *this;
48 actions.insert(actions.end(),rhs.actions.begin(),rhs.actions.end());
53 UndoTransaction::add_command (Command *const action)
55 actions.push_back (action);
59 UndoTransaction::clear ()
65 UndoTransaction::operator() ()
67 for (list<Command*>::iterator i = actions.begin(); i != actions.end(); ++i) {
73 UndoTransaction::undo ()
75 cerr << "Undo " << _name << endl;
76 for (list<Command*>::reverse_iterator i = actions.rbegin(); i != actions.rend(); ++i) {
82 UndoTransaction::redo ()
84 cerr << "Redo " << _name << endl;
88 XMLNode &UndoTransaction::get_state()
90 XMLNode *node = new XMLNode ("UndoTransaction");
92 ss << _timestamp.tv_sec;
93 node->add_property("tv_sec", ss.str());
95 ss << _timestamp.tv_usec;
96 node->add_property("tv_usec", ss.str());
97 node->add_property("name", _name);
99 list<Command*>::iterator it;
100 for (it=actions.begin(); it!=actions.end(); it++)
101 node->add_child_nocopy((*it)->get_state());
107 UndoHistory::add (UndoTransaction ut)
109 UndoList.push_back (ut);
113 UndoHistory::undo (unsigned int n)
116 if (UndoList.size() == 0) {
119 UndoTransaction ut = UndoList.back ();
120 UndoList.pop_back ();
122 RedoList.push_back (ut);
127 UndoHistory::redo (unsigned int n)
130 if (RedoList.size() == 0) {
133 UndoTransaction ut = RedoList.back ();
134 RedoList.pop_back ();
136 UndoList.push_back (ut);
141 UndoHistory::clear_redo ()
147 UndoHistory::clear_undo ()
153 UndoHistory::clear ()
159 XMLNode & UndoHistory::get_state()
161 XMLNode *node = new XMLNode ("UndoHistory");
163 list<UndoTransaction>::iterator it;
164 for (it=UndoList.begin(); it != UndoList.end(); it++)
165 node->add_child_nocopy(it->get_state());