Skip to content

Commit 87014a0

Browse files
committed
added statistics in handleReplaceInFiles()
1 parent 87a6944 commit 87014a0

File tree

1 file changed

+38
-29
lines changed

1 file changed

+38
-29
lines changed

src/MultiReplacePanel.cpp

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5372,6 +5372,13 @@ void MultiReplace::handleReplaceInFiles() {
53725372

53735373
resetCountColumns();
53745374

5375+
std::vector<int> listFindTotals;
5376+
std::vector<int> listReplaceTotals;
5377+
if (useListEnabled) {
5378+
listFindTotals.assign(replaceListData.size(), 0);
5379+
listReplaceTotals.assign(replaceListData.size(), 0);
5380+
}
5381+
53755382
int total = static_cast<int>(files.size()), idx = 0, changed = 0;
53765383
showStatusMessage(L"Progress: [ 0%]", MessageStatus::Info);
53775384

@@ -5425,43 +5432,45 @@ void MultiReplace::handleReplaceInFiles() {
54255432
send(SCI_ADDTEXT, utf8_input_buf.length(), reinterpret_cast<sptr_t>(utf8_input_buf.data()));
54265433

54275434
handleDelimiterPositions(DelimiterOperation::LoadAll);
5428-
bool fileProcessedSuccessfully = handleReplaceAllButton(false, &fp);
5429-
5430-
if (fileProcessedSuccessfully) {
5431-
// write the modified text back to the file.
5432-
std::string utf8_out = guard.getText();
5433-
5434-
// Restore original Scintilla context before writing
5435-
_hScintilla = oldSci;
5436-
pSciMsg = oldFn;
5437-
pSciWndData = oldData;
5438-
5439-
if (utf8_out != utf8_input_buf) {
5440-
std::string final_write_buf;
5441-
if (convertUtf8ToOriginal(utf8_out, enc_info, original_buf, final_write_buf)) {
5442-
if (guard.writeFile(fp, final_write_buf)) {
5443-
++changed; // Only increment if the file was successfully written.
5444-
}
5445-
}
5435+
5436+
if (!handleReplaceAllButton(false, &fp)) { _isCancelRequested = true; break; }
5437+
5438+
if (useListEnabled) {
5439+
for (size_t i = 0; i < replaceListData.size(); ++i) {
5440+
int f = replaceListData[i].findCount.empty()
5441+
? 0 : std::stoi(replaceListData[i].findCount);
5442+
int r = replaceListData[i].replaceCount.empty()
5443+
? 0 : std::stoi(replaceListData[i].replaceCount);
5444+
listFindTotals[i] += f;
5445+
listReplaceTotals[i] += r;
54465446
}
54475447
}
5448-
else {
5449-
// The user clicked "Stop" (e.g., from the Debug Window).
5450-
// The changes for THIS file will be discarded as it's never written to disk.
5451-
_isCancelRequested = true;
5452-
break;
5453-
}
54545448

5449+
std::string utf8_out = guard.getText();
5450+
_hScintilla = oldSci; pSciMsg = oldFn; pSciWndData = oldData;
5451+
5452+
if (utf8_out != utf8_input_buf) {
5453+
std::string final_write_buf;
5454+
if (convertUtf8ToOriginal(utf8_out, enc_info, original_buf, final_write_buf))
5455+
if (guard.writeFile(fp, final_write_buf)) ++changed;
5456+
}
54555457
}
54565458

5457-
// The UiStateGuard destructor automatically restores the UI here.
5459+
if (useListEnabled) {
5460+
for (size_t i = 0; i < replaceListData.size(); ++i) {
5461+
replaceListData[i].findCount = std::to_wstring(listFindTotals[i]);
5462+
replaceListData[i].replaceCount = std::to_wstring(listReplaceTotals[i]);
5463+
updateCountColumns(i, listFindTotals[i], listReplaceTotals[i]);
5464+
}
5465+
refreshUIListView();
5466+
}
54585467

5459-
// Display a simple, universal summary message unless the plugin is shutting down.
54605468
if (!_isShuttingDown) {
5461-
std::wstring summaryMsg = LM.get(L"status_replace_summary", { std::to_wstring(changed), std::to_wstring(total) });
5462-
showStatusMessage(summaryMsg, _isCancelRequested ? MessageStatus::Info : MessageStatus::Success);
5469+
std::wstring summaryMsg = LM.get(L"status_replace_summary",
5470+
{ std::to_wstring(changed), std::to_wstring(files.size()) });
5471+
showStatusMessage(summaryMsg, _isCancelRequested ? MessageStatus::Info
5472+
: MessageStatus::Success);
54635473
}
5464-
54655474
_isCancelRequested = false;
54665475
}
54675476

0 commit comments

Comments
 (0)