From f66df921d74c323d899f996d9ca520c224355a90 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Fri, 11 Jun 2021 14:34:34 +0200 Subject: Core: filepathify file renaming Change-Id: I3d4f39e34e65cde3df7b7c19570e3a54d0625d53 Reviewed-by: Christian Stenger Reviewed-by: David Schulz --- src/plugins/cpptools/cppmodelmanager.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/plugins/cpptools/cppmodelmanager.cpp') diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp index c9324b1f35..aafa51a906 100644 --- a/src/plugins/cpptools/cppmodelmanager.cpp +++ b/src/plugins/cpptools/cppmodelmanager.cpp @@ -1450,30 +1450,29 @@ QSet CppModelManager::internalTargets(const Utils::FilePath &filePath) return targets; } -void CppModelManager::renameIncludes(const QString &oldFileName, const QString &newFileName) +void CppModelManager::renameIncludes(const Utils::FilePath &oldFilePath, + const Utils::FilePath &newFilePath) { - if (oldFileName.isEmpty() || newFileName.isEmpty()) + if (oldFilePath.isEmpty() || newFilePath.isEmpty()) return; - const QFileInfo oldFileInfo(oldFileName); - const QFileInfo newFileInfo(newFileName); - // We just want to handle renamings so return when the file was actually moved. - if (oldFileInfo.absoluteDir() != newFileInfo.absoluteDir()) + if (oldFilePath.absolutePath() != newFilePath.absolutePath()) return; const TextEditor::RefactoringChanges changes; - foreach (Snapshot::IncludeLocation loc, snapshot().includeLocationsOfDocument(oldFileName)) { + foreach (Snapshot::IncludeLocation loc, + snapshot().includeLocationsOfDocument(oldFilePath.toString())) { TextEditor::RefactoringFilePtr file = changes.file( Utils::FilePath::fromString(loc.first->fileName())); const QTextBlock &block = file->document()->findBlockByNumber(loc.second - 1); - const int replaceStart = block.text().indexOf(oldFileInfo.fileName()); + const int replaceStart = block.text().indexOf(oldFilePath.fileName()); if (replaceStart > -1) { Utils::ChangeSet changeSet; changeSet.replace(block.position() + replaceStart, - block.position() + replaceStart + oldFileInfo.fileName().length(), - newFileInfo.fileName()); + block.position() + replaceStart + oldFilePath.fileName().length(), + newFilePath.fileName()); file->setChangeSet(changeSet); file->apply(); } -- cgit v1.2.1