2
2
This file is part of the KDE project
3
3
* Copyright (C) 2009 Ganesh Paramasivam <ganesh@crystalfab.com>
4
4
* Copyright (C) 2009 Pierre Stirnweiss <pstirnweiss@googlemail.com>
5
* Copyright (C) 2010 Thomas Zander <zander@kde.org>
6
7
* This library is free software; you can redistribute it and/or
7
8
* modify it under the terms of the GNU Library General Public
79
81
TextCommandBase::undo();
80
82
UndoRedoFinalizer finalizer(this);
82
QTextDocument *document = m_tool->m_textEditor->document();
84
QTextDocument *document = m_tool->m_textEditor.data()->document();
83
85
KoTextDocument(document).changeTracker()->elementById(m_addedChangeElement)->setValid(false);
84
86
foreach (int changeId, m_removedElements) {
85
87
KoTextDocument(document).changeTracker()->elementById(changeId)->setValid(true);
95
97
TextCommandBase::redo();
96
98
UndoRedoFinalizer finalizer(this);
97
QTextDocument *document = m_tool->m_textEditor->document();
99
QTextDocument *document = m_tool->m_textEditor.data()->document();
98
100
KoTextDocument(document).changeTracker()->elementById(m_addedChangeElement)->setValid(true);
99
101
foreach (int changeId, m_removedElements) {
100
102
KoTextDocument(document).changeTracker()->elementById(changeId)->setValid(false);
104
m_tool->m_textEditor->beginEditBlock();
106
m_tool->m_textEditor.data()->beginEditBlock();
105
107
if(m_mode == PreviousChar)
106
108
deletePreviousChar();
109
m_tool->m_textEditor->endEditBlock();
111
m_tool->m_textEditor.data()->endEditBlock();
113
115
void ChangeTrackedDeleteCommand::deleteChar()
115
QTextCursor *caret = m_tool->m_textEditor->cursor();
117
QTextCursor *caret = m_tool->m_textEditor.data()->cursor();
117
119
if (caret->atEnd() && !caret->hasSelection())
126
128
void ChangeTrackedDeleteCommand::deletePreviousChar()
128
QTextCursor *caret = m_tool->m_textEditor->cursor();
130
QTextCursor *caret = m_tool->m_textEditor.data()->cursor();
130
132
if (caret->atStart() && !caret->hasSelection())
177
179
selection.insertBlock();
178
180
// Mark it as inserted content
179
181
QTextCharFormat format = selection.charFormat();
180
m_tool->m_textEditor->registerTrackedChange(selection, KoGenChange::insertChange, i18n("Key Press"), format, format, false);
182
m_tool->m_textEditor.data()->registerTrackedChange(selection, KoGenChange::InsertChange, i18n("Key Press"), format, format, false);
181
183
//Paste the selected text
182
184
TextPasteCommand *pasteCommand = new TextPasteCommand(QClipboard::Clipboard, m_tool, this);
183
185
pasteCommand->redo();
198
200
void ChangeTrackedDeleteCommand::deleteSelection(QTextCursor &selection)
200
QTextDocument *document = m_tool->m_textEditor->document();
202
QTextDocument *document = m_tool->m_textEditor.data()->document();
201
203
KoTextDocumentLayout *layout = qobject_cast<KoTextDocumentLayout*>(document->documentLayout());
202
204
Q_ASSERT(layout);
203
205
Q_ASSERT(layout->inlineTextObjectManager());
241
243
checker.setPosition(selectionBegin);
243
245
if (!KoTextDocument(document).changeTracker()->displayChanges()) {
244
246
QChar charAtPos = document->characterAt(checker.position() - 1);
245
247
if (layout->inlineTextObjectManager()->inlineTextObject(checker) && charAtPos == QChar::ObjectReplacementCharacter) {
256
258
if (KoTextDocument(document).changeTracker()->containsInlineChanges(checker.charFormat())) {
257
259
int changeId = checker.charFormat().property(KoCharacterStyle::ChangeTrackerId).toInt();
258
if (KoTextDocument(document).changeTracker()->elementById(changeId)->getChangeType() == KoGenChange::deleteChange) {
260
if (KoTextDocument(document).changeTracker()->elementById(changeId)->getChangeType() == KoGenChange::DeleteChange) {
259
261
QTextDocumentFragment prefix = KoTextDocument(document).changeTracker()->elementById(changeId)->getDeleteData();
260
262
selectionBegin -= (fragmentLength(prefix) + 1 );
261
263
KoTextDocument(document).changeTracker()->elementById(changeId)->setValid(false);
360
362
currentList->add(cursor.block(), deletedListItemLevel);
364
} else if (tempCursor.currentTable()) {
365
QTextTable *deletedTable = tempCursor.currentTable();
366
int numRows = deletedTable->rows();
367
int numColumns = deletedTable->columns();
368
QTextTable *insertedTable = cursor.insertTable(numRows, numColumns, deletedTable->format());
369
for (int i=0; i<numRows; i++) {
370
for (int j=0; j<numColumns; j++) {
371
tempCursor.setPosition(deletedTable->cellAt(i,j).firstCursorPosition().position());
372
tempCursor.setPosition(deletedTable->cellAt(i,j).lastCursorPosition().position(), QTextCursor::KeepAnchor);
373
insertedTable->cellAt(i,j).setFormat(deletedTable->cellAt(i,j).format().toTableCellFormat());
374
cursor.setPosition(insertedTable->cellAt(i,j).firstCursorPosition().position());
375
cursor.insertFragment(tempCursor.selection());
378
tempCursor.setPosition(deletedTable->cellAt(numRows-1,numColumns-1).lastCursorPosition().position());
379
currentBlock = tempCursor.block();
380
//Move the cursor outside of table
381
cursor.setPosition(cursor.position() + 1);
363
// This block does not contain a list. So no special work here.
384
// This block does not contain a list. So no special work here.
364
385
if (currentBlock != tempDoc.begin())
365
386
cursor.insertBlock(currentBlock.blockFormat(), currentBlock.charFormat());
404
425
deletedListItem = currentBlock.blockFormat().property(KoDeleteChangeMarker::DeletedListItem).toBool();
405
426
if (currentBlock != tempDoc.begin() && deletedListItem)
406
427
length += 1; //For the Block separator
428
} else if (tempCursor.currentTable()) {
429
QTextTable *deletedTable = tempCursor.currentTable();
430
int numRows = deletedTable->rows();
431
int numColumns = deletedTable->columns();
432
for (int i=0; i<numRows; i++) {
433
for (int j=0; j<numColumns; j++) {
435
length += (deletedTable->cellAt(i,j).lastCursorPosition().position() - deletedTable->cellAt(i,j).firstCursorPosition().position());
438
tempCursor.setPosition(deletedTable->cellAt(numRows-1,numColumns-1).lastCursorPosition().position());
439
currentBlock = tempCursor.block();
408
443
if (currentBlock != tempDoc.begin())
409
444
length += 1; //For the Block Separator
440
if (m_document.isNull())
442
m_document->undo(KoTextDocument(m_document).textEditor()->cursor());
475
QTextDocument *doc = m_document.data();
477
doc->undo(KoTextDocument(doc).textEditor()->cursor());
446
if (m_document.isNull())
448
m_document->redo(KoTextDocument(m_document).textEditor()->cursor());
481
QTextDocument *doc = m_document.data();
483
doc->redo(KoTextDocument(doc).textEditor()->cursor());
451
QPointer<QTextDocument> m_document;
486
QWeakPointer<QTextDocument> m_document;
454
489
if (command->id() != id())
473
508
m_length = other->m_length;
475
510
for(int i=0; i < command->childCount(); i++)
476
new UndoTextCommand(m_tool->m_textEditor->document(), this);
511
new UndoTextCommand(m_tool->m_textEditor.data()->document(), this);
483
518
void ChangeTrackedDeleteCommand::updateListIds(QTextCursor &cursor)
485
520
m_newListIds.clear();
486
QTextDocument *document = m_tool->m_textEditor->document();
521
QTextDocument *document = m_tool->m_textEditor.data()->document();
487
522
QTextCursor tempCursor(document);
488
523
QTextBlock startBlock = document->findBlock(cursor.anchor());
489
524
QTextBlock endBlock = document->findBlock(cursor.position());
501
536
void ChangeTrackedDeleteCommand::updateListChanges()
503
QTextDocument *document = m_tool->m_textEditor->document();
538
QTextDocument *document = m_tool->m_textEditor.data()->document();
504
539
QTextCursor tempCursor(document);
505
540
QTextBlock startBlock = document->findBlock(m_position);
506
541
QTextBlock endBlock = document->findBlock(m_position + m_length);
536
571
void ChangeTrackedDeleteCommand::removeChangeElement(int changeId)
538
QTextDocument *document = m_tool->m_textEditor->document();
573
QTextDocument *document = m_tool->m_textEditor.data()->document();
539
574
KoTextDocumentLayout *layout = qobject_cast<KoTextDocumentLayout*>(document->documentLayout());
540
575
KoChangeTrackerElement *element = KoTextDocument(document).changeTracker()->elementById(changeId);
541
576
KoDeleteChangeMarker *marker = element->getDeleteChangeMarker();