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