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