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