| [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 |  | 
|---|
| [80951de] | 46 | Dialog* MakroAction::createDialog() { | 
|---|
|  | 47 | actions->callAllDialogs(); | 
|---|
|  | 48 | } | 
|---|
| [1fa107] | 49 |  | 
|---|
| [5b0b98] | 50 | Action::state_ptr MakroAction::performCall(){ | 
|---|
| [2efa90] | 51 | ActionSequence::stateSet states = actions->callAll(true); | 
|---|
| [5b0b98] | 52 | return Action::state_ptr(new MakroActionState(states)); | 
|---|
| [1fa107] | 53 | } | 
|---|
|  | 54 |  | 
|---|
| [5b0b98] | 55 | Action::state_ptr MakroAction::performUndo(Action::state_ptr _state) { | 
|---|
|  | 56 | MakroActionState *state = dynamic_cast<MakroActionState*>(_state.get()); | 
|---|
| [67e2b3] | 57 | ASSERT(state,"Type mismatch for the state of the MakroAction"); | 
|---|
|  | 58 | ActionSequence::stateSet states = actions->undoAll(state->states); | 
|---|
| [5b0b98] | 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)); | 
|---|
| [1fa107] | 67 | } | 
|---|
|  | 68 |  | 
|---|
|  | 69 | bool MakroAction::canUndo() { | 
|---|
|  | 70 | return actions->canUndo(); | 
|---|
|  | 71 | } | 
|---|
| [67e2b3] | 72 |  | 
|---|
|  | 73 | bool MakroAction::shouldUndo() { | 
|---|
|  | 74 | return actions->shouldUndo(); | 
|---|
|  | 75 | } | 
|---|