]> git.lyx.org Git - lyx.git/blob - src/undo.h
the DocIterator stuff
[lyx.git] / src / undo.h
1 // -*- C++ -*-
2 /**
3  * \file undo.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Asger Alstrup
8  * \author Lars Gullik Bjønnes
9  * \author John Levon
10  * \author André Pönitz
11  * \author Jürgen Vigna
12  *
13  * Full author contact details are available in file CREDITS.
14  */
15
16 #ifndef UNDO_H
17 #define UNDO_H
18
19 #include "ParagraphList_fwd.h"
20 #include "support/types.h"
21
22 #include <string>
23
24 class LCursor;
25 class BufferView;
26
27
28 /**
29  * These are the elements put on the undo stack. Each object
30  * contains complete paragraphs and sufficient information
31  * to restore the state.
32  */
33 struct Undo {
34         /// This is used to combine consecutive undo recordings of the same kind.
35         enum undo_kind {
36                 /**
37                  * Insert something - these will combine to one big chunk
38                  * when many inserts come after each other.
39                  */
40                 INSERT,
41                 /**
42                  * Delete something - these will combine to one big chunk
43                  * when many deletes come after each other.
44                  */
45                 DELETE,
46                 /// Atomic - each of these will have its own entry in the stack
47                 ATOMIC
48         };
49
50         /// which kind of operation are we recording for?
51         undo_kind kind;
52         /// hosting LyXText counted from buffer begin
53         int text;
54         /// cell in a tabular or similar
55         int index;
56         /// offset to the first paragraph in the paragraph list
57         int first_par;
58         /// offset to the last paragraph from the end of paragraph list
59         int end_par;
60         /// offset to the first paragraph in the paragraph list
61         int cursor_par;
62         /// the position of the cursor in the hosting paragraph
63         int cursor_pos;
64         /// the contents of the saved paragraphs (for texted)
65         ParagraphList pars;
66         /// the contents of the saved matharray (for mathed)
67         std::string array;
68         /// in mathed?
69         bool math;
70 };
71
72
73 /// this will undo the last action - returns false if no undo possible
74 bool textUndo(BufferView &);
75
76 /// this will redo the last undo - returns false if no redo possible
77 bool textRedo(BufferView &);
78
79 /// makes sure the next operation will be stored
80 void finishUndo();
81
82 /// whilst undo is frozen, no actions gets added to the undo stack
83 void freezeUndo();
84
85 /// track undos again
86 void unFreezeUndo();
87
88
89 /**
90  * Record undo information - call with the current cursor and the 'other
91  * end' of the range of changed  paragraphs.  So we give an inclusive range.
92  * This is called before you make the changes to the paragraph, and it
93  * will record the original information of the paragraphs in the undo stack.
94  */
95
96 /// the common case: prepare undo for an arbitrary range
97 void recordUndo(LCursor & cur, Undo::undo_kind kind,
98         lyx::paroffset_type from, lyx::paroffset_type to);
99
100 /// convienience: prepare undo for the range between 'from' and cursor.
101 void recordUndo(LCursor & cur, Undo::undo_kind kind, lyx::paroffset_type from);
102
103 /// convienience: prepare undo for the single paragraph containing the cursor
104 void recordUndo(LCursor & cur, Undo::undo_kind kind = Undo::ATOMIC);
105 /// convienience: prepare undo for the selected paragraphs
106 void recordUndoSelection(LCursor & cur, Undo::undo_kind kind = Undo::ATOMIC);
107
108 /// convienience: prepare undo for the single paragraph containing the cursor
109 void recordUndoFullDocument(LCursor & cur);
110
111 #endif // UNDO_FUNCS_H