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