4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "stringfile.inc"
31 #define UNDOLEVELS 500
32 #define UNDO_KEY_INTERVAL 100
34 // The undo stack is a series of key undo buffers and
35 // incremental undo buffers. The incremental buffers
36 // store the differences in the most compact way possible:
37 // a series of offsets, sizes and values. This should allow
38 // a huge number of undo updates.
41 class UndoStackItem : public ListItem<UndoStackItem>
47 // Must be inserted into the list before calling this, so it can get the
48 // previous key buffer.
49 void set_data(char *data);
50 void set_description(char *description);
51 void set_filename(char *filename);
52 const char* get_description();
53 void set_flags(uint64_t flags);
55 // Decompress the buffers and return them in a newly allocated string.
56 // The string must be deleted by the user.
65 // Get pointer to incremental data for use in an apply_difference command.
66 char* get_incremental_data();
67 int get_incremental_size();
69 void set_creator(void *creator);
73 // command description for the menu item
76 // key undo buffer or incremental undo buffer
79 // type of modification
82 // data after the modification for redos
86 // pointer to the object which set this undo buffer
89 char *session_filename;
92 class UndoStack : public List<UndoStackItem>
98 // Create a new undo entry and put on the stack.
99 // The current pointer points to the new entry.
100 // delete future undos if in the middle
101 // delete undos older than UNDOLEVELS if last
102 UndoStackItem* push();
104 // move to the previous undo entry
108 // move to the next undo entry for a redo
109 UndoStackItem* pull_next();
111 void dump(FILE *fp=stdout);
113 UndoStackItem* current;