ProjectExplorer: Update header guards also on copying a file

... rather than only on renaming.

Fixes: QTCREATORBUG-26654
Change-Id: I5a723969a078d76cc2e833d5e505ff64a3063bbe
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2021-12-08 16:26:32 +01:00
parent f1a5a1f716
commit f98a15d544
3 changed files with 35 additions and 14 deletions

View File

@@ -228,18 +228,25 @@ bool FileUtils::renameFile(const FilePath &orgFilePath, const FilePath &newFileP
DocumentManager::renamedFile(orgFilePath, newFilePath);
}
if (result && handleGuards == HandleIncludeGuards::Yes) {
bool headerUpdateSuccess = updateHeaderFileGuardAfterRename(newFilePath.toString(),
orgFilePath.baseName());
if (!headerUpdateSuccess) {
Core::MessageManager::writeDisrupting(
if (result)
updateHeaderFileGuardIfApplicable(orgFilePath, newFilePath, handleGuards);
return result;
}
void FileUtils::updateHeaderFileGuardIfApplicable(const Utils::FilePath &oldFilePath,
const Utils::FilePath &newFilePath,
HandleIncludeGuards handleGuards)
{
if (handleGuards == HandleIncludeGuards::No)
return;
const bool headerUpdateSuccess = updateHeaderFileGuardAfterRename(newFilePath.toString(),
oldFilePath.baseName());
if (headerUpdateSuccess)
return;
MessageManager::writeDisrupting(
QCoreApplication::translate("Core::FileUtils",
"Failed to rename the include guard in file \"%1\".")
.arg(newFilePath.toUserOutput()));
}
}
return result;
.arg(newFilePath.toUserOutput()));
}
bool FileUtils::updateHeaderFileGuardAfterRename(const QString &headerPath,