~UndoTransaction ();
void clear ();
+ bool empty() const;
+ bool clearing () const { return _clearing; }
void add_command (Command* const);
+ void remove_command (Command* const);
void operator() ();
void undo();
std::list<Command*> actions;
struct timeval _timestamp;
std::string _name;
- bool clearing;
- void remove_command (Command* const);
+ bool _clearing;
};
class UndoHistory
void save_state();
private:
- bool clearing;
+ bool _clearing;
std::list<UndoTransaction*> UndoList;
std::list<UndoTransaction*> RedoList;
using namespace std;
using namespace sigc;
+/* grrr, strict C++ says that static member functions are not C functions, but we also want
+ to be able to pack this into a sigc::ptr_fun and not sigc::mem_fun, so we have to make
+ it a genuine function rather than a member.
+*/
+
+static void command_death (UndoTransaction* ut, Command* c)
+{
+ if (ut->clearing()) {
+ return;
+ }
+
+ ut->remove_command (c);
+
+ if (ut->empty()) {
+ delete ut;
+ }
+}
+
+
UndoTransaction::UndoTransaction ()
{
- clearing = false;
+ _clearing = false;
}
UndoTransaction::UndoTransaction (const UndoTransaction& rhs)
{
_name = rhs._name;
- clearing = false;
+ _clearing = false;
clear ();
actions.insert(actions.end(),rhs.actions.begin(),rhs.actions.end());
}
void
UndoTransaction::add_command (Command *const action)
{
- action->GoingAway.connect (bind (mem_fun (*this, &UndoTransaction::remove_command), action));
+ action->GoingAway.connect (bind (sigc::ptr_fun (command_death), this, const_cast<Command*>(action)));
actions.push_back (action);
}
void
UndoTransaction::remove_command (Command* const action)
{
- if (clearing) {
- return;
- }
actions.remove (action);
- if (actions.empty()) {
- delete this;
- }
+}
+
+bool
+UndoTransaction::empty () const
+{
+ return actions.empty();
}
void
UndoTransaction::clear ()
{
- clearing = true;
+ _clearing = true;
for (list<Command*>::iterator i = actions.begin(); i != actions.end(); ++i) {
delete *i;
}
actions.clear ();
- clearing = false;
+ _clearing = false;
}
void
UndoHistory::UndoHistory ()
{
- clearing = false;
+ _clearing = false;
}
void
void
UndoHistory::remove (UndoTransaction* const ut)
{
- if (clearing) {
+ if (_clearing) {
return;
}
void
UndoHistory::clear_redo ()
{
- clearing = true;
+ _clearing = true;
RedoList.clear ();
- clearing = false;
+ _clearing = false;
}
void
UndoHistory::clear_undo ()
{
- clearing = true;
+ _clearing = true;
UndoList.clear ();
- clearing = false;
+ _clearing = false;
}
void