[97ebf8] | 1 | /*
|
---|
| 2 | * SetDefaultNameAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 8, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[112b09] | 8 | #include "Helpers/MemDebug.hpp"
|
---|
| 9 |
|
---|
[97ebf8] | 10 | #include "Actions/WorldAction/SetDefaultNameAction.hpp"
|
---|
| 11 | #include "log.hpp"
|
---|
[387b36] | 12 | #include "verbose.hpp"
|
---|
[97ebf8] | 13 | #include "World.hpp"
|
---|
| 14 |
|
---|
| 15 | #include <iostream>
|
---|
| 16 | #include <string>
|
---|
| 17 |
|
---|
| 18 | using namespace std;
|
---|
| 19 |
|
---|
| 20 | #include "UIElements/UIFactory.hpp"
|
---|
| 21 | #include "UIElements/Dialog.hpp"
|
---|
[792597] | 22 | #include "UIElements/ValueStorage.hpp"
|
---|
| 23 |
|
---|
| 24 |
|
---|
| 25 | // memento to remember the state when undoing
|
---|
| 26 |
|
---|
| 27 | class WorldSetDefaultNameState : public ActionState {
|
---|
| 28 | public:
|
---|
| 29 | WorldSetDefaultNameState(std::string _lastName) :
|
---|
| 30 | lastName(_lastName)
|
---|
| 31 | {}
|
---|
| 32 | std::string lastName;
|
---|
| 33 | };
|
---|
[97ebf8] | 34 |
|
---|
| 35 | const char WorldSetDefaultNameAction::NAME[] = "default-molname";
|
---|
| 36 |
|
---|
| 37 | WorldSetDefaultNameAction::WorldSetDefaultNameAction() :
|
---|
| 38 | Action(NAME)
|
---|
| 39 | {}
|
---|
| 40 |
|
---|
| 41 | WorldSetDefaultNameAction::~WorldSetDefaultNameAction()
|
---|
| 42 | {}
|
---|
| 43 |
|
---|
[792597] | 44 | Dialog* WorldSetDefaultNameAction::createDialog() {
|
---|
[97ebf8] | 45 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
[792597] | 46 |
|
---|
| 47 | string defaultname = World::getInstance().getDefaultName();
|
---|
| 48 | ValueStorage::getInstance().setCurrentValue(NAME, defaultname);
|
---|
| 49 | dialog->queryString(NAME, MapOfActions::getInstance().getDescription(NAME));
|
---|
| 50 |
|
---|
| 51 | return dialog;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | Action::state_ptr WorldSetDefaultNameAction::performCall() {
|
---|
[97ebf8] | 55 | string defaultname;
|
---|
| 56 |
|
---|
| 57 | defaultname = World::getInstance().getDefaultName();
|
---|
[792597] | 58 | ValueStorage::getInstance().queryCurrentValue(NAME, defaultname);
|
---|
| 59 |
|
---|
| 60 | World::getInstance().setDefaultName(defaultname);
|
---|
| 61 | DoLog(0) && (Log() << Verbose(0) << "Default name of new molecules set to " << World::getInstance().getDefaultName() << "." << endl);
|
---|
| 62 | return Action::success;
|
---|
[97ebf8] | 63 | }
|
---|
| 64 |
|
---|
| 65 | Action::state_ptr WorldSetDefaultNameAction::performUndo(Action::state_ptr _state) {
|
---|
[792597] | 66 | WorldSetDefaultNameState *state = assert_cast<WorldSetDefaultNameState*>(_state.get());
|
---|
| 67 |
|
---|
| 68 | string newName = World::getInstance().getDefaultName();
|
---|
| 69 | World::getInstance().setDefaultName(state->lastName);
|
---|
[97ebf8] | 70 |
|
---|
[792597] | 71 | return Action::state_ptr(new WorldSetDefaultNameState(newName));
|
---|
[97ebf8] | 72 | }
|
---|
| 73 |
|
---|
| 74 | Action::state_ptr WorldSetDefaultNameAction::performRedo(Action::state_ptr _state){
|
---|
[792597] | 75 | performUndo(_state);
|
---|
[97ebf8] | 76 | }
|
---|
| 77 |
|
---|
| 78 | bool WorldSetDefaultNameAction::canUndo() {
|
---|
[792597] | 79 | return true;
|
---|
[97ebf8] | 80 | }
|
---|
| 81 |
|
---|
| 82 | bool WorldSetDefaultNameAction::shouldUndo() {
|
---|
[792597] | 83 | return true;
|
---|
[97ebf8] | 84 | }
|
---|
| 85 |
|
---|
| 86 | const string WorldSetDefaultNameAction::getName() {
|
---|
| 87 | return NAME;
|
---|
| 88 | }
|
---|