| 1 | /*
 | 
|---|
| 2 |  * MakroAction.cpp
 | 
|---|
| 3 |  *
 | 
|---|
| 4 |  *  Created on: Dec 17, 2009
 | 
|---|
| 5 |  *      Author: crueger
 | 
|---|
| 6 |  */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | #include "Helpers/MemDebug.hpp"
 | 
|---|
| 9 | 
 | 
|---|
| 10 | #include <string>
 | 
|---|
| 11 | 
 | 
|---|
| 12 | #include "Actions/MakroAction.hpp"
 | 
|---|
| 13 | #include "Actions/Action.hpp"
 | 
|---|
| 14 | #include "Actions/ActionSequence.hpp"
 | 
|---|
| 15 | #include "Helpers/Assert.hpp"
 | 
|---|
| 16 | 
 | 
|---|
| 17 | using namespace std;
 | 
|---|
| 18 | 
 | 
|---|
| 19 | class MakroActionState : public ActionState{
 | 
|---|
| 20 | public:
 | 
|---|
| 21 |   MakroActionState(ActionSequence::stateSet _states) :
 | 
|---|
| 22 |     states(_states)
 | 
|---|
| 23 |   {}
 | 
|---|
| 24 |   virtual ~MakroActionState(){
 | 
|---|
| 25 |     // All contained states are destroyed by the shared ptrs
 | 
|---|
| 26 |   }
 | 
|---|
| 27 | 
 | 
|---|
| 28 |   ActionSequence::stateSet states;
 | 
|---|
| 29 | };
 | 
|---|
| 30 | 
 | 
|---|
| 31 | MakroAction::MakroAction(string _name,ActionSequence* _actions,bool _doRegister) :
 | 
|---|
| 32 | Action(_name,_doRegister),
 | 
|---|
| 33 | actions(_actions)
 | 
|---|
| 34 | {
 | 
|---|
| 35 | }
 | 
|---|
| 36 | 
 | 
|---|
| 37 | MakroAction::~MakroAction()
 | 
|---|
| 38 | {
 | 
|---|
| 39 |   Action* action;
 | 
|---|
| 40 |   while((action=actions->removeLastAction())){
 | 
|---|
| 41 |     delete action;
 | 
|---|
| 42 |   }
 | 
|---|
| 43 |   delete actions;
 | 
|---|
| 44 | }
 | 
|---|
| 45 | 
 | 
|---|
| 46 | Dialog* MakroAction::createDialog() {
 | 
|---|
| 47 |   actions->callAllDialogs();
 | 
|---|
| 48 | }
 | 
|---|
| 49 | 
 | 
|---|
| 50 | Action::state_ptr MakroAction::performCall(){
 | 
|---|
| 51 |   ActionSequence::stateSet states = actions->callAll(true);
 | 
|---|
| 52 |   return Action::state_ptr(new MakroActionState(states));
 | 
|---|
| 53 | }
 | 
|---|
| 54 | 
 | 
|---|
| 55 | Action::state_ptr MakroAction::performUndo(Action::state_ptr _state) {
 | 
|---|
| 56 |   MakroActionState *state = dynamic_cast<MakroActionState*>(_state.get());
 | 
|---|
| 57 |   ASSERT(state,"Type mismatch for the state of the MakroAction");
 | 
|---|
| 58 |   ActionSequence::stateSet states = actions->undoAll(state->states);
 | 
|---|
| 59 |   return Action::state_ptr(new MakroActionState(states));
 | 
|---|
| 60 | }
 | 
|---|
| 61 | 
 | 
|---|
| 62 | Action::state_ptr MakroAction::performRedo(Action::state_ptr _state){
 | 
|---|
| 63 |   MakroActionState *state = dynamic_cast<MakroActionState*>(_state.get());
 | 
|---|
| 64 |   ASSERT(state,"Type mismatch for the state of the MakroAction");
 | 
|---|
| 65 |   ActionSequence::stateSet states = actions->redoAll(state->states);
 | 
|---|
| 66 |   return Action::state_ptr(new MakroActionState(states));
 | 
|---|
| 67 | }
 | 
|---|
| 68 | 
 | 
|---|
| 69 | bool MakroAction::canUndo() {
 | 
|---|
| 70 |   return actions->canUndo();
 | 
|---|
| 71 | }
 | 
|---|
| 72 | 
 | 
|---|
| 73 | bool MakroAction::shouldUndo() {
 | 
|---|
| 74 |   return actions->shouldUndo();
 | 
|---|
| 75 | }
 | 
|---|