]> git.lyx.org Git - lyx.git/blob - src/undo.h
update build instructions (Qt 4.2.2 etc.)
[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 "dociterator.h"
20 #include "ParagraphList.h"
21 #include "bufferparams.h"
22
23 #include "support/types.h"
24
25 #include <string>
26
27
28 namespace lyx {
29
30 class BufferParams;
31 class BufferView;
32 class DocIterator;
33 class LCursor;
34
35
36 /**
37 These are the elements put on the undo stack. Each object contains complete
38 paragraphs from some cell and sufficient information to restore the cursor
39 state.
40
41 The cell is given by a DocIterator pointing to this cell, the 'interesting'
42 range of paragraphs by counting them from begin and end of cell,
43 respectively.
44
45 The cursor is also given as DocIterator and should point to some place in
46 the stored paragraph range.  In case of math, we simply store the whole
47 cell, as there usually is just a simple paragraph in a cell.
48
49 The idea is to store the contents of 'interesting' paragraphs in some
50 structure ('Undo') _before_ it is changed in some edit operation.
51 Obviously, the stored ranged should be as small as possible. However, it
52 there is a lower limit: The StableDocIterator pointing stored in the undo
53 class must be valid after the changes, too, as it will used as a pointer
54 where to insert the stored bits when performining undo.
55
56 */
57
58 class Undo {
59 public:
60         /// This is used to combine consecutive undo recordings of the same kind.
61         enum undo_kind {
62                 /**
63                  * Insert something - these will combine to one big chunk
64                  * when many inserts come after each other.
65                  */
66                 INSERT,
67                 /**
68                  * Delete something - these will combine to one big chunk
69                  * when many deletes come after each other.
70                  */
71                 DELETE,
72                 /// Atomic - each of these will have its own entry in the stack
73                 ATOMIC
74         };
75
76         /// Which kind of operation are we recording for?
77         undo_kind kind;
78         /// the position of the cursor
79         StableDocIterator cursor;
80         /// the position of the cell described
81         StableDocIterator cell;
82         /// counted from begin of cell
83         pit_type from;
84         /// complement to end of this cell
85         pit_type end;
86         /// the contents of the saved Paragraphs (for texted)
87         ParagraphList pars;
88         /// the stringified contents of the saved MathArray (for mathed)
89         docstring array;
90         /// Only used in case of full backups
91         BufferParams bparams;
92         /// Only used in case of full backups
93         bool isFullBuffer;
94 };
95
96
97 /// this will undo the last action - returns false if no undo possible
98 bool textUndo(BufferView & bv);
99
100 /// this will redo the last undo - returns false if no redo possible
101 bool textRedo(BufferView & bv);
102
103 /// makes sure the next operation will be stored
104 void finishUndo();
105
106
107 /**
108  * Record undo information - call with the current cursor and the 'other
109  * end' of the range of changed  paragraphs.  So we give an inclusive range.
110  * This is called before you make the changes to the paragraph, and it
111  * will record the original information of the paragraphs in the undo stack.
112  *
113  * FIXME: We need something to record undo in partial grids for mathed.
114  * Right now we use recordUndoInset if more than one cell is changed,
115  * but that puts the cursor in front of the inset after undo. We would need
116  * something like
117  * recordUndoGrid(LCursor & cur, Undo::undo_kind kind, idx_type from, idx_type to);
118  * and store the cell information in class Undo.
119  */
120
121 /// The general case: prepare undo for an arbitrary range.
122 /// FIXME: replace LCursor with DocIterator. This is not possible right
123 /// now because we need access to Buffer->params()!.
124 void recordUndo(LCursor & cur, Undo::undo_kind kind,
125         pit_type from, pit_type to);
126
127 /// Convenience: prepare undo for the range between 'from' and cursor.
128 void recordUndo(LCursor & cur, Undo::undo_kind kind, pit_type from);
129
130 /// Convenience: prepare undo for the single paragraph or cell
131 /// containing the cursor
132 void recordUndo(LCursor & cur, Undo::undo_kind kind = Undo::ATOMIC);
133 /// Convenience: prepare undo for the inset containing the cursor
134 void recordUndoInset(LCursor & cur, Undo::undo_kind kind = Undo::ATOMIC);
135 /// Convenience: prepare undo for the selected paragraphs
136 void recordUndoSelection(LCursor & cur, Undo::undo_kind kind = Undo::ATOMIC);
137
138 /// Convenience: prepare undo for the whole buffer
139 void recordUndoFullDocument(BufferView * bv);
140
141
142 } // namespace lyx
143
144 #endif // UNDO_FUNCS_H