Originally committed to SVN as r2462.
This commit is contained in:
Rodrigo Braz Monteiro 2008-11-16 01:22:20 +00:00
parent 1f1261c997
commit fbf55bacaa
4 changed files with 24 additions and 10 deletions

View file

@ -363,11 +363,19 @@ namespace Athenasub {
// Action list
class IActionList {
friend class CModel;
protected:
virtual std::list<Action> GetActions() = 0;
virtual void AddActionStart(Action action) = 0;
public:
virtual ~IActionList() {}
virtual String GetName() const = 0;
virtual String GetOwner() const = 0;
virtual Model GetModel() const = 0;
virtual bool CanUndo() const = 0;
virtual void AddAction(Action action) = 0;
virtual void Finish() = 0;

View file

@ -57,7 +57,7 @@ CActionList::~CActionList()
//////////////////////////////
// Add an action to the queue
void CActionList::AddAction(const Action action)
void CActionList::AddAction(Action action)
{
if (!valid) THROW_ATHENA_EXCEPTION(Exception::Invalid_ActionList);
actions.push_back(action);

View file

@ -50,8 +50,8 @@ namespace Athenasub {
// ActionList class
class CActionList : public IActionList {
friend class CModel;
friend class CController;
friend class CModel;
private:
String actionName;
@ -63,13 +63,17 @@ namespace Athenasub {
CActionList(weak_ptr<IModel>,const String actionName,const String owner,bool undoAble);
void Start(const String actionName);
void AddActionStart(const Action action);
virtual void AddActionStart(Action action);
virtual std::list<Action> GetActions() { return actions; }
public:
virtual ~CActionList();
virtual String GetName() const { return actionName; }
virtual String GetOwner() const { return owner; }
virtual Model GetModel() const { return Model(model); }
virtual bool CanUndo() const { return undoAble; }
virtual void AddAction(Action action);
virtual void Finish();

View file

@ -33,7 +33,7 @@
// Contact: mailto:amz@aegisub.net
//
#include "Athenasub.h"
#include "athenasub.h"
#include "model.h"
#include "controller.h"
using namespace Athenasub;
@ -74,27 +74,29 @@ void CModel::DispatchNotifications(Notification notification) const
void CModel::ProcessActionList(CActionList &_actionList,int type)
{
// Copy the list
//shared_ptr<CActionList> actions = shared_ptr<CActionList>(new CActionList(*static_pointer_cast<CActionList>(_actionList)));
shared_ptr<CActionList> actions = shared_ptr<CActionList>(new CActionList(_actionList));
//shared_ptr<CActionList> actions = shared_ptr<CActionList>(new CActionList(_actionList));
ActionList actions = ActionList(new CActionList(_actionList));
bool canUndo = actions->CanUndo();
// Setup undo
shared_ptr<CActionList> undo = shared_ptr<CActionList>(new CActionList(Model(actions->model),actions->actionName,actions->owner,actions->undoAble));
ActionList undo = ActionList(new CActionList(actions->GetModel(),actions->GetName(),actions->GetOwner(),canUndo));
ActionStack *stack;
if (type == 1) stack = &redoStack;
else stack = &undoStack;
// Execute actions
std::list<Action>::const_iterator cur;
for (cur=actions->actions.begin();cur!=actions->actions.end();cur++) {
std::list<Action> acts = actions->GetActions();
for (cur=acts.begin();cur!=acts.end();cur++) {
// Inserts the opposite into the undo action first
if (actions->undoAble) undo->AddActionStart((*cur)->GetAntiAction());
if (canUndo) undo->AddActionStart((*cur)->GetAntiAction());
// Execute the action itself
(*cur)->Execute();
}
// Insert into undo stack
if (actions->undoAble) {
if (canUndo) {
stack->push_back(undo);
if (stack->size() > undoLimit) stack->pop_front();
if (type == 0) redoStack.clear();