diff --git a/src/plugins/find/gui/advancedsearchwidget.cpp b/src/plugins/find/gui/advancedsearchwidget.cpp index 41cdfe5a2..e53afe5b9 100644 --- a/src/plugins/find/gui/advancedsearchwidget.cpp +++ b/src/plugins/find/gui/advancedsearchwidget.cpp @@ -88,6 +88,7 @@ class AdvancedSearchWidgetPrivate : public QObject WindowService *winSrv { nullptr }; MainController *controller { nullptr }; QTimer startTimer; + bool isReplaceAll { false }; }; AdvancedSearchWidgetPrivate::AdvancedSearchWidgetPrivate(AdvancedSearchWidget *qq) @@ -179,7 +180,7 @@ DToolButton *AdvancedSearchWidgetPrivate::registerOperator(const QIcon &icon, co btn->setIconSize({ 16, 16 }); btn->setToolTip(description); connect(btn, &DToolButton::clicked, this, handler); - + winSrv->registerWidgetToDockHeader(MWNA_ADVANCEDSEARCH, btn); return btn; } @@ -461,19 +462,35 @@ void AdvancedSearchWidgetPrivate::handleReplaceAll() } // 0: cancel 1:contionue int code = showMessage(msg); - if (1 == code) + if (1 == code) { + isReplaceAll = true; replace(resultMap); + } } void AdvancedSearchWidgetPrivate::handleReplaceFinished() { searchSpinner->setVisible(false); searchSpinner->stop(); + if (isReplaceAll) { + isReplaceAll = false; + const auto &results = resultWidget->allResult(); + const auto &items = results.values(); + const int resultCount = std::accumulate(items.cbegin(), items.cend(), 0, + [](int sum, const FindItemList &list) { + return sum + list.size(); + }); + QString msg = AdvancedSearchWidget::tr("Replaced %1 occurrences across %2 files with \"%3\""); + resultWidget->clear(); + resultWidget->showMessage(msg.arg(QString::number(results.count()), + QString::number(resultCount), + replaceEdit->text())); + } } AdvancedSearchWidget::AdvancedSearchWidget(QWidget *parent) : QWidget(parent), - d(new AdvancedSearchWidgetPrivate(this)) + d(new AdvancedSearchWidgetPrivate(this)) { d->initUI(); d->initConnection(); diff --git a/src/plugins/find/maincontroller/worker/searchreplaceworker.cpp b/src/plugins/find/maincontroller/worker/searchreplaceworker.cpp index 4ced584b3..68a029d8e 100644 --- a/src/plugins/find/maincontroller/worker/searchreplaceworker.cpp +++ b/src/plugins/find/maincontroller/worker/searchreplaceworker.cpp @@ -43,8 +43,8 @@ void SearchReplaceWorkerPrivate::startNextJob() process->setProgram(job.program); process->setArguments(job.arguments); process->start(); - if (!job.channelData.isEmpty()) { - process->write(job.channelData.toUtf8()); + if (job.channelData.has_value()) { + process->write(job.channelData->toUtf8()); process->closeWriteChannel(); } } diff --git a/src/plugins/find/maincontroller/worker/searchreplaceworker_p.h b/src/plugins/find/maincontroller/worker/searchreplaceworker_p.h index 7b89b56a1..3828c0438 100644 --- a/src/plugins/find/maincontroller/worker/searchreplaceworker_p.h +++ b/src/plugins/find/maincontroller/worker/searchreplaceworker_p.h @@ -17,7 +17,7 @@ class SearchReplaceWorkerPrivate : public QObject { QString program; QStringList arguments; - QString channelData; + std::optional channelData; QString keyword; SearchFlags flags; };