From 8cd29b9b30400e4275f1a65744cd0b3c2669cc98 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Tue, 6 Nov 2012 20:42:40 +0100 Subject: initial commit of SciTECO based on THECO --- undo.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 undo.cpp (limited to 'undo.cpp') 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 +#include + +#include + +#include + +#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 +void +UndoStack::push_var(Type &variable, Type value) +{ + UndoToken *token = new UndoTokenVariable(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; +} -- cgit v1.2.3