diff options
Diffstat (limited to 'libs/pbd/undo.cc')
-rw-r--r-- | libs/pbd/undo.cc | 42 |
1 files changed, 36 insertions, 6 deletions
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 */ } |