Changeset 0ec9f5 for src


Ignore:
Timestamp:
Apr 23, 2021, 9:02:12 PM (5 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
Candidate_v1.7.0, stable
Children:
0fbea3
Parents:
5061d9
git-author:
Frederik Heber <frederik.heber@…> (04/06/21 20:09:39)
git-committer:
Frederik Heber <frederik.heber@…> (04/23/21 21:02:12)
Message:

Added UndoMarkAction.

NOTE: This action is necessary as not all actions are actually recorded
in the history. For example, the UndoAction is an action that is not
pushed into the history deque and also must not as further undos would
then become impossible. There are other actions that just do output
or similar things that do not change the state.
This makes it impossible to undo back to a certain state by blindly
counting actions as one cannot know from the outside whether an action
is stateless or not.

undoing till the set mark.

  • TESTS: added regression test case on undo-mark.
Location:
src/Actions
Files:
3 added
8 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/ActionHistory.cpp

    r5061d9 r0ec9f5  
    6464  HistoryElement elem = history.back();
    6565  LOG(1, "INFO: Undoing action " << elem.action->getName());
     66  if ((mark != NULL) && (mark == &elem)) {
     67    LOG(2, "DEBUG: Undoing marked item in ActionHistory, hence resetting mark.");
     68    mark = NULL;
     69  }
    6670  history.pop_back();
    6771  ActionState::ptr newState = elem.action->undo(elem.state);
     
    9397}
    9498
     99void ActionHistory::setMark() {
     100  mark = &(history.back());
     101}
     102
     103void ActionHistory::unsetMark() {
     104  mark = NULL;
     105}
     106
     107void ActionHistory::undoTillMark() {
     108  if (mark == NULL) {
     109    undoLast();
     110  } else {
     111    while (mark != &(history.back()))
     112      undoLast();
     113  }
     114}
     115
    95116void ActionHistory::addElement(Action* action,ActionState::ptr state){
    96117  yrotsih.clear();
  • src/Actions/ActionHistory.hpp

    r5061d9 r0ec9f5  
    4343  bool hasRedo();
    4444
     45  void setMark();
     46  void unsetMark();
     47  void undoTillMark();
     48
    4549  void addElement(Action*,ActionState::ptr);
    4650  void clear();
     
    4953  std::deque<HistoryElement> history;
    5054  std::deque<HistoryElement> yrotsih;
     55
     56  //!> marks a specific state in the history to allow undoing directly till that
     57  HistoryElement * mark;
    5158
    5259public:
  • src/Actions/ActionQueue.cpp

    r5061d9 r0ec9f5  
    412412}
    413413
     414void ActionQueue::setMark() {
     415  history->setMark();
     416}
     417
     418void ActionQueue::unsetMark() {
     419  history->unsetMark();
     420}
     421
     422void ActionQueue::undoTillMark()
     423{
     424  history->undoTillMark();
     425}
     426
    414427bool ActionQueue::canUndo() const
    415428{
  • src/Actions/ActionQueue.hpp

    r5061d9 r0ec9f5  
    129129  void outputAsPython(std::ostream &output) const;
    130130
    131   /** Undoes last called Acfriend void ::cleanUp();tion.
     131  /** Undoes last called Action.
    132132   *
    133133   */
     
    138138   */
    139139  void redoLast();
     140
     141  /**
     142   * Marks the current item of the action history to allow returning to that state lateron.
     143   */
     144  void setMark();
     145
     146  /**
     147   * Resets any currently marked item in the action history.
     148   */
     149  void unsetMark();
     150
     151  /** Undoes actions till a set mark in the ActionHistory.
     152   *
     153   */
     154  void undoTillMark();
    140155
    141156  /** Checks whether there is one completed Action stored in ActionHistory in the past.
  • src/Actions/GlobalListOfActions.hpp

    r5061d9 r0ec9f5  
    5454  (CommandSetRandomNumbersDistribution) \
    5555  (CommandStoreSession) \
     56  (CommandUndoMark) \
    5657  (CommandVerbose) \
    5758  (CommandVersion) \
  • src/Actions/Makefile.am

    r5061d9 r0ec9f5  
    207207  Actions/CommandAction/NoDryRunAction.cpp \
    208208  Actions/CommandAction/StoreSessionAction.cpp \
     209  Actions/CommandAction/UndoMarkAction.cpp \
    209210  Actions/CommandAction/VerboseAction.cpp \
    210211  Actions/CommandAction/VersionAction.cpp \
     
    219220  Actions/CommandAction/NoDryRunAction.hpp \
    220221  Actions/CommandAction/StoreSessionAction.hpp \
     222  Actions/CommandAction/UndoMarkAction.hpp \
    221223  Actions/CommandAction/VerboseAction.hpp \
    222224  Actions/CommandAction/VersionAction.hpp \
     
    231233  Actions/CommandAction/NoDryRunAction.def \
    232234  Actions/CommandAction/StoreSessionAction.def \
     235  Actions/CommandAction/UndoMarkAction.def \
    233236  Actions/CommandAction/VerboseAction.def \
    234237  Actions/CommandAction/VersionAction.def \
  • src/Actions/UndoAction.cpp

    r5061d9 r0ec9f5  
    5252ActionState::ptr UndoAction::performCall(){
    5353  // std::cout << "Undo" << std::endl;
    54   ActionQueue::getInstance().undoLast();
     54  if (params.undoTillMark.get())
     55    ActionQueue::getInstance().undoTillMark();
     56  else
     57    ActionQueue::getInstance().undoLast();
    5558  return Action::success;
    5659}
  • src/Actions/UndoAction.def

    r5061d9 r0ec9f5  
    1313// ValueStorage by the token "Z" -> first column: int, Z, "Z"
    1414// "undefine" if no parameters are required, use (NOPARAM_DEFAULT) for each (undefined) default value
    15 #undef paramtypes
    16 #undef paramreferences
    17 #undef paramtokens
    18 #undef paramdescriptions
    19 #undef paramdefaults
     15#define paramtypes (bool)
     16#define paramtokens ("till-mark")
     17#define paramdescriptions ("whether to undo just a single step (false) or until a previously set mark (true)")
     18#define paramdefaults (PARAM_DEFAULT(false))
     19#define paramreferences (undoTillMark)
     20#define paramvalids (DummyValidator<bool>())
    2021
    2122// some defines for all the names, you may use ACTION, STATE and PARAMS
     
    2728
    2829// finally the information stored in the ActionTrait specialization
    29 #define DESCRIPTION "undo last action"
     30#define DESCRIPTION "undo last action or until a given mark"
    3031#undef SHORTFORM
Note: See TracChangeset for help on using the changeset viewer.