[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();
|
---|
[7aa3cf] | 69 | WorldSetDefaultNameState *UndoState = new WorldSetDefaultNameState(defaultname);
|
---|
[792597] | 70 | ValueStorage::getInstance().queryCurrentValue(NAME, defaultname);
|
---|
| 71 |
|
---|
| 72 | World::getInstance().setDefaultName(defaultname);
|
---|
| 73 | DoLog(0) && (Log() << Verbose(0) << "Default name of new molecules set to " << World::getInstance().getDefaultName() << "." << endl);
|
---|
[7aa3cf] | 74 | return Action::state_ptr(UndoState);
|
---|
[97ebf8] | 75 | }
|
---|
| 76 |
|
---|
| 77 | Action::state_ptr WorldSetDefaultNameAction::performUndo(Action::state_ptr _state) {
|
---|
[792597] | 78 | WorldSetDefaultNameState *state = assert_cast<WorldSetDefaultNameState*>(_state.get());
|
---|
| 79 |
|
---|
| 80 | string newName = World::getInstance().getDefaultName();
|
---|
| 81 | World::getInstance().setDefaultName(state->lastName);
|
---|
[7aa3cf] | 82 | DoLog(0) && (Log() << Verbose(0) << "Default name of new molecules set to " << World::getInstance().getDefaultName() << "." << endl);
|
---|
[97ebf8] | 83 |
|
---|
[792597] | 84 | return Action::state_ptr(new WorldSetDefaultNameState(newName));
|
---|
[97ebf8] | 85 | }
|
---|
| 86 |
|
---|
| 87 | Action::state_ptr WorldSetDefaultNameAction::performRedo(Action::state_ptr _state){
|
---|
[680470] | 88 | return performUndo(_state);
|
---|
[97ebf8] | 89 | }
|
---|
| 90 |
|
---|
| 91 | bool WorldSetDefaultNameAction::canUndo() {
|
---|
[792597] | 92 | return true;
|
---|
[97ebf8] | 93 | }
|
---|
| 94 |
|
---|
| 95 | bool WorldSetDefaultNameAction::shouldUndo() {
|
---|
[792597] | 96 | return true;
|
---|
[97ebf8] | 97 | }
|
---|
| 98 |
|
---|
| 99 | const string WorldSetDefaultNameAction::getName() {
|
---|
| 100 | return NAME;
|
---|
| 101 | }
|
---|