]> git.lyx.org Git - lyx.git/blob - src/undo.h
gnome build removal, gtk build fix
[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 class 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 class Undo {
53 public:
54         /// This is used to combine consecutive undo recordings of the same kind.
55         enum undo_kind {
56                 /**
57                  * Insert something - these will combine to one big chunk
58                  * when many inserts come after each other.
59                  */
60                 INSERT,
61                 /**
62                  * Delete something - these will combine to one big chunk
63                  * when many deletes come after each other.
64                  */
65                 DELETE,
66                 /// Atomic - each of these will have its own entry in the stack
67                 ATOMIC
68         };
69
70         /// Which kind of operation are we recording for?
71         undo_kind kind;
72         /// the position of the cursor
73         StableDocIterator cursor;
74         /// the position of the cell described
75         StableDocIterator cell;
76         /// counted from begin of cell
77         lyx::pit_type from;
78         /// complement to end of this cell
79         lyx::pit_type end;
80         /// the contents of the saved Paragraphs (for texted)
81         ParagraphList pars;
82         /// the stringified contents of the saved MathArray (for mathed)
83         std::string array;
84 };
85
86
87 /// this will undo the last action - returns false if no undo possible
88 bool textUndo(BufferView & bv);
89
90 /// this will redo the last undo - returns false if no redo possible
91 bool textRedo(BufferView & bv);
92
93 /// makes sure the next operation will be stored
94 void finishUndo();
95
96
97 /**
98  * Record undo information - call with the current cursor and the 'other
99  * end' of the range of changed  paragraphs.  So we give an inclusive range.
100  * This is called before you make the changes to the paragraph, and it
101  * will record the original information of the paragraphs in the undo stack.
102  */
103
104 /// The general case: prepare undo for an arbitrary range.
105 void recordUndo(LCursor & cur, Undo::undo_kind kind,
106         lyx::pit_type from, lyx::pit_type to);
107
108 /// Convenience: prepare undo for the range between 'from' and cursor.
109 void recordUndo(LCursor & cur, Undo::undo_kind kind, lyx::pit_type from);
110
111 /// Convenience: prepare undo for the single paragraph or cell
112 /// containing the cursor
113 void recordUndo(LCursor & cur, Undo::undo_kind kind = Undo::ATOMIC);
114 /// Convenience: prepare undo for the inset containing the cursor
115 void recordUndoInset(LCursor & cur, Undo::undo_kind kind = Undo::ATOMIC);
116 /// Convenience: prepare undo for the selected paragraphs
117 void recordUndoSelection(LCursor & cur, Undo::undo_kind kind = Undo::ATOMIC);
118
119 /// Convenience: prepare undo for the single paragraph containing the cursor
120 void recordUndoFullDocument(LCursor & cur);
121
122 #endif // UNDO_FUNCS_H