[97ebf8] | 1 | /*
|
---|
| 2 | * SetDefaultNameAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 8, 2010
|
---|
| 5 | * Author: heber
|
---|
| 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 |
|
---|
[97ebf8] | 15 | #include "Actions/WorldAction/SetDefaultNameAction.hpp"
|
---|
[0430e3] | 16 | #include "Actions/ActionRegistry.hpp"
|
---|
[952f38] | 17 | #include "Helpers/Log.hpp"
|
---|
| 18 | #include "Helpers/Verbose.hpp"
|
---|
[97ebf8] | 19 | #include "World.hpp"
|
---|
| 20 |
|
---|
| 21 | #include <iostream>
|
---|
| 22 | #include <string>
|
---|
| 23 |
|
---|
| 24 | using namespace std;
|
---|
| 25 |
|
---|
| 26 | #include "UIElements/UIFactory.hpp"
|
---|
| 27 | #include "UIElements/Dialog.hpp"
|
---|
[861874] | 28 | #include "Actions/ValueStorage.hpp"
|
---|
[792597] | 29 |
|
---|
| 30 |
|
---|
| 31 | // memento to remember the state when undoing
|
---|
| 32 |
|
---|
| 33 | class WorldSetDefaultNameState : public ActionState {
|
---|
| 34 | public:
|
---|
| 35 | WorldSetDefaultNameState(std::string _lastName) :
|
---|
| 36 | lastName(_lastName)
|
---|
| 37 | {}
|
---|
| 38 | std::string lastName;
|
---|
| 39 | };
|
---|
[97ebf8] | 40 |
|
---|
| 41 | const char WorldSetDefaultNameAction::NAME[] = "default-molname";
|
---|
| 42 |
|
---|
| 43 | WorldSetDefaultNameAction::WorldSetDefaultNameAction() :
|
---|
| 44 | Action(NAME)
|
---|
| 45 | {}
|
---|
| 46 |
|
---|
| 47 | WorldSetDefaultNameAction::~WorldSetDefaultNameAction()
|
---|
| 48 | {}
|
---|
| 49 |
|
---|
[a8f6ae] | 50 | void WorldSetDefaultName(std::string &defaultname) {
|
---|
| 51 | ValueStorage::getInstance().setCurrentValue(WorldSetDefaultNameAction::NAME, defaultname);
|
---|
| 52 | ActionRegistry::getInstance().getActionByName(WorldSetDefaultNameAction::NAME)->call(Action::NonInteractive);
|
---|
| 53 | };
|
---|
| 54 |
|
---|
[047878] | 55 | Dialog* WorldSetDefaultNameAction::fillDialog(Dialog *dialog) {
|
---|
| 56 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
[792597] | 57 |
|
---|
| 58 | string defaultname = World::getInstance().getDefaultName();
|
---|
| 59 | ValueStorage::getInstance().setCurrentValue(NAME, defaultname);
|
---|
[c89fb4] | 60 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
[792597] | 61 |
|
---|
| 62 | return dialog;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | Action::state_ptr WorldSetDefaultNameAction::performCall() {
|
---|
[97ebf8] | 66 | string defaultname;
|
---|
| 67 |
|
---|
| 68 | defaultname = World::getInstance().getDefaultName();
|
---|
[792597] | 69 | ValueStorage::getInstance().queryCurrentValue(NAME, defaultname);
|
---|
| 70 |
|
---|
| 71 | World::getInstance().setDefaultName(defaultname);
|
---|
| 72 | DoLog(0) && (Log() << Verbose(0) << "Default name of new molecules set to " << World::getInstance().getDefaultName() << "." << endl);
|
---|
| 73 | return Action::success;
|
---|
[97ebf8] | 74 | }
|
---|
| 75 |
|
---|
| 76 | Action::state_ptr WorldSetDefaultNameAction::performUndo(Action::state_ptr _state) {
|
---|
[792597] | 77 | WorldSetDefaultNameState *state = assert_cast<WorldSetDefaultNameState*>(_state.get());
|
---|
| 78 |
|
---|
| 79 | string newName = World::getInstance().getDefaultName();
|
---|
| 80 | World::getInstance().setDefaultName(state->lastName);
|
---|
[97ebf8] | 81 |
|
---|
[792597] | 82 | return Action::state_ptr(new WorldSetDefaultNameState(newName));
|
---|
[97ebf8] | 83 | }
|
---|
| 84 |
|
---|
| 85 | Action::state_ptr WorldSetDefaultNameAction::performRedo(Action::state_ptr _state){
|
---|
[680470] | 86 | return performUndo(_state);
|
---|
[97ebf8] | 87 | }
|
---|
| 88 |
|
---|
| 89 | bool WorldSetDefaultNameAction::canUndo() {
|
---|
[792597] | 90 | return true;
|
---|
[97ebf8] | 91 | }
|
---|
| 92 |
|
---|
| 93 | bool WorldSetDefaultNameAction::shouldUndo() {
|
---|
[792597] | 94 | return true;
|
---|
[97ebf8] | 95 | }
|
---|
| 96 |
|
---|
| 97 | const string WorldSetDefaultNameAction::getName() {
|
---|
| 98 | return NAME;
|
---|
| 99 | }
|
---|