diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-11-06 20:42:40 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-11-06 20:42:40 +0100 |
commit | 8cd29b9b30400e4275f1a65744cd0b3c2669cc98 (patch) | |
tree | f6297b44f6b7d9d6546311878070383d2d064f45 /undo.cpp | |
download | sciteco-8cd29b9b30400e4275f1a65744cd0b3c2669cc98.tar.gz |
initial commit of SciTECO based on THECO
Diffstat (limited to 'undo.cpp')
-rw-r--r-- | undo.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/undo.cpp b/undo.cpp new file mode 100644 index 0000000..f5fc81d --- /dev/null +++ b/undo.cpp @@ -0,0 +1,57 @@ +#include <string.h> +#include <bsd/sys/queue.h> + +#include <glib.h> + +#include <Scintilla.h> + +#include "sciteco.h" +#include "undo.h" + +UndoStack undo; + +UndoToken::UndoToken() : pos(strlen(cmdline)) {} + +void +UndoTokenMessage::run(void) +{ + editor_msg(iMessage, wParam, lParam); +} + +void +UndoStack::push_msg(unsigned int iMessage, uptr_t wParam, sptr_t lParam) +{ + UndoToken *token = new UndoTokenMessage(iMessage, wParam, lParam); + SLIST_INSERT_HEAD(&head, token, tokens); +} + +#if 0 +template <typename Type> +void +UndoStack::push_var(Type &variable, Type value) +{ + UndoToken *token = new UndoTokenVariable<Type>(variable, value); + SLIST_INSERT_HEAD(&head, token, tokens); +} +#endif + +void +UndoStack::pop(gint pos) +{ + while (!SLIST_EMPTY(&head) && SLIST_FIRST(&head)->pos >= pos) { + UndoToken *top = SLIST_FIRST(&head); + + top->run(); + + SLIST_REMOVE_HEAD(&head, tokens); + delete top; + } +} + +UndoStack::~UndoStack() +{ + UndoToken *token, *next; + + SLIST_FOREACH_SAFE(token, &head, tokens, next) + delete token; +} |