]> git.lyx.org Git - lyx.git/blob - src/Undo.h
InsetHyperlink.cpp: fix a bug I introduced in r26218
[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 /**
48  * Record undo information - call with the current cursor and the 'other
49  * end' of the range of changed  paragraphs.  So we give an inclusive range.
50  * This is called before you make the changes to the paragraph, and it
51  * will record the original information of the paragraphs in the undo stack.
52  *
53  * FIXME: We need something to record undo in partial grids for mathed.
54  * Right now we use recordUndoInset if more than one cell is changed,
55  * but that puts the cursor in front of the inset after undo. We would need
56  * something like
57  * recordUndoGrid(DocIterator & cur, UndoKind kind, idx_type from, idx_type to);
58  * and store the cell information in class Undo.
59  */
60 class Undo
61 {
62 public:
63
64         Undo(Buffer &);
65
66         ~Undo();
67
68         /// this will undo the last action - returns false if no undo possible
69         bool textUndo(DocIterator &);
70
71         /// this will redo the last undo - returns false if no redo possible
72         bool textRedo(DocIterator &);
73
74         /// makes sure the next operation will be stored
75         void finishUndo();
76
77         ///
78         bool hasUndoStack() const;
79         ///
80         bool hasRedoStack() const;
81
82         /// open a new group of undo operations. Groups can be nested.
83         void beginUndoGroup();
84
85         /// end the current undo group
86         void endUndoGroup();
87
88         /// The general case: prepare undo for an arbitrary range.
89         void recordUndo(DocIterator const & cur, UndoKind kind,
90                 pit_type from, pit_type to);
91
92         /// Convenience: prepare undo for the range between 'from' and cursor.
93         void recordUndo(DocIterator const & cur, UndoKind kind, pit_type from);
94
95         /// Convenience: prepare undo for the single paragraph or cell
96         /// containing the cursor
97         void recordUndo(DocIterator const & cur, UndoKind kind = ATOMIC_UNDO);
98         /// Convenience: prepare undo for the inset containing the cursor
99         void recordUndoInset(DocIterator const & cur, UndoKind kind = ATOMIC_UNDO);
100
101         /// Convenience: prepare undo for the whole buffer
102         void recordUndoFullDocument(DocIterator const & cur);
103
104 private:
105         struct Private;
106         Private * const d;
107 };
108
109
110
111 } // namespace lyx
112
113 #endif // UNDO_H