]> git.lyx.org Git - lyx.git/blob - src/Undo.h
20e3445d60a5fe0810d1d62cc4eb27adc4a71265
[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 DocIterator;
27 class MathData;
28 class ParagraphList;
29
30 /// This is used to combine consecutive undo recordings of the same kind.
31 enum UndoKind {
32         /**
33         * Insert something - these will combine to one big chunk
34         * when many inserts come after each other.
35         */
36         INSERT_UNDO,
37         /**
38         * Delete something - these will combine to one big chunk
39         * when many deletes come after each other.
40         */
41         DELETE_UNDO,
42         /// Atomic - each of these will have its own entry in the stack
43         ATOMIC_UNDO
44 };
45
46
47 class Undo
48 {
49 public:
50
51         Undo(Buffer &);
52
53         ~Undo();
54
55         /// this will undo the last action - returns false if no undo possible
56         bool textUndo(DocIterator &);
57
58         /// this will redo the last undo - returns false if no redo possible
59         bool textRedo(DocIterator &);
60
61         /// End a sequence of INSERT_UNDO or DELETE_UNDO type of undo
62         /// operations.
63         void finishUndo();
64
65         ///
66         bool hasUndoStack() const;
67         ///
68         bool hasRedoStack() const;
69
70         /// open a new group of undo operations. Groups can be nested.
71         void beginUndoGroup();
72
73         /// end the current undo group.
74         void endUndoGroup();
75
76         /// The general case: record undo information for an arbitrary range.
77         /**
78          * Record undo information - call with the current cursor and
79          * the 'other end' of the range of changed paragraphs. So we
80          * give an inclusive range. This is called before you make the
81          * changes to the paragraph, and it will record the original
82          * information of the paragraphs in the undo stack.
83          *
84          * FIXME: We need something to record undo in partial grids
85          * for mathed. Right now we use recordUndoInset if more than
86          * one cell is changed, but that puts the cursor in front of
87          * the inset after undo. We would need something like
88          * recordUndoGrid(DocIterator & cur, UndoKind kind, idx_type
89          * from, idx_type to); and store the cell information in class
90          * Undo.
91          */
92         void recordUndo(DocIterator const & cur, UndoKind kind,
93                 pit_type from, pit_type to);
94
95         /// Convenience: record undo information for the range between
96         /// 'from' and cursor.
97         void recordUndo(DocIterator const & cur, UndoKind kind, pit_type from);
98
99         /// Convenience: record undo information for the single
100         /// paragraph or cell containing the cursor.
101         void recordUndo(DocIterator const & cur, UndoKind kind = ATOMIC_UNDO);
102
103         /// Convenience: record undo information for the inset
104         /// containing the cursor.
105         void recordUndoInset(DocIterator const & cur, 
106                              UndoKind kind = ATOMIC_UNDO);
107
108         /// Convenience: prepare undo for the whole buffer
109         void recordUndoFullDocument(DocIterator const & cur);
110
111 private:
112         struct Private;
113         Private * const d;
114 };
115
116
117
118 } // namespace lyx
119
120 #endif // UNDO_H