summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2008-11-24 14:59:41 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2008-11-24 14:59:41 +0000
commitbee3c7a4190aa1adf035d5aee90bf7a602804096 (patch)
tree0c671993b91fb2ab301a4a24743997be75ae873c /libs
parentb6948a1bfa65702973e6461cb48c5f1d8cd2a9ff (diff)
tiny but massively important bug fix that actually deletes commands when they are removed from the unod history
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@4240 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs')
-rw-r--r--libs/pbd/command.cc1
-rw-r--r--libs/pbd/pbd/command.h2
-rw-r--r--libs/pbd/pbd/undo.h13
-rw-r--r--libs/pbd/undo.cc42
4 files changed, 47 insertions, 11 deletions
diff --git a/libs/pbd/command.cc b/libs/pbd/command.cc
index f84d99491f..d95c145084 100644
--- a/libs/pbd/command.cc
+++ b/libs/pbd/command.cc
@@ -20,7 +20,6 @@
#include <pbd/command.h>
#include <pbd/xml++.h>
-
XMLNode &Command::get_state()
{
XMLNode *node = new XMLNode ("Command");
diff --git a/libs/pbd/pbd/command.h b/libs/pbd/pbd/command.h
index 23bcf85b91..96393a0440 100644
--- a/libs/pbd/pbd/command.h
+++ b/libs/pbd/pbd/command.h
@@ -25,7 +25,7 @@
class Command : public PBD::StatefulDestructible
{
public:
- virtual ~Command() {}
+ virtual ~Command() { /* NOTE: derived classes must call drop_references() */ }
virtual void operator() () = 0;
virtual void undo() = 0;
virtual void redo() { (*this)(); }
diff --git a/libs/pbd/pbd/undo.h b/libs/pbd/pbd/undo.h
index fa53648b24..c5f60c51af 100644
--- a/libs/pbd/pbd/undo.h
+++ b/libs/pbd/pbd/undo.h
@@ -93,17 +93,24 @@ class UndoHistory : public sigc::trackable
void clear_undo ();
void clear_redo ();
+ /* returns all or part of the history.
+ If depth==0 it returns just the top
+ node. If depth<0, it returns everything.
+ If depth>0, it returns state for that
+ many elements of the history, or
+ the full history, whichever is smaller.
+ */
+
XMLNode &get_state(int32_t depth = 0);
void save_state();
- void set_depth (int32_t);
- int32_t get_depth() const { return _depth; }
+ void set_depth (uint32_t);
sigc::signal<void> Changed;
private:
bool _clearing;
- int32_t _depth;
+ uint32_t _depth;
std::list<UndoTransaction*> UndoList;
std::list<UndoTransaction*> RedoList;
diff --git a/libs/pbd/undo.cc b/libs/pbd/undo.cc
index 8823b2da64..43baad35d2 100644
--- a/libs/pbd/undo.cc
+++ b/libs/pbd/undo.cc
@@ -153,27 +153,57 @@ UndoHistory::UndoHistory ()
}
void
-UndoHistory::set_depth (int32_t d)
+UndoHistory::set_depth (uint32_t d)
{
+ UndoTransaction* ut;
+ uint32_t current_depth = UndoList.size();
+
_depth = d;
- while (_depth > 0 && UndoList.size() > (uint32_t) _depth) {
- UndoList.pop_front ();
+ if (d > current_depth) {
+ /* not even transactions to meet request */
+ return;
+ }
+
+ if (_depth > 0) {
+
+ uint32_t cnt = current_depth - d;
+
+ while (cnt--) {
+ ut = UndoList.front();
+ UndoList.pop_front ();
+ delete ut;
+ }
}
}
void
UndoHistory::add (UndoTransaction* const ut)
{
+ uint32_t current_depth = UndoList.size();
+
ut->GoingAway.connect (bind (mem_fun (*this, &UndoHistory::remove), ut));
- while (_depth > 0 && UndoList.size() > (uint32_t) _depth) {
- UndoList.pop_front ();
+ /* 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.
+ */
+
+ if ((_depth > 0) && current_depth && (current_depth >= _depth)) {
+
+ uint32_t cnt = 1 + (current_depth - _depth);
+
+ while (cnt--) {
+ UndoTransaction* ut;
+ ut = UndoList.front ();
+ UndoList.pop_front ();
+ delete ut;
+ }
}
UndoList.push_back (ut);
- /* we are now owners of the transaction */
+ /* we are now owners of the transaction and must delete it when finished with it */
Changed (); /* EMIT SIGNAL */
}