MCPcopy Create free account
hub / github.com/KDE/kdevelop / doReplacements

Method doReplacements

plugins/grepview/grepoutputmodel.cpp:441–479  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

439}
440
441void 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
481void GrepOutputModel::showMessageSlot(IStatus* status, const QString& message)
482{

Callers 2

onApplyMethod · 0.80
testReplaceMethod · 0.80

Calls 14

setFormatPolicyMethod · 0.80
checkStateMethod · 0.80
changeMethod · 0.80
addChangeMethod · 0.80
applyAllChangesMethod · 0.80
toHtmlEscapedMethod · 0.80
toLocalFileMethod · 0.80
rowCountMethod · 0.45
childMethod · 0.45
setEnabledMethod · 0.45
toUrlMethod · 0.45
lineMethod · 0.45

Tested by 1

testReplaceMethod · 0.64