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 { editInsertText, editRemoveText, editWrapLine, editUnWrapLine, editInsertLine, editRemoveLine, editMarkLineAutoWrapped, editInvalid };
31
32 enum ModificationFlag {
33 UndoLine1Modified = 1,
34 UndoLine2Modified = 2,
35 UndoLine1Saved = 4,
36 UndoLine2Saved = 8,
37 RedoLine1Modified = 16,
38 RedoLine2Modified = 32,
39 RedoLine1Saved = 64,
40 RedoLine2Saved = 128
41 };
42 Q_DECLARE_FLAGS(ModificationFlags, ModificationFlag)
43
44 UndoType type = editInvalid;
45 ModificationFlags lineModFlags;
46 int line = 0;
47 int col = 0;
48 QString text;
49 bool autowrapped = false;
50 bool newLine = false;
51 bool removeLine = false;
52 int len = 0;
53};
54
55/**
56 * Class to manage a group of undo items
57 */
59{
60public:
61 /**
62 * Constructor
63 * @param manager KateUndoManager this undo group will belong to
64 */
65 explicit KateUndoGroup(const KTextEditor::Cursor cursorPosition,
66 KTextEditor::Range selection,
68
69 KateUndoGroup(const KateUndoGroup &) = delete;
70 KateUndoGroup &operator=(const KateUndoGroup &) = delete;
71
72 KateUndoGroup(KateUndoGroup &&o) = default;
73 KateUndoGroup &operator=(KateUndoGroup &&o) = default;
74
75public:
76 /**
77 * Undo the contained undo items
78 */
79 void undo(KateUndoManager *manager, KTextEditor::ViewPrivate *view);
80
81 /**
82 * Redo the contained undo items
83 */
84 void redo(KateUndoManager *manager, KTextEditor::ViewPrivate *view);
85
86 void editEnd(const KTextEditor::Cursor cursorPosition,
87 KTextEditor::Range selectionRange,
89
90 /**
91 * merge this group with an other
92 * @param newGroup group to merge into this one
93 * @param complex set if a complex undo
94 * @return success
95 */
96 bool merge(KateUndoGroup *newGroup, bool complex);
97
98 /**
99 * set group as as savepoint. the next group will not merge with this one
100 */
101 void safePoint(bool safePoint = true);
102
103 /**
104 * is this undogroup empty?
105 */
106 bool isEmpty() const
107 {
108 return m_items.empty();
109 }
110
111 /**
112 * Change all LineSaved flags to LineModified of the line modification system.
113 */
114 void flagSavedAsModified();
115
116 void markUndoAsSaved(QBitArray &lines);
117 void markRedoAsSaved(QBitArray &lines);
118
119 /**
120 * Set the undo cursor to @p cursor.
121 */
122 inline void setUndoCursor(const KTextEditor::Cursor cursor)
123 {
124 m_undoCursor = cursor;
125 }
126
127 /**
128 * Set the redo cursor to @p cursor.
129 */
130 inline void setRedoCursor(const KTextEditor::Cursor cursor)
131 {
132 m_redoCursor = cursor;
133 }
134
135 inline KTextEditor::Cursor redoCursor() const
136 {
137 return m_redoCursor;
138 }
139
140private:
141 /**
142 * singleType
143 * @return the type if it's only one type, or editInvalid if it contains multiple types.
144 */
145 UndoItem::UndoType singleType() const;
146
147 /**
148 * are we only of this type ?
149 * @param type type to query
150 * @return we contain only the given type
151 */
152 bool isOnlyType(UndoItem::UndoType type) const;
153
154public:
155 /**
156 * add an undo item
157 * @param u item to add
158 */
159 void addItem(UndoItem u);
160
161private:
162 /**
163 * list of items contained
164 */
165 std::vector<UndoItem> m_items;
166
167 /**
168 * prohibit merging with the next group
169 */
170 bool m_safePoint = false;
171 /*
172 * Selection Range of primary cursor
173 */
174 KTextEditor::Range m_undoSelection;
175 /*
176 * Selection Range of primary cursor
177 */
178 KTextEditor::Range m_redoSelection;
179
180 /**
181 * the cursor position of the active view before the edit step
182 */
183 KTextEditor::Cursor m_undoCursor;
184 /**
185 * the cursor positions of the active view before the edit step
186 */
188
189 /**
190 * the cursor position of the active view after the edit step
191 */
192 KTextEditor::Cursor m_redoCursor;
193 /**
194 * the cursor positions of the active view before the edit step
195 */
197};
198
199#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:59
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:130
bool isEmpty() const
is this undogroup empty?
Definition kateundo.h:106
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:122
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 Fri Jun 14 2024 11:57:26 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.