X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fpbd%2Fstateful_diff_command.cc;h=e3a65ffc12c69f5551c5d10fc9d7353ffd199056;hb=c4fcb12d128857a0eaab7d2093d38fdf4cc641cc;hp=857235b803dd612b464b1529ac11c0e153be7dbd;hpb=7b2975244165b4ffd1dcf4080c1be4c8dcbc6708;p=ardour.git diff --git a/libs/pbd/stateful_diff_command.cc b/libs/pbd/stateful_diff_command.cc index 857235b803..e3a65ffc12 100644 --- a/libs/pbd/stateful_diff_command.cc +++ b/libs/pbd/stateful_diff_command.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2010 Paul Davis + Copyright (C) 2010 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 @@ -17,27 +17,25 @@ */ -#include - #include "pbd/stateful_diff_command.h" +#include "pbd/types_convert.h" #include "pbd/property_list.h" #include "pbd/demangle.h" -#include "i18n.h" +#include "pbd/i18n.h" using namespace std; using namespace PBD; /** Create a new StatefulDiffCommand by examining the changes made to a Stateful - * since the last time that clear_history was called on it. + * since the last time that clear_changes was called on it. * @param s Stateful object. */ StatefulDiffCommand::StatefulDiffCommand (boost::shared_ptr s) : _object (s) - , _undo (new PropertyList) - , _redo (new PropertyList) + , _changes (0) { - s->diff (*_undo, *_redo, this); + _changes = s->get_changes_as_properties (this); /* if the stateful object that this command refers to goes away, be sure to notify owners of this command. @@ -48,21 +46,17 @@ StatefulDiffCommand::StatefulDiffCommand (boost::shared_ptr s, XMLNode const & n) : _object (s) - , _undo (0) - , _redo (0) + , _changes (0) { const XMLNodeList& children (n.children()); for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) { - if ((*i)->name() == X_("Undo")) { - _undo = s->property_factory (**i); - } else if ((*i)->name() == X_("Do")) { - _redo = s->property_factory (**i); + if ((*i)->name() == X_("Changes")) { + _changes = s->property_factory (**i); } - } + } - assert (_undo != 0); - assert (_redo != 0); + assert (_changes != 0); /* if the stateful object that this command refers to goes away, be sure to notify owners of this command. @@ -75,8 +69,7 @@ StatefulDiffCommand::~StatefulDiffCommand () { drop_references (); - delete _undo; - delete _redo; + delete _changes; } void @@ -85,7 +78,7 @@ StatefulDiffCommand::operator() () boost::shared_ptr s (_object.lock()); if (s) { - s->apply_changes (*_redo); + s->apply_changes (*_changes); } } @@ -95,8 +88,9 @@ StatefulDiffCommand::undo () boost::shared_ptr s (_object.lock()); if (s) { - std::cerr << "Undoing a stateful diff command\n"; - s->apply_changes (*_undo); + PropertyList p = *_changes; + p.invert (); + s->apply_changes (p); } } @@ -112,17 +106,20 @@ StatefulDiffCommand::get_state () XMLNode* node = new XMLNode (X_("StatefulDiffCommand")); - node->add_property ("obj-id", s->id().to_s()); - node->add_property ("type-name", demangled_name (*s.get())); + node->set_property ("obj-id", s->id()); + node->set_property ("type-name", demangled_name (*s.get())); + + XMLNode* changes = new XMLNode (X_("Changes")); - XMLNode* undo = new XMLNode (X_("Undo")); - XMLNode* redo = new XMLNode (X_("Do")); + _changes->get_changes_as_xml (changes); - _undo->get_changes (undo); - _redo->get_changes (redo); - - node->add_child_nocopy (*undo); - node->add_child_nocopy (*redo); + node->add_child_nocopy (*changes); return *node; } + +bool +StatefulDiffCommand::empty () const +{ + return _changes->empty(); +}