| 439 | } |
| 440 | |
| 441 | void GrepOutputModel::doReplacements() |
| 442 | { |
| 443 | Q_ASSERT(m_rootItem); |
| 444 | if (!m_rootItem) |
| 445 | return; // nothing to do, abort |
| 446 | |
| 447 | DocumentChangeSet changeSet; |
| 448 | changeSet.setFormatPolicy(DocumentChangeSet::NoAutoFormat); |
| 449 | for(int fileRow = 0; fileRow < m_rootItem->rowCount(); fileRow++) |
| 450 | { |
| 451 | auto *file = static_cast<GrepOutputItem *>(m_rootItem->child(fileRow)); |
| 452 | |
| 453 | for(int matchRow = 0; matchRow < file->rowCount(); matchRow++) |
| 454 | { |
| 455 | auto *match = static_cast<GrepOutputItem *>(file->child(matchRow)); |
| 456 | if(match->checkState() == Qt::Checked) |
| 457 | { |
| 458 | DocumentChangePointer change = match->change(); |
| 459 | // setting replacement text based on current replace value |
| 460 | change->m_newText = replacementFor(change->m_oldText); |
| 461 | changeSet.addChange(change); |
| 462 | // this item cannot be checked anymore |
| 463 | match->setCheckState(Qt::Unchecked); |
| 464 | match->setEnabled(false); |
| 465 | } |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | DocumentChangeSet::ChangeResult result = changeSet.applyAllChanges(); |
| 470 | if(!result.m_success) |
| 471 | { |
| 472 | DocumentChangePointer ch = result.m_reasonChange; |
| 473 | if(ch) |
| 474 | emit showErrorMessage(i18nc("%1 is the old text, %2 is the new text, %3 is the file path, %4 and %5 are its row and column", |
| 475 | "Failed to replace <b>%1</b> by <b>%2</b> in %3:%4:%5", |
| 476 | ch->m_oldText.toHtmlEscaped(), ch->m_newText.toHtmlEscaped(), ch->m_document.toUrl().toLocalFile(), |
| 477 | ch->m_range.start().line() + 1, ch->m_range.start().column() + 1)); |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | void GrepOutputModel::showMessageSlot(IStatus* status, const QString& message) |
| 482 | { |