r602: Fix baver's code... don't insert timecode when show_tc is not set
[cinelerra_cv/mob.git] / cinelerra / undostack.C
blob4d87e742a64be93b00b1daa36ad56b81ba616a5b
1 #include "undostack.h"
2 #include "undostackitem.h"
5 UndoStack::UndoStack() : List<UndoStackItem>()
7         current = 0;
10 UndoStack::~UndoStack()
14 void UndoStack::push(UndoStackItem *item)
16 // current is only 0 if before first undo
17         if(current)
18                 current = insert_after(current, item);
19         else
20                 current = insert_before(first, item);
21         
22 // delete future undos if necessary
23         if(current && current->next)
24         {
25                 while(current->next) remove(last);
26         }
29 int UndoStack::pull()
31         if(current) current = PREVIOUS;
34 UndoStackItem* UndoStack::pull_next()
36 // use first entry if none
37         if(!current) current = first;
38         else
39 // use next entry if there is a next entry
40         if(current->next)
41                 current = NEXT;
42 // don't change current if there is no next entry
43         else
44                 return 0;
45                 
46         return current;
49 // enforces that the undo stack does not exceed a size of UNDOMEMORY
50 // except that it always has at least UNDOMINLEVELS entries
51 void UndoStack::prune()
53         int size = 0;
54         int levels = 0;
56         UndoStackItem* i = last;
57         while (i != 0 && (levels < UNDOMINLEVELS || size <= UNDOMEMORY))
58         {
59                 size += i->get_size();
60                 ++levels;
61                 i = i->previous;
62         }
64         if (i != 0)
65         {
66 // truncate everything before and including i
67                 while (first != i)
68                         remove(first);
69                 remove(first);
70         }