source:
src/Actions/ActionHistory.hpp@
bcc29ca
| Last change on this file since bcc29ca was bcc29ca, checked in by , 2 months ago | |
|---|---|
|
|
| File size: 1.4 KB | |
| Rev | Line | |
|---|---|---|
| [d56640] | 1 | /* |
| 2 | * ActionHistory.hpp | |
| 3 | * | |
| 4 | * Created on: Mar 25, 2010 | |
| 5 | * Author: crueger | |
| 6 | */ | |
| 7 | ||
| 8 | #ifndef ACTIONHISTORY_HPP_ | |
| 9 | #define ACTIONHISTORY_HPP_ | |
| 10 | ||
| [56f73b] | 11 | // include config.h |
| 12 | #ifdef HAVE_CONFIG_H | |
| 13 | #include <config.h> | |
| 14 | #endif | |
| 15 | ||
| [d56640] | 16 | #include <deque> |
| [7d2ee1] | 17 | #include <stack> |
| [d56640] | 18 | |
| 19 | #include "Actions/Action.hpp" | |
| [bcc29ca] | 20 | #include "Actions/CommandAction/RedoAction.hpp" |
| 21 | #include "Actions/CommandAction/UndoAction.hpp" | |
| [d56640] | 22 | |
| [ce7fdc] | 23 | namespace MoleCuilder { |
| [d56640] | 24 | |
| [6367dd] | 25 | class ActionHistory |
| [d56640] | 26 | { |
| 27 | struct HistoryElement { | |
| [b5b01e] | 28 | HistoryElement(Action *_action, ActionState::ptr _state) : |
| [d56640] | 29 | action(_action), |
| 30 | state(_state) | |
| 31 | {} | |
| 32 | Action *action; | |
| [b5b01e] | 33 | ActionState::ptr state; |
| [d56640] | 34 | }; |
| 35 | ||
| 36 | public: | |
| [6367dd] | 37 | ActionHistory(); |
| 38 | ~ActionHistory(); | |
| [d56640] | 39 | |
| 40 | void undoLast(); | |
| 41 | void redoLast(); | |
| 42 | ||
| [f9352d] | 43 | bool hasUndo(); |
| 44 | bool hasRedo(); | |
| 45 | ||
| [0ec9f5] | 46 | void setMark(); |
| 47 | void unsetMark(); | |
| 48 | void undoTillMark(); | |
| 49 | ||
| [b5b01e] | 50 | void addElement(Action*,ActionState::ptr); |
| [d56640] | 51 | void clear(); |
| [6367dd] | 52 | |
| [d56640] | 53 | private: |
| 54 | std::deque<HistoryElement> history; | |
| 55 | std::deque<HistoryElement> yrotsih; | |
| 56 | ||
| [0ec9f5] | 57 | //!> marks a specific state in the history to allow undoing directly till that |
| [7d2ee1] | 58 | std::stack<HistoryElement *> marked; |
| [0ec9f5] | 59 | |
| [d56640] | 60 | public: |
| 61 | // when constructing the actions we need the Actionregistry Singleton | |
| 62 | // Singletons need static variables to work, but we cannot access statics | |
| 63 | // inside a static initialization, so we have this init function that | |
| 64 | // needs to be called at a non-static point at the start of the program | |
| [6367dd] | 65 | // static void init(); |
| [d56640] | 66 | }; |
| 67 | ||
| [ce7fdc] | 68 | } |
| 69 | ||
| [d56640] | 70 | #endif /* ACTIONHISTORY_HPP_ */ |
Note:
See TracBrowser
for help on using the repository browser.
