X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fpbd%2Fstateful_diff_command.cc;h=9e22f2bc649fcf14ded884b31bbe85955030285f;hb=cfe42bc4ea9a5a6234f43c173e14fdd89af39589;hp=bfd9f3344071a422c422bc3a08e94faa3673f0c0;hpb=3a85e71031bc26d67d66db985da2159415f84fdb;p=ardour.git diff --git a/libs/pbd/stateful_diff_command.cc b/libs/pbd/stateful_diff_command.cc index bfd9f33440..9e22f2bc64 100644 --- a/libs/pbd/stateful_diff_command.cc +++ b/libs/pbd/stateful_diff_command.cc @@ -17,8 +17,6 @@ */ -#include - #include "pbd/stateful_diff_command.h" #include "pbd/property_list.h" #include "pbd/demangle.h" @@ -28,41 +26,49 @@ 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) - , _before (new PropertyList) - , _after (new PropertyList) +StatefulDiffCommand::StatefulDiffCommand (boost::shared_ptr s) + : _object (s) + , _changes (0) { - s->diff (*_before, *_after); + _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. + */ + + s->DropReferences.connect_same_thread (*this, boost::bind (&Destructible::drop_references, this)); } -StatefulDiffCommand::StatefulDiffCommand (boost::shared_ptr s, XMLNode const & n) +StatefulDiffCommand::StatefulDiffCommand (boost::shared_ptr s, XMLNode const & n) : _object (s) - , _before (0) - , _after (0) + , _changes (0) { const XMLNodeList& children (n.children()); for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) { - if ((*i)->name() == X_("Undo")) { - _before = s->property_factory (**i); - } else if ((*i)->name() == X_("Do")) { - _after = s->property_factory (**i); + if ((*i)->name() == X_("Changes")) { + _changes = s->property_factory (**i); } - } + } + + assert (_changes != 0); + + /* if the stateful object that this command refers to goes away, + be sure to notify owners of this command. + */ - assert (_before != 0); - assert (_after != 0); + s->DropReferences.connect_same_thread (*this, boost::bind (&Destructible::drop_references, this)); } StatefulDiffCommand::~StatefulDiffCommand () { - delete _before; - delete _after; + drop_references (); + + delete _changes; } void @@ -71,10 +77,7 @@ StatefulDiffCommand::operator() () boost::shared_ptr s (_object.lock()); if (s) { - PropertyChange changed = s->set_properties (*_after); - if (!changed.empty()) { - s->PropertyChanged (changed); - } + s->apply_changes (*_changes); } } @@ -84,12 +87,9 @@ StatefulDiffCommand::undo () boost::shared_ptr s (_object.lock()); if (s) { - std::cerr << "Undoing a stateful diff command\n"; - PropertyChange changed = s->set_properties (*_before); - if (!changed.empty()) { - std::cerr << "Sending changed\n"; - s->PropertyChanged (changed); - } + PropertyList p = *_changes; + p.invert (); + s->apply_changes (p); } } @@ -108,14 +108,17 @@ StatefulDiffCommand::get_state () node->add_property ("obj-id", s->id().to_s()); node->add_property ("type-name", demangled_name (*s.get())); - XMLNode* before = new XMLNode (X_("Undo")); - XMLNode* after = new XMLNode (X_("Do")); + XMLNode* changes = new XMLNode (X_("Changes")); - _before->add_history_state (before); - _after->add_history_state (after); + _changes->get_changes_as_xml (changes); - node->add_child_nocopy (*before); - node->add_child_nocopy (*after); + node->add_child_nocopy (*changes); return *node; } + +bool +StatefulDiffCommand::empty () const +{ + return _changes->empty(); +}