KTextEditor

kateundo.h
1/*
2 SPDX-FileCopyrightText: 2011 Dominik Haumann <dhaumann@kde.org>
3 SPDX-FileCopyrightText: 2009-2010 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
4 SPDX-FileCopyrightText: 2002 John Firebaugh <jfirebaugh@kde.org>
5 SPDX-FileCopyrightText: 2001 Christoph Cullmann <cullmann@kde.org>
6 SPDX-FileCopyrightText: 2001 Joseph Wenninger <jowenn@kde.org>
7 SPDX-FileCopyrightText: 2023 Waqar Ahmed <waqar.17a@gmail.com>
8
9 SPDX-License-Identifier: LGPL-2.0-or-later
10*/
11
12#ifndef kate_undo_h
13#define kate_undo_h
14
15#include <QList>
16
17#include <QBitArray>
18#include <kateview.h>
19#include <ktexteditor/range.h>
20
21class KateUndoManager;
22namespace KTextEditor
23{
24class DocumentPrivate;
25}
26
27class UndoItem
28{
29public:
30 enum UndoType {
31 editInsertText,
32 editRemoveText,
33 editWrapLine,
34 editUnWrapLine,
35 editInsertLine,
36 editRemoveLine,
37 editMarkLineAutoWrapped,
38 editInvalid
39 };
40
41 enum ModificationFlag {
42 UndoLine1Modified = 1,
43 UndoLine2Modified = 2,
44 UndoLine1Saved = 4,
45 UndoLine2Saved = 8,
46 RedoLine1Modified = 16,
47 RedoLine2Modified = 32,
48 RedoLine1Saved = 64,
49 RedoLine2Saved = 128
50 };
51 Q_DECLARE_FLAGS(ModificationFlags, ModificationFlag)
52
53 UndoType type = editInvalid;
54 ModificationFlags lineModFlags;
55 int line = 0;
56 int col = 0;
57 QString text;
58 bool autowrapped = false;
59 bool newLine = false;
60 bool removeLine = false;
61 int len = 0;
62};
63
64/**
65 * Class to manage a group of undo items
66 */
68{
69public:
70 /**
71 * Constructor
72 * @param manager KateUndoManager this undo group will belong to
73 */
74 explicit KateUndoGroup(const KTextEditor::Cursor cursorPosition,
75 KTextEditor::Range selection,
77
78 KateUndoGroup(const KateUndoGroup &) = delete;
79 KateUndoGroup &operator=(const KateUndoGroup &) = delete;
80
81 KateUndoGroup(KateUndoGroup &&o) = default;
82 KateUndoGroup &operator=(KateUndoGroup &&o) = default;
83
84public:
85 /**
86 * Undo the contained undo items
87 */
88 void undo(KateUndoManager *manager, KTextEditor::ViewPrivate *view);
89
90 /**
91 * Redo the contained undo items
92 */
93 void redo(KateUndoManager *manager, KTextEditor::ViewPrivate *view);
94
95 void editEnd(const KTextEditor::Cursor cursorPosition,
96 KTextEditor::Range selectionRange,
98
99 /**
100 * merge this group with an other
101 * @param newGroup group to merge into this one
102 * @param complex set if a complex undo
103 * @return success
104 */
105 bool merge(KateUndoGroup *newGroup, bool complex);
106
107 /**
108 * set group as as savepoint. the next group will not merge with this one
109 */
110 void safePoint(bool safePoint = true);
111
112 /**
113 * is this undogroup empty?
114 */
115 bool isEmpty() const
116 {
117 return m_items.empty();
118 }
119
120 /**
121 * Change all LineSaved flags to LineModified of the line modification system.
122 */
123 void flagSavedAsModified();
124
125 void markUndoAsSaved(QBitArray &lines);
126 void markRedoAsSaved(QBitArray &lines);
127
128 /**
129 * Set the undo cursor to @p cursor.
130 */
131 inline void setUndoCursor(const KTextEditor::Cursor cursor)
132 {
133 m_undoCursor = cursor;
134 }
135
136 /**
137 * Set the redo cursor to @p cursor.
138 */
139 inline void setRedoCursor(const KTextEditor::Cursor cursor)
140 {
141 m_redoCursor = cursor;
142 }
143
144 inline KTextEditor::Cursor redoCursor() const
145 {
146 return m_redoCursor;
147 }
148
149private:
150 /**
151 * singleType
152 * @return the type if it's only one type, or editInvalid if it contains multiple types.
153 */
154 UndoItem::UndoType singleType() const;
155
156 /**
157 * are we only of this type ?
158 * @param type type to query
159 * @return we contain only the given type
160 */
161 bool isOnlyType(UndoItem::UndoType type) const;
162
163public:
164 /**
165 * add an undo item
166 * @param u item to add
167 */
168 void addItem(UndoItem u);
169
170private:
171 /**
172 * list of items contained
173 */
174 std::vector<UndoItem> m_items;
175
176 /**
177 * prohibit merging with the next group
178 */
179 bool m_safePoint = false;
180 /*
181 * Selection Range of primary cursor
182 */
183 KTextEditor::Range m_undoSelection;
184 /*
185 * Selection Range of primary cursor
186 */
187 KTextEditor::Range m_redoSelection;
188
189 /**
190 * the cursor position of the active view before the edit step
191 */
192 KTextEditor::Cursor m_undoCursor;
193 /**
194 * the cursor positions of the active view before the edit step
195 */
197
198 /**
199 * the cursor position of the active view after the edit step
200 */
201 KTextEditor::Cursor m_redoCursor;
202 /**
203 * the cursor positions of the active view before the edit step
204 */
206};
207
208#endif
The Cursor represents a position in a Document.
Definition cursor.h:75
An object representing a section of text, from one Cursor to another.
Class to manage a group of undo items.
Definition kateundo.h:68
KateUndoGroup(const KTextEditor::Cursor cursorPosition, KTextEditor::Range selection, const QList< KTextEditor::ViewPrivate::PlainSecondaryCursor > &)
Constructor.
Definition kateundo.cpp:22
void setRedoCursor(const KTextEditor::Cursor cursor)
Set the redo cursor to cursor.
Definition kateundo.h:139
bool isEmpty() const
is this undogroup empty?
Definition kateundo.h:115
void addItem(UndoItem u)
add an undo item
Definition kateundo.cpp:214
void flagSavedAsModified()
Change all LineSaved flags to LineModified of the line modification system.
Definition kateundo.cpp:258
void setUndoCursor(const KTextEditor::Cursor cursor)
Set the undo cursor to cursor.
Definition kateundo.h:131
void redo(KateUndoManager *manager, KTextEditor::ViewPrivate *view)
Redo the contained undo items.
Definition kateundo.cpp:105
void safePoint(bool safePoint=true)
set group as as savepoint.
Definition kateundo.cpp:253
void undo(KateUndoManager *manager, KTextEditor::ViewPrivate *view)
Undo the contained undo items.
Definition kateundo.cpp:33
bool merge(KateUndoGroup *newGroup, bool complex)
merge this group with an other
Definition kateundo.cpp:225
KateUndoManager implements a document's history.
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:11:27 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.