diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 8b7b2af1d0..e73d44971b 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -1616,7 +1616,7 @@ class Editor : public PublicEditor /* visual history */ UndoHistory visual_history; - UndoCommand current_visual_command; + UndoTransaction current_visual_command; void begin_reversible_visual_command (const string & cmd_name); void commit_reversible_visual_command (); diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 83acb3f82a..3d164a4b05 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -489,7 +489,7 @@ class Session : public sigc::trackable, public Stateful static vector* possible_states(string path); XMLNode& get_state(); - int set_state(const XMLNode& node); + int set_state(const XMLNode& node); // not idempotent XMLNode& get_template(); void add_instant_xml (XMLNode&, const std::string& dir); @@ -849,13 +849,13 @@ class Session : public sigc::trackable, public Stateful void commit_reversible_command (UndoAction* private_redo = 0); void add_undo (const UndoAction& ua) { - current_cmd.add_undo (ua); + current_trans.add_undo (ua); } void add_redo (const UndoAction& ua) { - current_cmd.add_redo (ua); + current_trans.add_redo (ua); } void add_redo_no_execute (const UndoAction& ua) { - current_cmd.add_redo_no_execute (ua); + current_trans.add_redo_no_execute (ua); } UndoAction global_solo_memento (void *src); @@ -1635,7 +1635,7 @@ class Session : public sigc::trackable, public Stateful void reverse_diskstream_buffers (); UndoHistory history; - UndoCommand current_cmd; + UndoTransaction current_trans; GlobalRouteBooleanState get_global_route_boolean (bool (Route::*method)(void) const); GlobalRouteMeterState get_global_route_metering (); diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index cf510e9881..5ef717de8a 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -2562,11 +2562,11 @@ Session::set_meter_falloff (float val) void Session::begin_reversible_command (string name, UndoAction* private_undo) { - current_cmd.clear (); - current_cmd.set_name (name); + current_trans.clear (); + current_trans.set_name (name); if (private_undo) { - current_cmd.add_undo (*private_undo); + current_trans.add_undo (*private_undo); } } @@ -2576,13 +2576,13 @@ Session::commit_reversible_command (UndoAction* private_redo) struct timeval now; if (private_redo) { - current_cmd.add_redo_no_execute (*private_redo); + current_trans.add_redo_no_execute (*private_redo); } gettimeofday (&now, 0); - current_cmd.set_timestamp (now); + current_trans.set_timestamp (now); - history.add (current_cmd); + history.add (current_trans); } Session::GlobalRouteBooleanState diff --git a/libs/pbd3/pbd/undo.h b/libs/pbd3/pbd/undo.h index b540179012..488e896706 100644 --- a/libs/pbd3/pbd/undo.h +++ b/libs/pbd3/pbd/undo.h @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -33,42 +34,47 @@ using std::list; typedef sigc::slot UndoAction; -class Serializable; - -class MementoBase +// TODO stick this in its own file, and make the arguments multiply-inherit it +class Serializable { public: - MementoBase(std::string key); + XMLNode &serialize(); +}; + +class UndoCommand +{ +public: + UndoCommand(id_t object_id, std::string method_name); void operator() () { return _slot(); } XMLNode &serialize(); protected: sigc::slot _slot; - std::list _args; }; template -class Memento; +class SlotCommand; template <> -class Memento <> : public MementoBase {}; +class SlotCommand <> : public UndoCommand {}; template -class Memento : public MementoBase +class SlotCommand : public UndoCommand { + T1 _arg1; public: - Memento(std::string key, T1 arg1) : MementoBase(key) + SlotCommand(id_t object_id, std::string key, T1 arg1) + : UndoCommand(object_id, key), _arg1(arg1) { - _args.push_back(arg1); _slot = sigc::bind(_slot, arg1); } }; -class UndoCommand +class UndoTransaction { public: - UndoCommand (); - UndoCommand (const UndoCommand&); - UndoCommand& operator= (const UndoCommand&); + UndoTransaction (); + UndoTransaction (const UndoTransaction&); + UndoTransaction& operator= (const UndoTransaction&); void clear (); @@ -105,7 +111,7 @@ class UndoHistory UndoHistory() {} ~UndoHistory() {} - void add (UndoCommand uc); + void add (UndoTransaction ut); void undo (unsigned int n); void redo (unsigned int n); @@ -120,8 +126,8 @@ class UndoHistory void clear_redo (); private: - list UndoList; - list RedoList; + list UndoList; + list RedoList; }; diff --git a/libs/pbd3/undo.cc b/libs/pbd3/undo.cc index f2f11b1c5c..0aac58effc 100644 --- a/libs/pbd3/undo.cc +++ b/libs/pbd3/undo.cc @@ -25,11 +25,11 @@ using namespace std; using namespace sigc; -UndoCommand::UndoCommand () +UndoTransaction::UndoTransaction () { } -UndoCommand::UndoCommand (const UndoCommand& rhs) +UndoTransaction::UndoTransaction (const UndoTransaction& rhs) { _name = rhs._name; clear (); @@ -37,8 +37,8 @@ UndoCommand::UndoCommand (const UndoCommand& rhs) redo_actions.insert(redo_actions.end(),rhs.redo_actions.begin(),rhs.redo_actions.end()); } -UndoCommand& -UndoCommand::operator= (const UndoCommand& rhs) +UndoTransaction& +UndoTransaction::operator= (const UndoTransaction& rhs) { if (this == &rhs) return *this; _name = rhs._name; @@ -49,33 +49,33 @@ UndoCommand::operator= (const UndoCommand& rhs) } void -UndoCommand::add_undo (const UndoAction& action) +UndoTransaction::add_undo (const UndoAction& action) { undo_actions.push_back (action); } void -UndoCommand::add_redo (const UndoAction& action) +UndoTransaction::add_redo (const UndoAction& action) { redo_actions.push_back (action); redo_actions.back()(); // operator() } void -UndoCommand::add_redo_no_execute (const UndoAction& action) +UndoTransaction::add_redo_no_execute (const UndoAction& action) { redo_actions.push_back (action); } void -UndoCommand::clear () +UndoTransaction::clear () { undo_actions.clear (); redo_actions.clear (); } void -UndoCommand::undo () +UndoTransaction::undo () { cerr << "Undo " << _name << endl; for (list::reverse_iterator i = undo_actions.rbegin(); i != undo_actions.rend(); ++i) { @@ -84,7 +84,7 @@ UndoCommand::undo () } void -UndoCommand::redo () +UndoTransaction::redo () { cerr << "Redo " << _name << endl; for (list::iterator i = redo_actions.begin(); i != redo_actions.end(); ++i) { @@ -93,9 +93,9 @@ UndoCommand::redo () } void -UndoHistory::add (UndoCommand uc) +UndoHistory::add (UndoTransaction ut) { - UndoList.push_back (uc); + UndoList.push_back (ut); } void @@ -105,10 +105,10 @@ UndoHistory::undo (unsigned int n) if (UndoList.size() == 0) { return; } - UndoCommand uc = UndoList.back (); + UndoTransaction ut = UndoList.back (); UndoList.pop_back (); - uc.undo (); - RedoList.push_back (uc); + ut.undo (); + RedoList.push_back (ut); } } @@ -119,10 +119,10 @@ UndoHistory::redo (unsigned int n) if (RedoList.size() == 0) { return; } - UndoCommand cmd = RedoList.back (); + UndoTransaction trans = RedoList.back (); RedoList.pop_back (); - cmd.redo (); - UndoList.push_back (cmd); + trans.redo (); + UndoList.push_back (trans); } }