Fix formatting of command stuff to adhere to The Guidelines(TM).
git-svn-id: svn://localhost/ardour2/trunk@2130 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
|
||||
XMLNode &Command::get_state()
|
||||
{
|
||||
XMLNode *node = new XMLNode ("Command");
|
||||
node->add_content("WARNING: Somebody forgot to subclass Command.");
|
||||
return *node;
|
||||
XMLNode *node = new XMLNode ("Command");
|
||||
node->add_content("WARNING: Somebody forgot to subclass Command.");
|
||||
return *node;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
Copyright (C) 2006 Hans Fugal & Paul Davis
|
||||
Copyright (C) 2006 Paul Davis
|
||||
Author: Hans Fugal
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -24,13 +25,16 @@
|
||||
|
||||
class Command : public PBD::StatefulDestructible
|
||||
{
|
||||
public:
|
||||
public:
|
||||
virtual ~Command() {}
|
||||
|
||||
virtual void operator() () = 0;
|
||||
virtual void undo() = 0;
|
||||
virtual void redo() { (*this)(); }
|
||||
virtual XMLNode &get_state();
|
||||
virtual int set_state(const XMLNode&) { /* noop */ return 0; }
|
||||
|
||||
virtual void undo() = 0;
|
||||
virtual void redo() { (*this)(); }
|
||||
|
||||
virtual XMLNode &get_state();
|
||||
virtual int set_state(const XMLNode&) { /* noop */ return 0; }
|
||||
};
|
||||
|
||||
#endif // __lib_pbd_command_h_
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
Copyright (C) 2006 Hans Fugal & Paul Davis
|
||||
Copyright (C) 2006 Paul Davis
|
||||
Author: Hans Fugal
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -21,8 +22,6 @@
|
||||
#define __lib_pbd_memento_command_h__
|
||||
|
||||
#include <iostream>
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
#include <pbd/command.h>
|
||||
#include <pbd/stacktrace.h>
|
||||
@@ -36,66 +35,67 @@ using std::endl;
|
||||
* (from Stateful::get_state()), so undo becomes restoring the before
|
||||
* memento, and redo is restoring the after memento.
|
||||
*/
|
||||
|
||||
template <class obj_T>
|
||||
class MementoCommand : public Command
|
||||
{
|
||||
public:
|
||||
MementoCommand(obj_T &object,
|
||||
XMLNode *before,
|
||||
XMLNode *after
|
||||
)
|
||||
: obj(object), before(before), after(after) {
|
||||
public:
|
||||
MementoCommand(obj_T &object, XMLNode *before, XMLNode *after)
|
||||
: obj(object), before(before), after(after)
|
||||
{
|
||||
/* catch destruction of the object */
|
||||
new PBD::Shiva<obj_T,MementoCommand<obj_T> > (object, *this);
|
||||
}
|
||||
|
||||
~MementoCommand () {
|
||||
GoingAway();
|
||||
if (before) {
|
||||
~MementoCommand ()
|
||||
{
|
||||
GoingAway(); /* EMIT SIGNAL */
|
||||
|
||||
if (before)
|
||||
delete before;
|
||||
}
|
||||
if (after) {
|
||||
|
||||
if (after)
|
||||
delete after;
|
||||
}
|
||||
}
|
||||
void operator() ()
|
||||
{
|
||||
if (after)
|
||||
obj.set_state(*after);
|
||||
}
|
||||
void undo()
|
||||
{
|
||||
if (before)
|
||||
obj.set_state(*before);
|
||||
}
|
||||
virtual XMLNode &get_state()
|
||||
{
|
||||
string name;
|
||||
if (before && after)
|
||||
name = "MementoCommand";
|
||||
else if (before)
|
||||
name = "MementoUndoCommand";
|
||||
else
|
||||
name = "MementoRedoCommand";
|
||||
|
||||
|
||||
XMLNode *node = new XMLNode(name);
|
||||
void operator() ()
|
||||
{
|
||||
if (after)
|
||||
obj.set_state(*after);
|
||||
}
|
||||
|
||||
node->add_property("obj_id", obj.id().to_s());
|
||||
node->add_property("type_name", typeid(obj).name());
|
||||
|
||||
if (before)
|
||||
node->add_child_copy(*before);
|
||||
if (after)
|
||||
node->add_child_copy(*after);
|
||||
void undo()
|
||||
{
|
||||
if (before)
|
||||
obj.set_state(*before);
|
||||
}
|
||||
|
||||
return *node;
|
||||
}
|
||||
virtual XMLNode &get_state()
|
||||
{
|
||||
string name;
|
||||
if (before && after)
|
||||
name = "MementoCommand";
|
||||
else if (before)
|
||||
name = "MementoUndoCommand";
|
||||
else
|
||||
name = "MementoRedoCommand";
|
||||
|
||||
protected:
|
||||
obj_T &obj;
|
||||
XMLNode *before, *after;
|
||||
XMLNode *node = new XMLNode(name);
|
||||
|
||||
node->add_property("obj_id", obj.id().to_s());
|
||||
node->add_property("type_name", typeid(obj).name());
|
||||
|
||||
if (before)
|
||||
node->add_child_copy(*before);
|
||||
|
||||
if (after)
|
||||
node->add_child_copy(*after);
|
||||
|
||||
return *node;
|
||||
}
|
||||
|
||||
protected:
|
||||
obj_T &obj;
|
||||
XMLNode *before, *after;
|
||||
};
|
||||
|
||||
#endif // __lib_pbd_memento_h__
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 2002 Brett Viren & Paul Davis
|
||||
Copyright (C) 2002 Brett Viren & Paul Davis
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -45,7 +45,7 @@ class UndoTransaction : public Command
|
||||
void add_command (Command* const);
|
||||
void remove_command (Command* const);
|
||||
|
||||
void operator() ();
|
||||
void operator() ();
|
||||
void undo();
|
||||
void redo();
|
||||
|
||||
@@ -93,8 +93,8 @@ class UndoHistory : public sigc::trackable
|
||||
void clear_undo ();
|
||||
void clear_redo ();
|
||||
|
||||
XMLNode &get_state(uint32_t depth = 0);
|
||||
void save_state();
|
||||
XMLNode &get_state(uint32_t depth = 0);
|
||||
void save_state();
|
||||
|
||||
sigc::signal<void> Changed;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user