2005-05-13 16:47:18 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2001 Brett Viren & Paul Davis
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <pbd/undo.h>
|
2006-08-09 10:14:17 -04:00
|
|
|
#include <pbd/xml++.h>
|
2005-05-13 16:47:18 -04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace sigc;
|
|
|
|
|
2006-06-15 14:21:31 -04:00
|
|
|
UndoTransaction::UndoTransaction ()
|
2005-05-13 16:47:18 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-06-15 14:21:31 -04:00
|
|
|
UndoTransaction::UndoTransaction (const UndoTransaction& rhs)
|
2005-05-13 16:47:18 -04:00
|
|
|
{
|
|
|
|
_name = rhs._name;
|
|
|
|
clear ();
|
2006-06-29 14:49:03 -04:00
|
|
|
actions.insert(actions.end(),rhs.actions.begin(),rhs.actions.end());
|
2005-05-13 16:47:18 -04:00
|
|
|
}
|
|
|
|
|
2006-06-15 14:21:31 -04:00
|
|
|
UndoTransaction&
|
|
|
|
UndoTransaction::operator= (const UndoTransaction& rhs)
|
2005-05-13 16:47:18 -04:00
|
|
|
{
|
|
|
|
if (this == &rhs) return *this;
|
|
|
|
_name = rhs._name;
|
|
|
|
clear ();
|
2006-06-29 14:49:03 -04:00
|
|
|
actions.insert(actions.end(),rhs.actions.begin(),rhs.actions.end());
|
2005-05-13 16:47:18 -04:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-07-28 23:17:11 -04:00
|
|
|
UndoTransaction::add_command (Command *const action)
|
2005-05-13 16:47:18 -04:00
|
|
|
{
|
2006-06-29 14:49:03 -04:00
|
|
|
actions.push_back (action);
|
2005-05-13 16:47:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-06-29 14:49:03 -04:00
|
|
|
UndoTransaction::clear ()
|
2005-05-13 16:47:18 -04:00
|
|
|
{
|
2006-06-29 14:49:03 -04:00
|
|
|
actions.clear ();
|
2005-05-13 16:47:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-06-29 14:49:03 -04:00
|
|
|
UndoTransaction::operator() ()
|
2005-05-13 16:47:18 -04:00
|
|
|
{
|
2006-07-28 23:17:11 -04:00
|
|
|
for (list<Command*>::iterator i = actions.begin(); i != actions.end(); ++i) {
|
|
|
|
(*(*i))();
|
2006-06-29 14:49:03 -04:00
|
|
|
}
|
2005-05-13 16:47:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-06-15 14:21:31 -04:00
|
|
|
UndoTransaction::undo ()
|
2005-05-13 16:47:18 -04:00
|
|
|
{
|
2006-05-30 22:46:04 -04:00
|
|
|
cerr << "Undo " << _name << endl;
|
2006-07-28 23:17:11 -04:00
|
|
|
for (list<Command*>::reverse_iterator i = actions.rbegin(); i != actions.rend(); ++i) {
|
|
|
|
(*i)->undo();
|
2005-05-13 16:47:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-06-15 14:21:31 -04:00
|
|
|
UndoTransaction::redo ()
|
2005-05-13 16:47:18 -04:00
|
|
|
{
|
2006-05-30 22:46:04 -04:00
|
|
|
cerr << "Redo " << _name << endl;
|
2006-06-29 14:49:03 -04:00
|
|
|
(*this)();
|
2005-05-13 16:47:18 -04:00
|
|
|
}
|
|
|
|
|
2006-08-09 10:14:17 -04:00
|
|
|
XMLNode &UndoTransaction::get_state()
|
2006-08-03 17:54:14 -04:00
|
|
|
{
|
|
|
|
XMLNode *node = new XMLNode ("UndoTransaction");
|
|
|
|
// TODO
|
|
|
|
return *node;
|
|
|
|
}
|
|
|
|
|
2005-05-13 16:47:18 -04:00
|
|
|
void
|
2006-06-15 14:21:31 -04:00
|
|
|
UndoHistory::add (UndoTransaction ut)
|
2005-05-13 16:47:18 -04:00
|
|
|
{
|
2006-06-15 14:21:31 -04:00
|
|
|
UndoList.push_back (ut);
|
2005-05-13 16:47:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UndoHistory::undo (unsigned int n)
|
|
|
|
{
|
|
|
|
while (n--) {
|
|
|
|
if (UndoList.size() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2006-06-15 14:21:31 -04:00
|
|
|
UndoTransaction ut = UndoList.back ();
|
2005-05-13 16:47:18 -04:00
|
|
|
UndoList.pop_back ();
|
2006-06-15 14:21:31 -04:00
|
|
|
ut.undo ();
|
|
|
|
RedoList.push_back (ut);
|
2005-05-13 16:47:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UndoHistory::redo (unsigned int n)
|
|
|
|
{
|
|
|
|
while (n--) {
|
|
|
|
if (RedoList.size() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2006-06-29 14:49:03 -04:00
|
|
|
UndoTransaction ut = RedoList.back ();
|
2005-05-13 16:47:18 -04:00
|
|
|
RedoList.pop_back ();
|
2006-06-29 14:49:03 -04:00
|
|
|
ut.redo ();
|
2006-07-28 23:17:11 -04:00
|
|
|
UndoList.push_back (ut);
|
2005-05-13 16:47:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UndoHistory::clear_redo ()
|
|
|
|
{
|
|
|
|
RedoList.clear ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UndoHistory::clear_undo ()
|
|
|
|
{
|
|
|
|
UndoList.clear ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UndoHistory::clear ()
|
|
|
|
{
|
|
|
|
RedoList.clear ();
|
|
|
|
UndoList.clear ();
|
|
|
|
}
|