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