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