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