[e2009b] | 1 | /*
|
---|
| 2 | * SelectionNotAtomByIdAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 12, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #include "Helpers/MemDebug.hpp"
|
---|
| 9 |
|
---|
| 10 | #include "Actions/SelectionAction/NotAtomByIdAction.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"
|
---|
[533838] | 23 | #include "UIElements/ValueStorage.hpp"
|
---|
[e2009b] | 24 |
|
---|
| 25 |
|
---|
| 26 | // memento to remember the state when undoing
|
---|
| 27 |
|
---|
| 28 | class SelectionNotAtomByIdState : public ActionState {
|
---|
| 29 | public:
|
---|
| 30 | SelectionNotAtomByIdState(atom* _walker) :
|
---|
| 31 | walker(_walker)
|
---|
| 32 | {}
|
---|
| 33 | atom* walker;
|
---|
| 34 | };
|
---|
| 35 |
|
---|
| 36 | const char SelectionNotAtomByIdAction::NAME[] = "unselect-atom-by-id";
|
---|
| 37 |
|
---|
| 38 | SelectionNotAtomByIdAction::SelectionNotAtomByIdAction() :
|
---|
| 39 | Action(NAME)
|
---|
| 40 | {}
|
---|
| 41 |
|
---|
| 42 | SelectionNotAtomByIdAction::~SelectionNotAtomByIdAction()
|
---|
| 43 | {}
|
---|
| 44 |
|
---|
[533838] | 45 | Dialog* SelectionNotAtomByIdAction::createDialog() {
|
---|
[e2009b] | 46 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
[533838] | 47 |
|
---|
| 48 | dialog->queryAtom(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 49 |
|
---|
| 50 | return dialog;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | Action::state_ptr SelectionNotAtomByIdAction::performCall() {
|
---|
[e2009b] | 54 | atom *Walker = NULL;
|
---|
| 55 |
|
---|
[533838] | 56 | ValueStorage::getInstance().queryCurrentValue(NAME, Walker);
|
---|
[e2009b] | 57 |
|
---|
[533838] | 58 | if (World::getInstance().isSelected(Walker)) {
|
---|
| 59 | DoLog(1) && (Log() << Verbose(1) << "Unselecting atom " << *Walker << endl);
|
---|
| 60 | World::getInstance().unselectAtom(Walker);
|
---|
| 61 | return Action::state_ptr(new SelectionNotAtomByIdState(Walker));
|
---|
[e2009b] | 62 | } else {
|
---|
[533838] | 63 | return Action::success;
|
---|
[e2009b] | 64 | }
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | Action::state_ptr SelectionNotAtomByIdAction::performUndo(Action::state_ptr _state) {
|
---|
| 68 | SelectionNotAtomByIdState *state = assert_cast<SelectionNotAtomByIdState*>(_state.get());
|
---|
| 69 |
|
---|
| 70 | if (state->walker != NULL)
|
---|
| 71 | World::getInstance().selectAtom(state->walker);
|
---|
| 72 |
|
---|
| 73 | return Action::state_ptr(new SelectionNotAtomByIdState(state->walker));
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | Action::state_ptr SelectionNotAtomByIdAction::performRedo(Action::state_ptr _state){
|
---|
| 77 | SelectionNotAtomByIdState *state = assert_cast<SelectionNotAtomByIdState*>(_state.get());
|
---|
| 78 |
|
---|
| 79 | if (state->walker != NULL)
|
---|
| 80 | World::getInstance().unselectAtom(state->walker);
|
---|
| 81 |
|
---|
| 82 | return Action::state_ptr(new SelectionNotAtomByIdState(state->walker));
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | bool SelectionNotAtomByIdAction::canUndo() {
|
---|
| 86 | return true;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | bool SelectionNotAtomByIdAction::shouldUndo() {
|
---|
| 90 | return true;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | const string SelectionNotAtomByIdAction::getName() {
|
---|
| 94 | return NAME;
|
---|
| 95 | }
|
---|