r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / undostack.C
bloba1c6faa9cb1e63da8d60603732c73afd3c08bd5a
1 #include "stringfile.h"
2 #include "undostack.h"
3 #include <string.h>
5 UndoStack::UndoStack() : List<UndoStackItem>()
7         current = 0;
10 UndoStack::~UndoStack()
14 UndoStackItem* UndoStack::push()
16 // current is only 0 if before first undo
17         if(current)
18                 current = insert_after(current);
19         else
20                 current = insert_before(first);
21         
22 // delete future undos if necessary
23         if(current && current->next)
24         {
25                 while(current->next) remove(last);
26         }
28 // delete oldest undo if necessary
29         if(total() > UNDOLEVELS) remove(first);
30         
31         return current;
34 int UndoStack::pull()
36         if(current) current = PREVIOUS;
39 UndoStackItem* UndoStack::pull_next()
41 // use first entry if none
42         if(!current) current = first;
43         else
44 // use next entry if there is a next entry
45         if(current->next)
46                 current = NEXT;
47 // don't change current if there is no next entry
48         else
49                 return 0;
50                 
51         return current;
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);