[e2009b] | 1 | /*
|
---|
| 2 | * SelectionAtomByIdAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 12, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #include "Helpers/MemDebug.hpp"
|
---|
| 9 |
|
---|
| 10 | #include "Actions/SelectionAction/AtomByIdAction.hpp"
|
---|
| 11 | #include "atom.hpp"
|
---|
| 12 | #include "log.hpp"
|
---|
| 13 | #include "verbose.hpp"
|
---|
| 14 | #include "World.hpp"
|
---|
| 15 |
|
---|
| 16 | #include <iostream>
|
---|
| 17 | #include <string>
|
---|
| 18 |
|
---|
| 19 | using namespace std;
|
---|
| 20 |
|
---|
| 21 | #include "UIElements/UIFactory.hpp"
|
---|
| 22 | #include "UIElements/Dialog.hpp"
|
---|
| 23 | #include "Actions/MapOfActions.hpp"
|
---|
| 24 |
|
---|
| 25 |
|
---|
| 26 | // memento to remember the state when undoing
|
---|
| 27 |
|
---|
| 28 | class SelectionAtomByIdState : public ActionState {
|
---|
| 29 | public:
|
---|
| 30 | SelectionAtomByIdState(atom* _walker) :
|
---|
| 31 | walker(_walker)
|
---|
| 32 | {}
|
---|
| 33 | atom* walker;
|
---|
| 34 | };
|
---|
| 35 |
|
---|
| 36 | const char SelectionAtomByIdAction::NAME[] = "select-atom-by-id";
|
---|
| 37 |
|
---|
| 38 | SelectionAtomByIdAction::SelectionAtomByIdAction() :
|
---|
| 39 | Action(NAME)
|
---|
| 40 | {}
|
---|
| 41 |
|
---|
| 42 | SelectionAtomByIdAction::~SelectionAtomByIdAction()
|
---|
| 43 | {}
|
---|
| 44 |
|
---|
| 45 | Action::state_ptr SelectionAtomByIdAction::performCall() {
|
---|
| 46 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
| 47 | atom *Walker = NULL;
|
---|
| 48 |
|
---|
| 49 | dialog->queryAtom(NAME, &Walker, MapOfActions::getInstance().getDescription(NAME));
|
---|
| 50 |
|
---|
| 51 | if(dialog->display()) {
|
---|
| 52 | delete dialog;
|
---|
| 53 | if (!World::getInstance().isSelected(Walker)) {
|
---|
| 54 | World::getInstance().selectAtom(Walker);
|
---|
| 55 | return Action::state_ptr(new SelectionAtomByIdState(Walker));
|
---|
| 56 | } else {
|
---|
| 57 | return Action::success;
|
---|
| 58 | }
|
---|
| 59 | } else {
|
---|
| 60 | delete dialog;
|
---|
| 61 | return Action::failure;
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | Action::state_ptr SelectionAtomByIdAction::performUndo(Action::state_ptr _state) {
|
---|
| 66 | SelectionAtomByIdState *state = assert_cast<SelectionAtomByIdState*>(_state.get());
|
---|
| 67 |
|
---|
| 68 | if (state->walker != NULL)
|
---|
| 69 | World::getInstance().unselectAtom(state->walker);
|
---|
| 70 |
|
---|
| 71 | return Action::state_ptr(new SelectionAtomByIdState(state->walker));
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | Action::state_ptr SelectionAtomByIdAction::performRedo(Action::state_ptr _state){
|
---|
| 75 | SelectionAtomByIdState *state = assert_cast<SelectionAtomByIdState*>(_state.get());
|
---|
| 76 |
|
---|
| 77 | if (state->walker != NULL)
|
---|
| 78 | World::getInstance().selectAtom(state->walker);
|
---|
| 79 |
|
---|
| 80 | return Action::state_ptr(new SelectionAtomByIdState(state->walker));
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | bool SelectionAtomByIdAction::canUndo() {
|
---|
| 84 | return true;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | bool SelectionAtomByIdAction::shouldUndo() {
|
---|
| 88 | return true;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | const string SelectionAtomByIdAction::getName() {
|
---|
| 92 | return NAME;
|
---|
| 93 | }
|
---|