]> git.lyx.org Git - lyx.git/blob - src/undo.h
Convert the Search/Replace dialog to the cleaner MCV scheme.
[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 "ParagraphList_fwd.h"
20 #include "support/types.h"
21
22 class LCursor;
23 class LyXText;
24 class BufferView;
25
26 /**
27  * These are the elements put on the undo stack. Each object
28  * contains complete paragraphs and sufficient information
29  * to restore the state.
30  */
31 class Undo {
32 public:
33         /**
34          * The undo kinds are used to combine consecutive undo recordings
35          * of the same kind.
36          */
37         enum undo_kind {
38                 /**
39                  * Insert something - these will combine to one big chunk
40                  * when many inserts come after each other.
41                  */
42                 INSERT,
43
44                 /**
45                  * Delete something - these will combine to one big chunk
46                  * when many deletes come after each other.
47                  */
48                 DELETE,
49
50                 /// Atomic - each of these will have its own entry in the stack
51                 ATOMIC
52         };
53         /// constructor
54         Undo(undo_kind kind, int text, int index,
55                 int first_par, int end_par, int cursor_par, int cursor_pos);
56
57         /// which kind of operation are we recording for?
58         undo_kind kind;
59
60         /// hosting LyXText counted from buffer begin
61         int text;
62
63         /// cell in a tabular or similar
64         int index;
65
66         /// offset to the first paragraph in the paragraph list
67         int first_par;
68
69         /// offset to the last paragraph from the end of parargraph list
70         int end_par;
71
72         /// offset to the first paragraph in the paragraph list
73         int cursor_par;
74
75         /// the position of the cursor in the hosting paragraph
76         int cursor_pos;
77
78         /// the contents of the paragraphs saved
79         ParagraphList pars;
80 };
81
82
83 /// this will undo the last action - returns false if no undo possible
84 bool textUndo(BufferView *);
85
86 /// this will redo the last undo - returns false if no redo possible
87 bool textRedo(BufferView *);
88
89 /// makes sure the next operation will be stored
90 void finishUndo();
91
92 /// whilst undo is frozen, all actions do not get added to the undo stack
93 void freezeUndo();
94
95 /// track undos again
96 void unFreezeUndo();
97
98 /**
99  * Record undo information - call with the first paragraph that will be changed
100  * and the last paragraph that will be changed. So we give an inclusive
101  * range.
102  * This is called before you make the changes to the paragraph, and it
103  * will record the original information of the paragraphs in the undo stack.
104  */
105 void recordUndo(Undo::undo_kind kind,
106         LyXText const * text, lyx::paroffset_type first, lyx::paroffset_type last);
107
108 /// convienience: prepare undo when change in a single paragraph
109 void recordUndo(Undo::undo_kind kind,
110         LyXText const * text, lyx::paroffset_type par);
111
112 /// convienience: prepare undo for the paragraph that contains the cursor
113 void recordUndo(BufferView *, Undo::undo_kind kind);
114 void recordUndo(LCursor &, Undo::undo_kind kind);
115
116 /// are we avoiding tracking undos currently?
117 extern bool undo_frozen;
118
119 #endif // UNDO_FUNCS_H