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.
26 #include <pbd/xml++.h>
28 #include <sigc++/bind.h>
33 UndoTransaction::UndoTransaction ()
38 UndoTransaction::UndoTransaction (const UndoTransaction& rhs)
43 actions.insert(actions.end(),rhs.actions.begin(),rhs.actions.end());
46 UndoTransaction::~UndoTransaction ()
53 UndoTransaction::operator= (const UndoTransaction& rhs)
55 if (this == &rhs) return *this;
58 actions.insert(actions.end(),rhs.actions.begin(),rhs.actions.end());
63 UndoTransaction::add_command (Command *const action)
65 action->GoingAway.connect (bind (mem_fun (*this, &UndoTransaction::remove_command), action));
66 actions.push_back (action);
70 UndoTransaction::remove_command (Command* const action)
75 actions.remove (action);
76 if (actions.empty()) {
82 UndoTransaction::clear ()
85 for (list<Command*>::iterator i = actions.begin(); i != actions.end(); ++i) {
93 UndoTransaction::operator() ()
95 for (list<Command*>::iterator i = actions.begin(); i != actions.end(); ++i) {
101 UndoTransaction::undo ()
103 for (list<Command*>::reverse_iterator i = actions.rbegin(); i != actions.rend(); ++i) {
109 UndoTransaction::redo ()
114 XMLNode &UndoTransaction::get_state()
116 XMLNode *node = new XMLNode ("UndoTransaction");
118 ss << _timestamp.tv_sec;
119 node->add_property("tv_sec", ss.str());
121 ss << _timestamp.tv_usec;
122 node->add_property("tv_usec", ss.str());
123 node->add_property("name", _name);
125 list<Command*>::iterator it;
126 for (it=actions.begin(); it!=actions.end(); it++)
127 node->add_child_nocopy((*it)->get_state());
132 UndoHistory::UndoHistory ()
138 UndoHistory::add (UndoTransaction* const ut)
140 ut->GoingAway.connect (bind (mem_fun (*this, &UndoHistory::remove), ut));
141 UndoList.push_back (ut);
143 /* we are now owners of the transaction */
147 UndoHistory::remove (UndoTransaction* const ut)
153 UndoList.remove (ut);
154 RedoList.remove (ut);
158 UndoHistory::undo (unsigned int n)
161 if (UndoList.size() == 0) {
164 UndoTransaction* ut = UndoList.back ();
165 UndoList.pop_back ();
167 RedoList.push_back (ut);
172 UndoHistory::redo (unsigned int n)
175 if (RedoList.size() == 0) {
178 UndoTransaction* ut = RedoList.back ();
179 RedoList.pop_back ();
181 UndoList.push_back (ut);
186 UndoHistory::clear_redo ()
194 UndoHistory::clear_undo ()
202 UndoHistory::clear ()
208 XMLNode & UndoHistory::get_state()
210 XMLNode *node = new XMLNode ("UndoHistory");
212 list<UndoTransaction*>::iterator it;
213 for (it = UndoList.begin(); it != UndoList.end(); it++) {
214 node->add_child_nocopy((*it)->get_state());