summaryrefslogtreecommitdiff
path: root/libs/pbd
diff options
context:
space:
mode:
authorHans Fugal <hans@fugal.net>2006-08-09 14:15:05 +0000
committerHans Fugal <hans@fugal.net>2006-08-09 14:15:05 +0000
commitc26215c1e59b6341da86f94f5b2b3ca950dd3889 (patch)
treeaded41982da1aae24d553407595a3dc7482c3ac7 /libs/pbd
parent5fc16bf95f43c816cbabbc594f826d1d934adbd4 (diff)
r283@gandalf: fugalh | 2006-08-09 08:13:37 -0600
Save state basics, including adding PBD::ID to the delinquents. Compiles but needs to be tested (because I can't get the whole thing to compile on OSX due to the Rect problem). git-svn-id: svn://localhost/ardour2/branches/undo@769 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/pbd')
-rw-r--r--libs/pbd/command.cc2
-rw-r--r--libs/pbd/id.cc8
-rw-r--r--libs/pbd/pbd/id.h1
-rw-r--r--libs/pbd/pbd/memento_command.h21
-rw-r--r--libs/pbd/pbd/undo.h2
-rw-r--r--libs/pbd/undo.cc18
6 files changed, 39 insertions, 13 deletions
diff --git a/libs/pbd/command.cc b/libs/pbd/command.cc
index c0fcf36187..5b41691c07 100644
--- a/libs/pbd/command.cc
+++ b/libs/pbd/command.cc
@@ -5,6 +5,6 @@
XMLNode &Command::get_state()
{
XMLNode *node = new XMLNode ("Command");
- // TODO
+ node->add_content("WARNING: Somebody forgot to subclass Command.");
return *node;
}
diff --git a/libs/pbd/id.cc b/libs/pbd/id.cc
index f9afa72c98..0de0d052c3 100644
--- a/libs/pbd/id.cc
+++ b/libs/pbd/id.cc
@@ -8,6 +8,7 @@
#include <inttypes.h>
#include <pbd/id.h>
+#include <string>
using namespace std;
using namespace PBD;
@@ -45,6 +46,13 @@ ID::print (char* buf) const
snprintf (buf, 16, "%" PRIu64, id);
}
+string ID::to_s() const
+{
+ char buf[16]; // see print()
+ print(buf);
+ return string(buf);
+}
+
ID&
ID::operator= (string str)
{
diff --git a/libs/pbd/pbd/id.h b/libs/pbd/pbd/id.h
index 9a3f10478d..1ce448d58b 100644
--- a/libs/pbd/pbd/id.h
+++ b/libs/pbd/pbd/id.h
@@ -28,6 +28,7 @@ class ID {
}
void print (char* buf) const;
+ std::string to_s() const;
static uint64_t counter() { return _counter; }
static void init_counter (uint64_t val) { _counter = val; }
diff --git a/libs/pbd/pbd/memento_command.h b/libs/pbd/pbd/memento_command.h
index a86006a6ae..46c724e9ea 100644
--- a/libs/pbd/pbd/memento_command.h
+++ b/libs/pbd/pbd/memento_command.h
@@ -22,6 +22,7 @@
#define __lib_pbd_memento_command_h__
#include <pbd/command.h>
+#include <pbd/xml++.h>
#include <sigc++/slot.h>
/** This command class is initialized with before and after mementos
@@ -42,9 +43,9 @@ class MementoCommand : public Command
virtual XMLNode &get_state()
{
XMLNode *node = new XMLNode("MementoCommand");
- // obj.id
- // key is "MementoCommand" or something
- // before and after mementos
+ node->add_property("obj_id", obj.id().to_s());
+ node->add_child_nocopy(before);
+ node->add_child_nocopy(after);
return *node;
}
// TODO does this need a copy constructor?
@@ -64,10 +65,9 @@ public:
void undo() { obj.set_state(before); }
virtual XMLNode &get_state()
{
- XMLNode *node = new XMLNode("MementoUndoCommand"); // XXX
- // obj.id
- // key is "MementoCommand" or something
- // before and after mementos
+ XMLNode *node = new XMLNode("MementoUndoCommand");
+ node->add_property("obj_id", obj.id().to_s());
+ node->add_child_nocopy(before);
return *node;
}
protected:
@@ -86,10 +86,9 @@ public:
void undo() { /* noop */ }
virtual XMLNode &get_state()
{
- XMLNode *node = new XMLNode("MementoUndoCommand");
- // obj.id
- // key is "MementoCommand" or something
- // before and after mementos
+ XMLNode *node = new XMLNode("MementoRedoCommand");
+ node->add_property("obj_id", obj.id().to_s());
+ node->add_child_nocopy(after);
return *node;
}
protected:
diff --git a/libs/pbd/pbd/undo.h b/libs/pbd/pbd/undo.h
index 49ff19ccce..724e86aaa0 100644
--- a/libs/pbd/pbd/undo.h
+++ b/libs/pbd/pbd/undo.h
@@ -90,6 +90,8 @@ class UndoHistory
void clear_undo ();
void clear_redo ();
+ XMLNode &get_state();
+ void save_state();
private:
list<UndoTransaction> UndoList;
list<UndoTransaction> RedoList;
diff --git a/libs/pbd/undo.cc b/libs/pbd/undo.cc
index a5ca6b713a..8d1b416c16 100644
--- a/libs/pbd/undo.cc
+++ b/libs/pbd/undo.cc
@@ -22,6 +22,7 @@
#include <pbd/undo.h>
#include <pbd/xml++.h>
+#include <string>
using namespace std;
using namespace sigc;
@@ -86,7 +87,11 @@ UndoTransaction::redo ()
XMLNode &UndoTransaction::get_state()
{
XMLNode *node = new XMLNode ("UndoTransaction");
- // TODO
+
+ list<Command*>::iterator it;
+ for (it=actions.begin(); it!=actions.end(); it++)
+ node->add_child_nocopy((*it)->get_state());
+
return *node;
}
@@ -142,3 +147,14 @@ UndoHistory::clear ()
RedoList.clear ();
UndoList.clear ();
}
+
+XMLNode & UndoHistory::get_state()
+{
+ XMLNode *node = new XMLNode ("UndoHistory");
+
+ list<UndoTransaction>::iterator it;
+ for (it=UndoList.begin(); it != UndoList.end(); it++)
+ node->add_child_nocopy(it->get_state());
+
+ return *node;
+}