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