summaryrefslogtreecommitdiff
path: root/libs/pbd/undo.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libs/pbd/undo.cc')
-rw-r--r--libs/pbd/undo.cc171
1 files changed, 84 insertions, 87 deletions
diff --git a/libs/pbd/undo.cc b/libs/pbd/undo.cc
index ab8607faff..4a4ca81a3a 100644
--- a/libs/pbd/undo.cc
+++ b/libs/pbd/undo.cc
@@ -21,31 +21,29 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include <string>
#include <sstream>
+#include <string>
#include <time.h>
#include "pbd/undo.h"
#include "pbd/xml++.h"
-#include <sigc++/bind.h>
-
using namespace std;
using namespace sigc;
UndoTransaction::UndoTransaction ()
- : _clearing(false)
+ : _clearing (false)
{
gettimeofday (&_timestamp, 0);
}
UndoTransaction::UndoTransaction (const UndoTransaction& rhs)
- : Command(rhs._name)
- , _clearing(false)
+ : Command (rhs._name)
+ , _clearing (false)
{
- _timestamp = rhs._timestamp;
+ _timestamp = rhs._timestamp;
clear ();
- actions.insert(actions.end(),rhs.actions.begin(),rhs.actions.end());
+ actions.insert (actions.end (), rhs.actions.begin (), rhs.actions.end ());
}
UndoTransaction::~UndoTransaction ()
@@ -57,13 +55,13 @@ UndoTransaction::~UndoTransaction ()
void
command_death (UndoTransaction* ut, Command* c)
{
- if (ut->clearing()) {
+ if (ut->clearing ()) {
return;
}
ut->remove_command (c);
- if (ut->empty()) {
+ if (ut->empty ()) {
delete ut;
}
}
@@ -71,19 +69,21 @@ command_death (UndoTransaction* ut, Command* c)
UndoTransaction&
UndoTransaction::operator= (const UndoTransaction& rhs)
{
- if (this == &rhs) return *this;
+ if (this == &rhs) {
+ return *this;
+ }
_name = rhs._name;
clear ();
- actions.insert(actions.end(),rhs.actions.begin(),rhs.actions.end());
+ actions.insert (actions.end (), rhs.actions.begin (), rhs.actions.end ());
return *this;
}
void
-UndoTransaction::add_command (Command *const cmd)
+UndoTransaction::add_command (Command* const cmd)
{
/* catch death of command (e.g. caused by death of object to
- which it refers. command_death() is a normal static function
- so there is no need to manage this connection.
+ * which it refers. command_death() is a normal static function
+ * so there is no need to manage this connection.
*/
cmd->DropReferences.connect_same_thread (*this, boost::bind (&command_death, this, cmd));
@@ -99,14 +99,14 @@ UndoTransaction::remove_command (Command* const action)
bool
UndoTransaction::empty () const
{
- return actions.empty();
+ return actions.empty ();
}
void
UndoTransaction::clear ()
{
_clearing = true;
- for (list<Command*>::iterator i = actions.begin(); i != actions.end(); ++i) {
+ for (list<Command*>::iterator i = actions.begin (); i != actions.end (); ++i) {
delete *i;
}
actions.clear ();
@@ -116,64 +116,69 @@ UndoTransaction::clear ()
void
UndoTransaction::operator() ()
{
- for (list<Command*>::iterator i = actions.begin(); i != actions.end(); ++i) {
- (*(*i))();
+ for (list<Command*>::iterator i = actions.begin (); i != actions.end (); ++i) {
+ (*(*i)) ();
}
}
void
UndoTransaction::undo ()
{
- for (list<Command*>::reverse_iterator i = actions.rbegin(); i != actions.rend(); ++i) {
- (*i)->undo();
+ for (list<Command*>::reverse_iterator i = actions.rbegin (); i != actions.rend (); ++i) {
+ (*i)->undo ();
}
}
void
UndoTransaction::redo ()
{
- (*this)();
+ (*this) ();
}
-XMLNode &UndoTransaction::get_state()
+XMLNode&
+UndoTransaction::get_state ()
{
- XMLNode *node = new XMLNode ("UndoTransaction");
- node->set_property("tv-sec", (int64_t)_timestamp.tv_sec);
- node->set_property("tv-usec", (int64_t)_timestamp.tv_usec);
- node->set_property("name", _name);
-
- list<Command*>::iterator it;
- for (it=actions.begin(); it!=actions.end(); it++)
- node->add_child_nocopy((*it)->get_state());
+ XMLNode* node = new XMLNode ("UndoTransaction");
+ node->set_property ("tv-sec", (int64_t)_timestamp.tv_sec);
+ node->set_property ("tv-usec", (int64_t)_timestamp.tv_usec);
+ node->set_property ("name", _name);
+
+ list<Command*>::iterator it;
+ for (it = actions.begin (); it != actions.end (); it++) {
+ node->add_child_nocopy ((*it)->get_state ());
+ }
- return *node;
+ return *node;
}
-class UndoRedoSignaller {
+class UndoRedoSignaller
+{
public:
- UndoRedoSignaller (UndoHistory& uh)
- : _history (uh) {
- _history.BeginUndoRedo();
- }
- ~UndoRedoSignaller() {
- _history.EndUndoRedo();
- }
+ UndoRedoSignaller (UndoHistory& uh)
+ : _history (uh)
+ {
+ _history.BeginUndoRedo ();
+ }
+
+ ~UndoRedoSignaller ()
+ {
+ _history.EndUndoRedo ();
+ }
private:
- UndoHistory& _history;
+ UndoHistory& _history;
};
UndoHistory::UndoHistory ()
{
_clearing = false;
- _depth = 0;
+ _depth = 0;
}
void
UndoHistory::set_depth (uint32_t d)
{
- UndoTransaction* ut;
- uint32_t current_depth = UndoList.size();
+ uint32_t current_depth = UndoList.size ();
_depth = d;
@@ -183,11 +188,10 @@ UndoHistory::set_depth (uint32_t d)
}
if (_depth > 0) {
-
uint32_t cnt = current_depth - d;
while (cnt--) {
- ut = UndoList.front();
+ UndoTransaction* ut = UndoList.front ();
UndoList.pop_front ();
delete ut;
}
@@ -197,17 +201,16 @@ UndoHistory::set_depth (uint32_t d)
void
UndoHistory::add (UndoTransaction* const ut)
{
- uint32_t current_depth = UndoList.size();
+ uint32_t current_depth = UndoList.size ();
ut->DropReferences.connect_same_thread (*this, boost::bind (&UndoHistory::remove, this, ut));
/* if the current undo history is larger than or equal to the currently
- requested depth, then pop off at least 1 element to make space
- at the back for new one.
- */
+ requested depth, then pop off at least 1 element to make space
+ at the back for new one.
+ */
if ((_depth > 0) && current_depth && (current_depth >= _depth)) {
-
uint32_t cnt = 1 + (current_depth - _depth);
while (cnt--) {
@@ -221,9 +224,9 @@ UndoHistory::add (UndoTransaction* const ut)
UndoList.push_back (ut);
/* Adding a transacrion makes the redo list meaningless. */
_clearing = true;
- for (std::list<UndoTransaction*>::iterator i = RedoList.begin(); i != RedoList.end(); ++i) {
- delete *i;
- }
+ for (std::list<UndoTransaction*>::iterator i = RedoList.begin (); i != RedoList.end (); ++i) {
+ delete *i;
+ }
RedoList.clear ();
_clearing = false;
@@ -259,7 +262,7 @@ UndoHistory::undo (unsigned int n)
UndoRedoSignaller exception_safe_signaller (*this);
while (n--) {
- if (UndoList.size() == 0) {
+ if (UndoList.size () == 0) {
return;
}
UndoTransaction* ut = UndoList.back ();
@@ -283,7 +286,7 @@ UndoHistory::redo (unsigned int n)
UndoRedoSignaller exception_safe_signaller (*this);
while (n--) {
- if (RedoList.size() == 0) {
+ if (RedoList.size () == 0) {
return;
}
UndoTransaction* ut = RedoList.back ();
@@ -300,23 +303,22 @@ void
UndoHistory::clear_redo ()
{
_clearing = true;
- for (std::list<UndoTransaction*>::iterator i = RedoList.begin(); i != RedoList.end(); ++i) {
- delete *i;
- }
+ for (std::list<UndoTransaction*>::iterator i = RedoList.begin (); i != RedoList.end (); ++i) {
+ delete *i;
+ }
RedoList.clear ();
_clearing = false;
Changed (); /* EMIT SIGNAL */
-
}
void
UndoHistory::clear_undo ()
{
_clearing = true;
- for (std::list<UndoTransaction*>::iterator i = UndoList.begin(); i != UndoList.end(); ++i) {
- delete *i;
- }
+ for (std::list<UndoTransaction*>::iterator i = UndoList.begin (); i != UndoList.end (); ++i) {
+ delete *i;
+ }
UndoList.clear ();
_clearing = false;
@@ -335,36 +337,31 @@ UndoHistory::clear ()
XMLNode&
UndoHistory::get_state (int32_t depth)
{
- XMLNode *node = new XMLNode ("UndoHistory");
-
- if (depth == 0) {
-
- return (*node);
+ XMLNode* node = new XMLNode ("UndoHistory");
- } else if (depth < 0) {
+ if (depth == 0) {
+ return (*node);
- /* everything */
+ } else if (depth < 0) {
+ /* everything */
- for (list<UndoTransaction*>::iterator it = UndoList.begin(); it != UndoList.end(); ++it) {
- node->add_child_nocopy((*it)->get_state());
- }
-
- } else {
+ for (list<UndoTransaction*>::iterator it = UndoList.begin (); it != UndoList.end (); ++it) {
+ node->add_child_nocopy ((*it)->get_state ());
+ }
- /* just the last "depth" transactions */
+ } else {
+ /* just the last "depth" transactions */
- list<UndoTransaction*> in_order;
+ list<UndoTransaction*> in_order;
- for (list<UndoTransaction*>::reverse_iterator it = UndoList.rbegin(); it != UndoList.rend() && depth; ++it, depth--) {
- in_order.push_front (*it);
- }
+ for (list<UndoTransaction*>::reverse_iterator it = UndoList.rbegin (); it != UndoList.rend () && depth; ++it, depth--) {
+ in_order.push_front (*it);
+ }
- for (list<UndoTransaction*>::iterator it = in_order.begin(); it != in_order.end(); it++) {
- node->add_child_nocopy((*it)->get_state());
- }
- }
+ for (list<UndoTransaction*>::iterator it = in_order.begin (); it != in_order.end (); it++) {
+ node->add_child_nocopy ((*it)->get_state ());
+ }
+ }
- return *node;
+ return *node;
}
-
-