| 1 | /*
 | 
|---|
| 2 |  * VerboseAction.cpp
 | 
|---|
| 3 |  *
 | 
|---|
| 4 |  *  Created on: May 9, 2010
 | 
|---|
| 5 |  *      Author: heber
 | 
|---|
| 6 |  */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | #include "Helpers/MemDebug.hpp"
 | 
|---|
| 9 | 
 | 
|---|
| 10 | #include "Actions/CmdAction/VerboseAction.hpp"
 | 
|---|
| 11 | #include "Actions/ActionRegistry.hpp"
 | 
|---|
| 12 | #include "Helpers/Log.hpp"
 | 
|---|
| 13 | #include "Helpers/Verbose.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 "Actions/ValueStorage.hpp"
 | 
|---|
| 23 | 
 | 
|---|
| 24 | // memento to remember the state when undoing
 | 
|---|
| 25 | 
 | 
|---|
| 26 | class CommandLineVerboseState : public ActionState {
 | 
|---|
| 27 | public:
 | 
|---|
| 28 |   CommandLineVerboseState(int _verbosity) :
 | 
|---|
| 29 |     verbosity(_verbosity)
 | 
|---|
| 30 |   {}
 | 
|---|
| 31 |   int verbosity;
 | 
|---|
| 32 | };
 | 
|---|
| 33 | 
 | 
|---|
| 34 | 
 | 
|---|
| 35 | const char CommandLineVerboseAction::NAME[] = "verbose";
 | 
|---|
| 36 | 
 | 
|---|
| 37 | CommandLineVerboseAction::CommandLineVerboseAction() :
 | 
|---|
| 38 |   Action(NAME)
 | 
|---|
| 39 | {}
 | 
|---|
| 40 | 
 | 
|---|
| 41 | CommandLineVerboseAction::~CommandLineVerboseAction()
 | 
|---|
| 42 | {}
 | 
|---|
| 43 | 
 | 
|---|
| 44 | void CommandVerbose(int verbosity) {
 | 
|---|
| 45 |   ValueStorage::getInstance().setCurrentValue(CommandLineVerboseAction::NAME, verbosity);
 | 
|---|
| 46 |   ActionRegistry::getInstance().getActionByName(CommandLineVerboseAction::NAME)->call(Action::NonInteractive);
 | 
|---|
| 47 | };
 | 
|---|
| 48 | 
 | 
|---|
| 49 | Dialog* CommandLineVerboseAction::fillDialog(Dialog *dialog) {
 | 
|---|
| 50 |   ASSERT(dialog,"No Dialog given when filling action dialog");
 | 
|---|
| 51 | 
 | 
|---|
| 52 |   dialog->queryInt(NAME, ValueStorage::getInstance().getDescription(NAME));
 | 
|---|
| 53 | 
 | 
|---|
| 54 |   return dialog;
 | 
|---|
| 55 | }
 | 
|---|
| 56 | 
 | 
|---|
| 57 | Action::state_ptr CommandLineVerboseAction::performCall() {
 | 
|---|
| 58 |   int verbosity = 2;
 | 
|---|
| 59 | 
 | 
|---|
| 60 |   ValueStorage::getInstance().queryCurrentValue(NAME, verbosity);
 | 
|---|
| 61 | 
 | 
|---|
| 62 |   setVerbosity(verbosity);
 | 
|---|
| 63 |   DoLog(0) && (Log() << Verbose(0) << "Setting verbosity to " << verbosity << "." << endl);
 | 
|---|
| 64 |   return Action::success;
 | 
|---|
| 65 | }
 | 
|---|
| 66 | 
 | 
|---|
| 67 | Action::state_ptr CommandLineVerboseAction::performUndo(Action::state_ptr _state) {
 | 
|---|
| 68 |   CommandLineVerboseState *state = assert_cast<CommandLineVerboseState*>(_state.get());
 | 
|---|
| 69 | 
 | 
|---|
| 70 |   int verbosity = 2;
 | 
|---|
| 71 |   ValueStorage::getInstance().queryCurrentValue(NAME, verbosity);
 | 
|---|
| 72 | 
 | 
|---|
| 73 |   setVerbosity(state->verbosity);
 | 
|---|
| 74 |   return Action::state_ptr(new CommandLineVerboseState(verbosity));
 | 
|---|
| 75 | }
 | 
|---|
| 76 | 
 | 
|---|
| 77 | Action::state_ptr CommandLineVerboseAction::performRedo(Action::state_ptr _state){
 | 
|---|
| 78 |   return performUndo(_state);
 | 
|---|
| 79 | }
 | 
|---|
| 80 | 
 | 
|---|
| 81 | bool CommandLineVerboseAction::canUndo() {
 | 
|---|
| 82 |   return true;
 | 
|---|
| 83 | }
 | 
|---|
| 84 | 
 | 
|---|
| 85 | bool CommandLineVerboseAction::shouldUndo() {
 | 
|---|
| 86 |   return true;
 | 
|---|
| 87 | }
 | 
|---|
| 88 | 
 | 
|---|
| 89 | const string CommandLineVerboseAction::getName() {
 | 
|---|
| 90 |   return NAME;
 | 
|---|
| 91 | }
 | 
|---|