23 #include "katedocument.h"
25 #include "katecursor.h"
63 bool merge(KateUndo* u);
69 void undo (KateDocument *doc);
75 void redo (KateDocument *doc);
97 inline uint line ()
const {
return m_line; }
103 inline uint col ()
const {
return m_col; }
109 inline uint len()
const {
return m_len; }
115 inline const TQString& text()
const {
return m_text; };
153 KateUndo::~KateUndo ()
157 bool KateUndo::isValid()
159 if (m_type == KateUndoGroup::editInsertText || m_type == KateUndoGroup::editRemoveText)
166 bool KateUndo::merge(KateUndo* u)
168 if (m_type != u->type())
171 if (m_type == KateUndoGroup::editInsertText
172 && m_line == u->line()
173 && (m_col + m_len) == u->col())
179 else if (m_type == KateUndoGroup::editRemoveText
180 && m_line == u->line()
181 && m_col == (u->col() + u->len()))
183 m_text.prepend(u->text());
192 void KateUndo::undo (KateDocument *doc)
194 if (m_type == KateUndoGroup::editInsertText)
196 doc->editRemoveText (m_line, m_col, m_len);
198 else if (m_type == KateUndoGroup::editRemoveText)
200 doc->editInsertText (m_line, m_col, m_text);
202 else if (m_type == KateUndoGroup::editWrapLine)
204 doc->editUnWrapLine (m_line, (m_text ==
"1"), m_len);
206 else if (m_type == KateUndoGroup::editUnWrapLine)
208 doc->editWrapLine (m_line, m_col, (m_text ==
"1"));
210 else if (m_type == KateUndoGroup::editInsertLine)
212 doc->editRemoveLine (m_line);
214 else if (m_type == KateUndoGroup::editRemoveLine)
216 doc->editInsertLine (m_line, m_text);
218 else if (m_type == KateUndoGroup::editMarkLineAutoWrapped)
220 doc->editMarkLineAutoWrapped (m_line, m_col == 0);
224 void KateUndo::redo (KateDocument *doc)
226 if (m_type == KateUndoGroup::editRemoveText)
228 doc->editRemoveText (m_line, m_col, m_len);
230 else if (m_type == KateUndoGroup::editInsertText)
232 doc->editInsertText (m_line, m_col, m_text);
234 else if (m_type == KateUndoGroup::editUnWrapLine)
236 doc->editUnWrapLine (m_line, (m_text ==
"1"), m_len);
238 else if (m_type == KateUndoGroup::editWrapLine)
240 doc->editWrapLine (m_line, m_col, (m_text ==
"1"));
242 else if (m_type == KateUndoGroup::editRemoveLine)
244 doc->editRemoveLine (m_line);
246 else if (m_type == KateUndoGroup::editInsertLine)
248 doc->editInsertLine (m_line, m_text);
250 else if (m_type == KateUndoGroup::editMarkLineAutoWrapped)
252 doc->editMarkLineAutoWrapped (m_line, m_col == 1);
258 if (m_type == KateUndoGroup::editInsertLine || m_type == KateUndoGroup::editUnWrapLine)
260 else if (m_type == KateUndoGroup::editRemoveText)
268 if (m_type == KateUndoGroup::editRemoveLine || m_type == KateUndoGroup::editWrapLine)
270 else if (m_type == KateUndoGroup::editInsertText)
277 : m_doc (doc),m_safePoint(false)
279 m_items.setAutoDelete (
true);
288 if (m_items.count() == 0)
291 m_doc->editStart (
false);
293 for (KateUndo* u = m_items.last(); u; u = m_items.prev())
296 if (m_doc->activeView())
298 for (uint z=0; z < m_items.count(); z++)
299 if (m_items.at(z)->type() != KateUndoGroup::editMarkLineAutoWrapped)
301 m_doc->activeView()->editSetCursor (m_items.at(z)->cursorBefore());
311 if (m_items.count() == 0)
314 m_doc->editStart (
false);
316 for (KateUndo* u = m_items.first(); u; u = m_items.next())
319 if (m_doc->activeView())
321 for (uint z=0; z < m_items.count(); z++)
322 if (m_items.at(z)->type() != KateUndoGroup::editMarkLineAutoWrapped)
324 m_doc->activeView()->editSetCursor (m_items.at(z)->cursorAfter());
334 addItem(
new KateUndo(type, line, col, len, text));
341 else if (m_items.last() && m_items.last()->merge(u))
349 if (m_safePoint)
return false;
350 if (newGroup->isOnlyType(singleType()) || complex) {
352 KateUndo* u = newGroup->m_items.take(0);
355 u = newGroup->m_items.take(0);
371 for (KateUndo* u = m_items.first(); u; u = m_items.next()) {
372 if (ret == editInvalid)
374 else if (ret != u->type())
383 if (type == editInvalid)
return false;
385 for (KateUndo* u = m_items.first(); u; u = m_items.next())
386 if (u->type() != type)
Simple cursor class with no document pointer.
Class to manage a group of undo items.
void redo()
Redo the contained undo items.
~KateUndoGroup()
Destructor.
void undo()
Undo the contained undo items.
void addItem(KateUndoGroup::UndoType type, uint line, uint col, uint len, const TQString &text)
add an item to the group
KateUndoGroup(KateDocument *doc)
Constructor.
UndoType
Types for undo items.
void safePoint(bool safePoint=true)
set group as as savepoint.
bool merge(KateUndoGroup *newGroup, bool complex)
merge this group with an other
const TDEShortcut & redo()
const TDEShortcut & undo()