| 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 |  | 
|---|
| 47 | Action::state_ptr MakroAction::performCall(){ | 
|---|
| 48 | ActionSequence::stateSet states = actions->callAll(true); | 
|---|
| 49 | return Action::state_ptr(new MakroActionState(states)); | 
|---|
| 50 | } | 
|---|
| 51 |  | 
|---|
| 52 | Action::state_ptr MakroAction::performUndo(Action::state_ptr _state) { | 
|---|
| 53 | MakroActionState *state = dynamic_cast<MakroActionState*>(_state.get()); | 
|---|
| 54 | ASSERT(state,"Type mismatch for the state of the MakroAction"); | 
|---|
| 55 | ActionSequence::stateSet states = actions->undoAll(state->states); | 
|---|
| 56 | return Action::state_ptr(new MakroActionState(states)); | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 | Action::state_ptr MakroAction::performRedo(Action::state_ptr _state){ | 
|---|
| 60 | MakroActionState *state = dynamic_cast<MakroActionState*>(_state.get()); | 
|---|
| 61 | ASSERT(state,"Type mismatch for the state of the MakroAction"); | 
|---|
| 62 | ActionSequence::stateSet states = actions->redoAll(state->states); | 
|---|
| 63 | return Action::state_ptr(new MakroActionState(states)); | 
|---|
| 64 | } | 
|---|
| 65 |  | 
|---|
| 66 | bool MakroAction::canUndo() { | 
|---|
| 67 | return actions->canUndo(); | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|
| 70 | bool MakroAction::shouldUndo() { | 
|---|
| 71 | return actions->shouldUndo(); | 
|---|
| 72 | } | 
|---|