diff --git a/athenasub/include/athenasub/interfaces.h b/athenasub/include/athenasub/interfaces.h index 801b1e970..1c9945075 100644 --- a/athenasub/include/athenasub/interfaces.h +++ b/athenasub/include/athenasub/interfaces.h @@ -363,11 +363,19 @@ namespace Athenasub { // Action list class IActionList { + friend class CModel; + + protected: + virtual std::list 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; diff --git a/athenasub/src/actionlist.cpp b/athenasub/src/actionlist.cpp index 8345c3236..c199a974e 100644 --- a/athenasub/src/actionlist.cpp +++ b/athenasub/src/actionlist.cpp @@ -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); diff --git a/athenasub/src/actionlist.h b/athenasub/src/actionlist.h index bb9436254..f19e5dfcb 100644 --- a/athenasub/src/actionlist.h +++ b/athenasub/src/actionlist.h @@ -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,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 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(); diff --git a/athenasub/src/model.cpp b/athenasub/src/model.cpp index 0bdf5493d..c46842c4c 100644 --- a/athenasub/src/model.cpp +++ b/athenasub/src/model.cpp @@ -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 actions = shared_ptr(new CActionList(*static_pointer_cast(_actionList))); - shared_ptr actions = shared_ptr(new CActionList(_actionList)); + //shared_ptr actions = shared_ptr(new CActionList(_actionList)); + ActionList actions = ActionList(new CActionList(_actionList)); + bool canUndo = actions->CanUndo(); // Setup undo - shared_ptr undo = shared_ptr(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::const_iterator cur; - for (cur=actions->actions.begin();cur!=actions->actions.end();cur++) { + std::list 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();