1 | /*
|
---|
2 | * SetDefaultNameAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: May 8, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Helpers/MemDebug.hpp"
|
---|
9 |
|
---|
10 | #include "Actions/WorldAction/SetDefaultNameAction.hpp"
|
---|
11 | #include "log.hpp"
|
---|
12 | #include "verbose.hpp"
|
---|
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"
|
---|
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 | };
|
---|
34 |
|
---|
35 | const char WorldSetDefaultNameAction::NAME[] = "default-molname";
|
---|
36 |
|
---|
37 | WorldSetDefaultNameAction::WorldSetDefaultNameAction() :
|
---|
38 | Action(NAME)
|
---|
39 | {}
|
---|
40 |
|
---|
41 | WorldSetDefaultNameAction::~WorldSetDefaultNameAction()
|
---|
42 | {}
|
---|
43 |
|
---|
44 | Dialog* WorldSetDefaultNameAction::createDialog() {
|
---|
45 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
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() {
|
---|
55 | string defaultname;
|
---|
56 |
|
---|
57 | defaultname = World::getInstance().getDefaultName();
|
---|
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;
|
---|
63 | }
|
---|
64 |
|
---|
65 | Action::state_ptr WorldSetDefaultNameAction::performUndo(Action::state_ptr _state) {
|
---|
66 | WorldSetDefaultNameState *state = assert_cast<WorldSetDefaultNameState*>(_state.get());
|
---|
67 |
|
---|
68 | string newName = World::getInstance().getDefaultName();
|
---|
69 | World::getInstance().setDefaultName(state->lastName);
|
---|
70 |
|
---|
71 | return Action::state_ptr(new WorldSetDefaultNameState(newName));
|
---|
72 | }
|
---|
73 |
|
---|
74 | Action::state_ptr WorldSetDefaultNameAction::performRedo(Action::state_ptr _state){
|
---|
75 | performUndo(_state);
|
---|
76 | }
|
---|
77 |
|
---|
78 | bool WorldSetDefaultNameAction::canUndo() {
|
---|
79 | return true;
|
---|
80 | }
|
---|
81 |
|
---|
82 | bool WorldSetDefaultNameAction::shouldUndo() {
|
---|
83 | return true;
|
---|
84 | }
|
---|
85 |
|
---|
86 | const string WorldSetDefaultNameAction::getName() {
|
---|
87 | return NAME;
|
---|
88 | }
|
---|