]> git.lyx.org Git - lyx.git/blob - src/Undo.h
tex2lyx: support for multiple indices and subindices
[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  * \author Abdelrazak Younes
13  *
14  * Full author contact details are available in file CREDITS.
15  */
16
17 #ifndef UNDO_H
18 #define UNDO_H
19
20 #include "support/types.h"
21
22 namespace lyx {
23
24 class Buffer;
25 class BufferParams;
26 class CursorData;
27 class Inset;
28 class MathData;
29 class ParagraphList;
30
31 /// This is used to combine consecutive undo recordings of the same kind.
32 enum UndoKind {
33         /**
34         * Insert something - these will combine to one big chunk
35         * when many inserts come after each other.
36         */
37         INSERT_UNDO,
38         /**
39         * Delete something - these will combine to one big chunk
40         * when many deletes come after each other.
41         */
42         DELETE_UNDO,
43         /// Atomic - each of these will have its own entry in the stack
44         ATOMIC_UNDO
45 };
46
47
48 class Undo
49 {
50 public:
51
52         Undo(Buffer &);
53
54         ~Undo();
55
56         /// Clear out all undo/redo contents.
57         void clear();
58
59         /// this will undo the last action - returns false if no undo possible
60         bool textUndo(CursorData &);
61
62         /// this will redo the last undo - returns false if no redo possible
63         bool textRedo(CursorData &);
64
65         /// End a sequence of INSERT_UNDO or DELETE_UNDO type of undo
66         /// operations (grouping of consecutive characters insertion/deletion).
67         void finishUndo();
68
69         ///
70         bool hasUndoStack() const;
71         ///
72         bool hasRedoStack() const;
73
74         /// Mark all the elements of the undo and redo stacks as dirty
75         void markDirty();
76
77         /// open a new group of undo operations.
78         /**
79          *  Groups can be nested. Such a nested group e.g. { {} {} } is undone in
80          *  a single step. This means you can add a group whenever you are not sure.
81          */
82         void beginUndoGroup();
83
84         /// end the current undo group.
85         void endUndoGroup();
86
87         /// end the current undo group and set UndoElement::cur_after if necessary.
88         void endUndoGroup(CursorData const &);
89
90         /// The general case: record undo information for an arbitrary range.
91         /**
92          * Record undo information - call with the current cursor and
93          * the 'other end' of the range of changed paragraphs. So we
94          * give an inclusive range. This is called before you make the
95          * changes to the paragraph, and it will record the original
96          * information of the paragraphs in the undo stack.
97          */
98         void recordUndo(CursorData const & cur, UndoKind kind,
99                 pit_type from, pit_type to);
100
101         /// Convenience: record undo information for the range between
102         /// 'from' and cursor.
103         void recordUndo(CursorData const & cur, UndoKind kind, pit_type from);
104
105         /// Convenience: record undo information for the single
106         /// paragraph or cell containing the cursor.
107         void recordUndo(CursorData const & cur, UndoKind kind = ATOMIC_UNDO);
108
109         /// Convenience: record undo information for the inset
110         /// containing the cursor.
111         void recordUndoInset(CursorData const & cur,
112                              UndoKind kind = ATOMIC_UNDO,
113                              Inset const * inset = 0);
114
115         /// Convenience: prepare undo for the whole buffer
116         void recordUndoFullDocument(CursorData const & cur);
117
118 private:
119         struct Private;
120         Private * const d;
121 };
122
123
124
125 } // namespace lyx
126
127 #endif // UNDO_H