r59@gandalf: fugalh | 2006-06-15 12:16:20 -0600
renamed UndoCommand to UndoTransaction, and created new UndoCommand class and its templated subclass SlotCommand. Those two are still in considerable flux. git-svn-id: svn://localhost/ardour2/branches/undo@606 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
eb3f77df57
commit
7c9361b865
@ -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 ();
|
||||
|
@ -489,7 +489,7 @@ class Session : public sigc::trackable, public Stateful
|
||||
static vector<string*>* 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 ();
|
||||
|
@ -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
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <sigc++/slot.h>
|
||||
#include <sigc++/bind.h>
|
||||
#include <sys/time.h>
|
||||
@ -33,42 +34,47 @@ using std::list;
|
||||
|
||||
typedef sigc::slot<void> 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<void> _slot;
|
||||
std::list<Serializable> _args;
|
||||
};
|
||||
|
||||
template <class T1=void, class T2=void, class T3=void, class T4=void>
|
||||
class Memento;
|
||||
class SlotCommand;
|
||||
|
||||
template <>
|
||||
class Memento <> : public MementoBase {};
|
||||
class SlotCommand <> : public UndoCommand {};
|
||||
|
||||
template <class T1>
|
||||
class Memento <T1> : public MementoBase
|
||||
class SlotCommand <T1> : 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<UndoCommand> UndoList;
|
||||
list<UndoCommand> RedoList;
|
||||
list<UndoTransaction> UndoList;
|
||||
list<UndoTransaction> RedoList;
|
||||
};
|
||||
|
||||
|
||||
|
@ -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<UndoAction>::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<UndoAction>::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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user