1 #include "stringfile.h"
5 UndoStack::UndoStack() : List<UndoStackItem>()
10 UndoStack::~UndoStack()
14 UndoStackItem* UndoStack::push()
16 // current is only 0 if before first undo
18 current = insert_after(current);
20 current = insert_before(first);
22 // delete future undos if necessary
23 if(current && current->next)
25 while(current->next) remove(last);
28 // delete oldest undo if necessary
29 if(total() > UNDOLEVELS) remove(first);
36 if(current) current = PREVIOUS;
39 UndoStackItem* UndoStack::pull_next()
41 // use first entry if none
42 if(!current) current = first;
44 // use next entry if there is a next entry
47 // don't change current if there is no next entry
60 UndoStackItem::UndoStackItem() : ListItem<UndoStackItem>()
62 description = type = data_after = data_before = 0;
65 UndoStackItem::~UndoStackItem()
67 if(description) delete [] description;
68 if(type) delete [] type;
69 if(data_after) delete [] data_after;
70 if(data_before) delete [] data_before;
73 int UndoStackItem::set_description(char *description)
75 this->description = new char[strlen(description) + 1];
76 strcpy(this->description, description);
79 int UndoStackItem::set_type(char *type)
81 this->type = new char[strlen(type) + 1];
82 strcpy(this->type, type);
85 int UndoStackItem::set_data_before(char *data)
87 this->data_before = new char[strlen(data) + 1];
88 strcpy(this->data_before, data);
91 int UndoStackItem::set_data_after(char *data)
93 this->data_after = new char[strlen(data) + 1];
94 strcpy(this->data_after, data);