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