[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:
|
---|
| 33 | CommandLineVerboseState(int _verbosity) :
|
---|
| 34 | verbosity(_verbosity)
|
---|
| 35 | {}
|
---|
| 36 | int verbosity;
|
---|
| 37 | };
|
---|
| 38 |
|
---|
[97ebf8] | 39 |
|
---|
| 40 | const char CommandLineVerboseAction::NAME[] = "verbose";
|
---|
| 41 |
|
---|
| 42 | CommandLineVerboseAction::CommandLineVerboseAction() :
|
---|
| 43 | Action(NAME)
|
---|
| 44 | {}
|
---|
| 45 |
|
---|
| 46 | CommandLineVerboseAction::~CommandLineVerboseAction()
|
---|
| 47 | {}
|
---|
| 48 |
|
---|
[ecbc9a] | 49 | void CommandVerbose(int verbosity) {
|
---|
| 50 | ValueStorage::getInstance().setCurrentValue(CommandLineVerboseAction::NAME, verbosity);
|
---|
| 51 | ActionRegistry::getInstance().getActionByName(CommandLineVerboseAction::NAME)->call(Action::NonInteractive);
|
---|
| 52 | };
|
---|
| 53 |
|
---|
[047878] | 54 | Dialog* CommandLineVerboseAction::fillDialog(Dialog *dialog) {
|
---|
| 55 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
[1d2d177] | 56 |
|
---|
| 57 | dialog->queryInt(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 58 |
|
---|
| 59 | return dialog;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | Action::state_ptr CommandLineVerboseAction::performCall() {
|
---|
[97ebf8] | 63 | int verbosity = 2;
|
---|
| 64 |
|
---|
[1d2d177] | 65 | ValueStorage::getInstance().queryCurrentValue(NAME, verbosity);
|
---|
| 66 |
|
---|
| 67 | setVerbosity(verbosity);
|
---|
| 68 | DoLog(0) && (Log() << Verbose(0) << "Setting verbosity to " << verbosity << "." << endl);
|
---|
| 69 | return Action::success;
|
---|
[97ebf8] | 70 | }
|
---|
| 71 |
|
---|
| 72 | Action::state_ptr CommandLineVerboseAction::performUndo(Action::state_ptr _state) {
|
---|
[1d2d177] | 73 | CommandLineVerboseState *state = assert_cast<CommandLineVerboseState*>(_state.get());
|
---|
| 74 |
|
---|
| 75 | int verbosity = 2;
|
---|
| 76 | ValueStorage::getInstance().queryCurrentValue(NAME, verbosity);
|
---|
[97ebf8] | 77 |
|
---|
[1d2d177] | 78 | setVerbosity(state->verbosity);
|
---|
| 79 | return Action::state_ptr(new CommandLineVerboseState(verbosity));
|
---|
[97ebf8] | 80 | }
|
---|
| 81 |
|
---|
| 82 | Action::state_ptr CommandLineVerboseAction::performRedo(Action::state_ptr _state){
|
---|
[680470] | 83 | return performUndo(_state);
|
---|
[97ebf8] | 84 | }
|
---|
| 85 |
|
---|
| 86 | bool CommandLineVerboseAction::canUndo() {
|
---|
[1d2d177] | 87 | return true;
|
---|
[97ebf8] | 88 | }
|
---|
| 89 |
|
---|
| 90 | bool CommandLineVerboseAction::shouldUndo() {
|
---|
[1d2d177] | 91 | return true;
|
---|
[97ebf8] | 92 | }
|
---|
| 93 |
|
---|
| 94 | const string CommandLineVerboseAction::getName() {
|
---|
| 95 | return NAME;
|
---|
| 96 | }
|
---|