Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/CmdAction/VerboseAction.cpp

    r623e89 r680470  
    66 */
    77
     8#include "Helpers/MemDebug.hpp"
     9
    810#include "Actions/CmdAction/VerboseAction.hpp"
     11#include "Actions/ActionRegistry.hpp"
    912#include "log.hpp"
    1013#include "verbose.hpp"
     
    1720#include "UIElements/UIFactory.hpp"
    1821#include "UIElements/Dialog.hpp"
    19 #include "Actions/MapOfActions.hpp"
     22#include "UIElements/ValueStorage.hpp"
     23
     24// memento to remember the state when undoing
     25
     26class CommandLineVerboseState : public ActionState {
     27public:
     28  CommandLineVerboseState(int _verbosity) :
     29    verbosity(_verbosity)
     30  {}
     31  int verbosity;
     32};
     33
    2034
    2135const char CommandLineVerboseAction::NAME[] = "verbose";
     
    2842{}
    2943
     44void CommandVerbose(int verbosity) {
     45  ValueStorage::getInstance().setCurrentValue(CommandLineVerboseAction::NAME, verbosity);
     46  ActionRegistry::getInstance().getActionByName(CommandLineVerboseAction::NAME)->call(Action::NonInteractive);
     47};
     48
     49Dialog* 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
    3057Action::state_ptr CommandLineVerboseAction::performCall() {
    31   Dialog *dialog = UIFactory::getInstance().makeDialog();
    3258  int verbosity = 2;
    3359
    34   dialog->queryInt(NAME, &verbosity, MapOfActions::getInstance().getDescription(NAME));
     60  ValueStorage::getInstance().queryCurrentValue(NAME, verbosity);
    3561
    36   if(dialog->display()) {
    37     setVerbosity(verbosity);
    38     DoLog(0) && (Log() << Verbose(0) << "Setting verbosity to " << verbosity << "." << endl);
    39     delete dialog;
    40     return Action::success;
    41   } else {
    42     delete dialog;
    43     return Action::failure;
    44   }
     62  setVerbosity(verbosity);
     63  DoLog(0) && (Log() << Verbose(0) << "Setting verbosity to " << verbosity << "." << endl);
     64  return Action::success;
    4565}
    4666
    4767Action::state_ptr CommandLineVerboseAction::performUndo(Action::state_ptr _state) {
    48 //  ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
     68  CommandLineVerboseState *state = assert_cast<CommandLineVerboseState*>(_state.get());
    4969
    50   return Action::failure;
    51 //  string newName = state->mol->getName();
    52 //  state->mol->setName(state->lastName);
    53 //
    54 //  return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
     70  int verbosity = 2;
     71  ValueStorage::getInstance().queryCurrentValue(NAME, verbosity);
     72
     73  setVerbosity(state->verbosity);
     74  return Action::state_ptr(new CommandLineVerboseState(verbosity));
    5575}
    5676
    5777Action::state_ptr CommandLineVerboseAction::performRedo(Action::state_ptr _state){
    58   return Action::failure;
     78  return performUndo(_state);
    5979}
    6080
    6181bool CommandLineVerboseAction::canUndo() {
    62   return false;
     82  return true;
    6383}
    6484
    6585bool CommandLineVerboseAction::shouldUndo() {
    66   return false;
     86  return true;
    6787}
    6888
Note: See TracChangeset for help on using the changeset viewer.