[97ebf8] | 1 | /*
|
---|
| 2 | * VerboseAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 9, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[112b09] | 8 | #include "Helpers/MemDebug.hpp"
|
---|
| 9 |
|
---|
[97ebf8] | 10 | #include "Actions/CmdAction/VerboseAction.hpp"
|
---|
[0430e3] | 11 | #include "Actions/ActionRegistry.hpp"
|
---|
[952f38] | 12 | #include "Helpers/Log.hpp"
|
---|
| 13 | #include "Helpers/Verbose.hpp"
|
---|
[97ebf8] | 14 |
|
---|
| 15 | #include <iostream>
|
---|
| 16 | #include <string>
|
---|
| 17 |
|
---|
| 18 | using namespace std;
|
---|
| 19 |
|
---|
| 20 | #include "UIElements/UIFactory.hpp"
|
---|
| 21 | #include "UIElements/Dialog.hpp"
|
---|
[861874] | 22 | #include "Actions/ValueStorage.hpp"
|
---|
[1d2d177] | 23 |
|
---|
| 24 | // memento to remember the state when undoing
|
---|
| 25 |
|
---|
| 26 | class CommandLineVerboseState : public ActionState {
|
---|
| 27 | public:
|
---|
[92c52f] | 28 | CommandLineVerboseState(const int _oldverbosity, const int _newverbosity) :
|
---|
| 29 | oldverbosity(_oldverbosity),
|
---|
| 30 | newverbosity(_newverbosity)
|
---|
[1d2d177] | 31 | {}
|
---|
[92c52f] | 32 | int oldverbosity;
|
---|
| 33 | int newverbosity;
|
---|
[1d2d177] | 34 | };
|
---|
| 35 |
|
---|
[97ebf8] | 36 |
|
---|
| 37 | const char CommandLineVerboseAction::NAME[] = "verbose";
|
---|
| 38 |
|
---|
| 39 | CommandLineVerboseAction::CommandLineVerboseAction() :
|
---|
| 40 | Action(NAME)
|
---|
| 41 | {}
|
---|
| 42 |
|
---|
| 43 | CommandLineVerboseAction::~CommandLineVerboseAction()
|
---|
| 44 | {}
|
---|
| 45 |
|
---|
[ecbc9a] | 46 | void CommandVerbose(int verbosity) {
|
---|
| 47 | ValueStorage::getInstance().setCurrentValue(CommandLineVerboseAction::NAME, verbosity);
|
---|
| 48 | ActionRegistry::getInstance().getActionByName(CommandLineVerboseAction::NAME)->call(Action::NonInteractive);
|
---|
| 49 | };
|
---|
| 50 |
|
---|
[047878] | 51 | Dialog* CommandLineVerboseAction::fillDialog(Dialog *dialog) {
|
---|
| 52 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
[1d2d177] | 53 |
|
---|
| 54 | dialog->queryInt(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 55 |
|
---|
| 56 | return dialog;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | Action::state_ptr CommandLineVerboseAction::performCall() {
|
---|
[92c52f] | 60 | int oldverbosity = getVerbosity();
|
---|
| 61 | int newverbosity = 2;
|
---|
| 62 |
|
---|
| 63 | ValueStorage::getInstance().queryCurrentValue(NAME, newverbosity);
|
---|
| 64 |
|
---|
| 65 | if (oldverbosity != newverbosity) {
|
---|
| 66 | CommandLineVerboseState *UndoState = new CommandLineVerboseState(oldverbosity, newverbosity);
|
---|
| 67 | setVerbosity(newverbosity);
|
---|
| 68 | DoLog(0) && (Log() << Verbose(0) << "Setting verbosity from " << oldverbosity << " to " << newverbosity << "." << endl);
|
---|
| 69 | return Action::state_ptr(UndoState);
|
---|
| 70 | } else {
|
---|
| 71 | DoLog(0) && (Log() << Verbose(0) << "Verbosity remains unchanged at " << oldverbosity << "." << endl);
|
---|
| 72 | return Action::failure;
|
---|
| 73 | }
|
---|
[97ebf8] | 74 | }
|
---|
| 75 |
|
---|
| 76 | Action::state_ptr CommandLineVerboseAction::performUndo(Action::state_ptr _state) {
|
---|
[1d2d177] | 77 | CommandLineVerboseState *state = assert_cast<CommandLineVerboseState*>(_state.get());
|
---|
| 78 |
|
---|
[92c52f] | 79 | DoLog(0) && (Log() << Verbose(0) << "Setting verbosity from " << state->newverbosity << " to " << state->oldverbosity << "." << endl);
|
---|
| 80 | setVerbosity(state->oldverbosity);
|
---|
[97ebf8] | 81 |
|
---|
[92c52f] | 82 | return Action::state_ptr(_state);
|
---|
[97ebf8] | 83 | }
|
---|
| 84 |
|
---|
| 85 | Action::state_ptr CommandLineVerboseAction::performRedo(Action::state_ptr _state){
|
---|
[92c52f] | 86 | CommandLineVerboseState *state = assert_cast<CommandLineVerboseState*>(_state.get());
|
---|
| 87 |
|
---|
| 88 | DoLog(0) && (Log() << Verbose(0) << "Setting verbosity from " << state->oldverbosity << " to " << state->newverbosity << "." << endl);
|
---|
| 89 | setVerbosity(state->newverbosity);
|
---|
| 90 |
|
---|
| 91 | return Action::state_ptr(_state);
|
---|
[97ebf8] | 92 | }
|
---|
| 93 |
|
---|
| 94 | bool CommandLineVerboseAction::canUndo() {
|
---|
[1d2d177] | 95 | return true;
|
---|
[97ebf8] | 96 | }
|
---|
| 97 |
|
---|
| 98 | bool CommandLineVerboseAction::shouldUndo() {
|
---|
[1d2d177] | 99 | return true;
|
---|
[97ebf8] | 100 | }
|
---|
| 101 |
|
---|
| 102 | const string CommandLineVerboseAction::getName() {
|
---|
| 103 | return NAME;
|
---|
| 104 | }
|
---|