| 1 | /*
|
|---|
| 2 | * VerboseAction.cpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: May 9, 2010
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | // include config.h
|
|---|
| 9 | #ifdef HAVE_CONFIG_H
|
|---|
| 10 | #include <config.h>
|
|---|
| 11 | #endif
|
|---|
| 12 |
|
|---|
| 13 | #include "Helpers/MemDebug.hpp"
|
|---|
| 14 |
|
|---|
| 15 | #include "Actions/CmdAction/VerboseAction.hpp"
|
|---|
| 16 | #include "Actions/ActionRegistry.hpp"
|
|---|
| 17 | #include "Helpers/Log.hpp"
|
|---|
| 18 | #include "Helpers/Verbose.hpp"
|
|---|
| 19 |
|
|---|
| 20 | #include <iostream>
|
|---|
| 21 | #include <string>
|
|---|
| 22 |
|
|---|
| 23 | using namespace std;
|
|---|
| 24 |
|
|---|
| 25 | #include "UIElements/UIFactory.hpp"
|
|---|
| 26 | #include "UIElements/Dialog.hpp"
|
|---|
| 27 | #include "Actions/ValueStorage.hpp"
|
|---|
| 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 |
|
|---|
| 39 |
|
|---|
| 40 | const char CommandLineVerboseAction::NAME[] = "verbose";
|
|---|
| 41 |
|
|---|
| 42 | CommandLineVerboseAction::CommandLineVerboseAction() :
|
|---|
| 43 | Action(NAME)
|
|---|
| 44 | {}
|
|---|
| 45 |
|
|---|
| 46 | CommandLineVerboseAction::~CommandLineVerboseAction()
|
|---|
| 47 | {}
|
|---|
| 48 |
|
|---|
| 49 | void CommandVerbose(int verbosity) {
|
|---|
| 50 | ValueStorage::getInstance().setCurrentValue(CommandLineVerboseAction::NAME, verbosity);
|
|---|
| 51 | ActionRegistry::getInstance().getActionByName(CommandLineVerboseAction::NAME)->call(Action::NonInteractive);
|
|---|
| 52 | };
|
|---|
| 53 |
|
|---|
| 54 | Dialog* CommandLineVerboseAction::fillDialog(Dialog *dialog) {
|
|---|
| 55 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
|---|
| 56 |
|
|---|
| 57 | dialog->queryInt(NAME, ValueStorage::getInstance().getDescription(NAME));
|
|---|
| 58 |
|
|---|
| 59 | return dialog;
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | Action::state_ptr CommandLineVerboseAction::performCall() {
|
|---|
| 63 | int verbosity = 2;
|
|---|
| 64 |
|
|---|
| 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;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | Action::state_ptr CommandLineVerboseAction::performUndo(Action::state_ptr _state) {
|
|---|
| 73 | CommandLineVerboseState *state = assert_cast<CommandLineVerboseState*>(_state.get());
|
|---|
| 74 |
|
|---|
| 75 | int verbosity = 2;
|
|---|
| 76 | ValueStorage::getInstance().queryCurrentValue(NAME, verbosity);
|
|---|
| 77 |
|
|---|
| 78 | setVerbosity(state->verbosity);
|
|---|
| 79 | return Action::state_ptr(new CommandLineVerboseState(verbosity));
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | Action::state_ptr CommandLineVerboseAction::performRedo(Action::state_ptr _state){
|
|---|
| 83 | return performUndo(_state);
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | bool CommandLineVerboseAction::canUndo() {
|
|---|
| 87 | return true;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | bool CommandLineVerboseAction::shouldUndo() {
|
|---|
| 91 | return true;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | const string CommandLineVerboseAction::getName() {
|
|---|
| 95 | return NAME;
|
|---|
| 96 | }
|
|---|