diff --git a/src/plugins/coreplugin/documentmanager.cpp b/src/plugins/coreplugin/documentmanager.cpp index d194eb1169f..d6acd84a67b 100644 --- a/src/plugins/coreplugin/documentmanager.cpp +++ b/src/plugins/coreplugin/documentmanager.cpp @@ -476,15 +476,15 @@ static void dump() permission information to avoid annoying the user with \e {the file has been removed} popups. */ -void DocumentManager::renamedFile(const QString &from, const QString &to) +void DocumentManager::renamedFile(const Utils::FilePath &from, const Utils::FilePath &to) { - const QString &fromKey = filePathKey(from, KeepLinks); + const Utils::FilePath &fromKey = filePathKey(from, KeepLinks); // gather the list of IDocuments QList documentsToRename; for (auto it = d->m_documentsWithWatch.cbegin(), end = d->m_documentsWithWatch.cend(); it != end; ++it) { - if (it.value().contains(fromKey)) + if (it.value().contains(fromKey.toString())) documentsToRename.append(it.key()); } @@ -492,7 +492,7 @@ void DocumentManager::renamedFile(const QString &from, const QString &to) foreach (IDocument *document, documentsToRename) { d->m_blockedIDocument = document; removeFileInfo(document); - document->setFilePath(FilePath::fromString(to)); + document->setFilePath(to); addFileInfos({document}); d->m_blockedIDocument = nullptr; } @@ -505,7 +505,7 @@ void DocumentManager::filePathChanged(const FilePath &oldName, const FilePath &n QTC_ASSERT(doc, return); if (doc == d->m_blockedIDocument) return; - emit m_instance->documentRenamed(doc, oldName.toString(), newName.toString()); + emit m_instance->documentRenamed(doc, oldName, newName); } void DocumentManager::updateSaveAll() diff --git a/src/plugins/coreplugin/documentmanager.h b/src/plugins/coreplugin/documentmanager.h index 3adcc2ea426..7aa85d8c91d 100644 --- a/src/plugins/coreplugin/documentmanager.h +++ b/src/plugins/coreplugin/documentmanager.h @@ -63,7 +63,7 @@ public: static bool removeDocument(IDocument *document); static QList modifiedDocuments(); - static void renamedFile(const QString &from, const QString &to); + static void renamedFile(const Utils::FilePath &from, const Utils::FilePath &to); static void expectFileChange(const Utils::FilePath &filePath); static void unexpectFileChange(const Utils::FilePath &filePath); @@ -148,9 +148,11 @@ signals: lead to any editors to reload or any other editor manager actions. */ void filesChangedInternally(const QStringList &files); /// emitted if all documents changed their name e.g. due to the file changing on disk - void allDocumentsRenamed(const QString &from, const QString &to); + void allDocumentsRenamed(const Utils::FilePath &from, const Utils::FilePath &to); /// emitted if one document changed its name e.g. due to save as - void documentRenamed(Core::IDocument *document, const QString &from, const QString &to); + void documentRenamed(Core::IDocument *document, + const Utils::FilePath &from, + const Utils::FilePath &to); void projectsDirectoryChanged(const Utils::FilePath &directory); private: diff --git a/src/plugins/coreplugin/fileutils.cpp b/src/plugins/coreplugin/fileutils.cpp index 0f9cc1d3c8b..4f81b9f5df4 100644 --- a/src/plugins/coreplugin/fileutils.cpp +++ b/src/plugins/coreplugin/fileutils.cpp @@ -194,41 +194,33 @@ void FileUtils::removeFiles(const FilePaths &filePaths, bool deleteFromFS) } } -static inline bool fileSystemRenameFile(const QString &orgFilePath, - const QString &newFilePath) -{ - // QTBUG-3570 is also valid for Qt 5 but QAbstractFileEngine is now in a private header file and - // the symbol is not exported. - return QFile::rename(orgFilePath, newFilePath); -} - -bool FileUtils::renameFile(const QString &orgFilePath, const QString &newFilePath, +bool FileUtils::renameFile(const FilePath &orgFilePath, const FilePath &newFilePath, HandleIncludeGuards handleGuards) { if (orgFilePath == newFilePath) return false; - QString dir = QFileInfo(orgFilePath).absolutePath(); - IVersionControl *vc = VcsManager::findVersionControlForDirectory(dir); + FilePath dir = orgFilePath.absolutePath(); + IVersionControl *vc = VcsManager::findVersionControlForDirectory(dir.toString()); bool result = false; if (vc && vc->supportsOperation(IVersionControl::MoveOperation)) - result = vc->vcsMove(orgFilePath, newFilePath); + result = vc->vcsMove(orgFilePath.toString(), newFilePath.toString()); if (!result) // The moving via vcs failed or the vcs does not support moving, fall back - result = fileSystemRenameFile(orgFilePath, newFilePath); + result = Utils::FileUtils::renameFile(orgFilePath, newFilePath); if (result) { // yeah we moved, tell the filemanager about it DocumentManager::renamedFile(orgFilePath, newFilePath); } if (result && handleGuards == HandleIncludeGuards::Yes) { - QFileInfo fi(orgFilePath); - bool headerUpdateSuccess = updateHeaderFileGuardAfterRename(newFilePath, fi.baseName()); + bool headerUpdateSuccess = updateHeaderFileGuardAfterRename(newFilePath.toString(), + orgFilePath.baseName()); if (!headerUpdateSuccess) { Core::MessageManager::writeDisrupting( QCoreApplication::translate("Core::FileUtils", "Failed to rename the include guard in file \"%1\".") - .arg(newFilePath)); + .arg(newFilePath.toUserOutput())); } } diff --git a/src/plugins/coreplugin/fileutils.h b/src/plugins/coreplugin/fileutils.h index 5d1ff071778..dd140f5d8d7 100644 --- a/src/plugins/coreplugin/fileutils.h +++ b/src/plugins/coreplugin/fileutils.h @@ -53,7 +53,7 @@ struct CORE_EXPORT FileUtils // File operations aware of version control and file system case-insensitiveness static void removeFile(const QString &filePath, bool deleteFromFS); static void removeFiles(const Utils::FilePaths &filePaths, bool deleteFromFS); - static bool renameFile(const QString &from, const QString &to, + static bool renameFile(const Utils::FilePath &from, const Utils::FilePath &to, HandleIncludeGuards handleGuards = HandleIncludeGuards::No); // This method is used to refactor the include guards in the renamed headers static bool updateHeaderFileGuardAfterRename(const QString &headerPath, const QString &oldHeaderBaseName); diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp index c9324b1f35d..aafa51a906a 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(); } diff --git a/src/plugins/cpptools/cppmodelmanager.h b/src/plugins/cpptools/cppmodelmanager.h index ff987caf93f..2677a4327d4 100644 --- a/src/plugins/cpptools/cppmodelmanager.h +++ b/src/plugins/cpptools/cppmodelmanager.h @@ -241,7 +241,7 @@ public: QSet internalTargets(const Utils::FilePath &filePath) const; - void renameIncludes(const QString &oldFileName, const QString &newFileName); + void renameIncludes(const Utils::FilePath &oldFilePath, const Utils::FilePath &newFilePath); // for VcsBaseSubmitEditor Q_INVOKABLE QSet symbolsInFiles(const QSet &files) const; diff --git a/src/plugins/cpptools/cppmodelmanager_test.cpp b/src/plugins/cpptools/cppmodelmanager_test.cpp index c4a36379868..8e2700c2a23 100644 --- a/src/plugins/cpptools/cppmodelmanager_test.cpp +++ b/src/plugins/cpptools/cppmodelmanager_test.cpp @@ -1035,7 +1035,9 @@ void CppToolsPlugin::test_modelmanager_renameIncludes() QCOMPARE(snapshot.allIncludesForDocument(sourceFile), QSet() << oldHeader); // Renaming the header - QVERIFY(Core::FileUtils::renameFile(oldHeader, newHeader, Core::HandleIncludeGuards::Yes)); + QVERIFY(Core::FileUtils::renameFile(Utils::FilePath::fromString(oldHeader), + Utils::FilePath::fromString(newHeader), + Core::HandleIncludeGuards::Yes)); // Update the c++ model manager again and check for the new includes modelManager->updateSourceFiles(sourceFiles).waitForFinished(); @@ -1103,12 +1105,14 @@ void CppToolsPlugin::test_modelmanager_renameIncludesInEditor() QVERIFY(modelManager->workingCopy().contains(mainFile)); // Test the renaming of a header file where a pragma once guard is present - QVERIFY(Core::FileUtils::renameFile(headerWithPragmaOnce, renamedHeaderWithPragmaOnce, + QVERIFY(Core::FileUtils::renameFile(Utils::FilePath::fromString(headerWithPragmaOnce), + Utils::FilePath::fromString(renamedHeaderWithPragmaOnce), Core::HandleIncludeGuards::Yes)); // Test the renaming the header with include guard: // The contents should match the foobar2000.h in the testdata_project2 project - QVERIFY(Core::FileUtils::renameFile(headerWithNormalGuard, renamedHeaderWithNormalGuard, + QVERIFY(Core::FileUtils::renameFile(Utils::FilePath::fromString(headerWithNormalGuard), + Utils::FilePath::fromString(renamedHeaderWithNormalGuard), Core::HandleIncludeGuards::Yes)); const MyTestDataDir testDir2(_("testdata_project2")); @@ -1125,8 +1129,10 @@ void CppToolsPlugin::test_modelmanager_renameIncludesInEditor() // Test the renaming the header with underscore pre/suffixed include guard: // The contents should match the foobar2000.h in the testdata_project2 project - QVERIFY(Core::FileUtils::renameFile(headerWithUnderscoredGuard, renamedHeaderWithUnderscoredGuard, - Core::HandleIncludeGuards::Yes)); + QVERIFY( + Core::FileUtils::renameFile(Utils::FilePath::fromString(headerWithUnderscoredGuard), + Utils::FilePath::fromString(renamedHeaderWithUnderscoredGuard), + Core::HandleIncludeGuards::Yes)); QFile foobar4000Header(testDir2.file("foobar4000.h")); QVERIFY(foobar4000Header.open(QFile::ReadOnly | QFile::Text)); @@ -1146,7 +1152,8 @@ void CppToolsPlugin::test_modelmanager_renameIncludesInEditor() auto originalMalformedGuardContents = renamedHeader.readAll(); renamedHeader.close(); - QVERIFY(Core::FileUtils::renameFile(headerWithMalformedGuard, renamedHeaderWithMalformedGuard, + QVERIFY(Core::FileUtils::renameFile(Utils::FilePath::fromString(headerWithMalformedGuard), + Utils::FilePath::fromString(renamedHeaderWithMalformedGuard), Core::HandleIncludeGuards::Yes)); renamedHeader.setFileName(renamedHeaderWithMalformedGuard); diff --git a/src/plugins/fakevim/fakevimplugin.cpp b/src/plugins/fakevim/fakevimplugin.cpp index 09148aa5793..49ded4a2048 100644 --- a/src/plugins/fakevim/fakevimplugin.cpp +++ b/src/plugins/fakevim/fakevimplugin.cpp @@ -531,9 +531,9 @@ public: void editorAboutToClose(Core::IEditor *); void currentEditorAboutToChange(Core::IEditor *); - void allDocumentsRenamed(const QString &oldName, const QString &newName); - void documentRenamed(Core::IDocument *document, const QString &oldName, const QString &newName); - void renameFileNameInEditors(const QString &oldName, const QString &newName); + void allDocumentsRenamed(const FilePath &oldPath, const FilePath &newPath); + void documentRenamed(Core::IDocument *document, const FilePath &oldPath, const FilePath &newPath); + void renameFileNameInEditors(const FilePath &oldPath, const FilePath &newPath); void setUseFakeVim(bool on); void setUseFakeVimInternal(bool on); @@ -1881,23 +1881,23 @@ void FakeVimPluginPrivate::currentEditorAboutToChange(IEditor *editor) handler->enterCommandMode(); } -void FakeVimPluginPrivate::allDocumentsRenamed(const QString &oldName, const QString &newName) +void FakeVimPluginPrivate::allDocumentsRenamed(const FilePath &oldPath, const FilePath &newPath) { - renameFileNameInEditors(oldName, newName); - FakeVimHandler::updateGlobalMarksFilenames(oldName, newName); + renameFileNameInEditors(oldPath, newPath); + FakeVimHandler::updateGlobalMarksFilenames(oldPath.toString(), newPath.toString()); } void FakeVimPluginPrivate::documentRenamed( - IDocument *, const QString &oldName, const QString &newName) + IDocument *, const FilePath &oldPath, const FilePath &newPath) { - renameFileNameInEditors(oldName, newName); + renameFileNameInEditors(oldPath, newPath); } -void FakeVimPluginPrivate::renameFileNameInEditors(const QString &oldName, const QString &newName) +void FakeVimPluginPrivate::renameFileNameInEditors(const FilePath &oldPath, const FilePath &newPath) { foreach (FakeVimHandler *handler, m_editorToHandler.values()) { - if (handler->currentFileName() == oldName) - handler->setCurrentFileName(newName); + if (handler->currentFileName() == oldPath.toString()) + handler->setCurrentFileName(newPath.toString()); } } diff --git a/src/plugins/genericprojectmanager/genericproject.cpp b/src/plugins/genericprojectmanager/genericproject.cpp index c57d5cf05df..6539617dfa7 100644 --- a/src/plugins/genericprojectmanager/genericproject.cpp +++ b/src/plugins/genericprojectmanager/genericproject.cpp @@ -136,7 +136,9 @@ public: } RemovedFilesFromProject removeFiles(Node *, const QStringList &filePaths, QStringList *) final; - bool renameFile(Node *, const QString &filePath, const QString &newFilePath) final; + bool renameFile(Node *, + const Utils::FilePath &oldFilePath, + const Utils::FilePath &newFilePath) final; bool addFiles(Node *, const QStringList &filePaths, QStringList *) final; FilePath filesFilePath() const { return ::FilePath::fromString(m_filesFileName); } @@ -391,17 +393,17 @@ bool GenericBuildSystem::setFiles(const QStringList &filePaths) return saveRawFileList(newList); } -bool GenericBuildSystem::renameFile(Node *, const QString &filePath, const QString &newFilePath) +bool GenericBuildSystem::renameFile(Node *, const FilePath &oldFilePath, const FilePath &newFilePath) { QStringList newList = m_rawFileList; - QHash::iterator i = m_rawListEntries.find(filePath); + QHash::iterator i = m_rawListEntries.find(oldFilePath.toString()); if (i != m_rawListEntries.end()) { int index = newList.indexOf(i.value()); if (index != -1) { QDir baseDir(projectDirectory().toString()); newList.removeAt(index); - insertSorted(&newList, baseDir.relativeFilePath(newFilePath)); + insertSorted(&newList, baseDir.relativeFilePath(newFilePath.toString())); } } diff --git a/src/plugins/nim/project/nimblebuildsystem.cpp b/src/plugins/nim/project/nimblebuildsystem.cpp index b08793087c7..54e9c9cd23c 100644 --- a/src/plugins/nim/project/nimblebuildsystem.cpp +++ b/src/plugins/nim/project/nimblebuildsystem.cpp @@ -262,9 +262,9 @@ bool NimbleBuildSystem::deleteFiles(Node *, const QStringList &) return true; } -bool NimbleBuildSystem::renameFile(Node *, const QString &filePath, const QString &newFilePath) +bool NimbleBuildSystem::renameFile(Node *, const FilePath &oldFilePath, const FilePath &newFilePath) { - return m_projectScanner.renameFile(filePath, newFilePath); + return m_projectScanner.renameFile(oldFilePath.toString(), newFilePath.toString()); } } // Nim diff --git a/src/plugins/nim/project/nimblebuildsystem.h b/src/plugins/nim/project/nimblebuildsystem.h index 7a81687ec70..07e3c823ed9 100644 --- a/src/plugins/nim/project/nimblebuildsystem.h +++ b/src/plugins/nim/project/nimblebuildsystem.h @@ -81,7 +81,7 @@ private: QStringList *) override; bool deleteFiles(ProjectExplorer::Node *, const QStringList &) override; bool renameFile(ProjectExplorer::Node *, - const QString &filePath, const QString &newFilePath) override; + const Utils::FilePath &oldFilePath, const Utils::FilePath &newFilePath) override; void triggerParsing() final; diff --git a/src/plugins/nim/project/nimbuildsystem.cpp b/src/plugins/nim/project/nimbuildsystem.cpp index ba128c7932f..a9af84cf9e7 100644 --- a/src/plugins/nim/project/nimbuildsystem.cpp +++ b/src/plugins/nim/project/nimbuildsystem.cpp @@ -238,9 +238,9 @@ bool NimBuildSystem::deleteFiles(Node *, const QStringList &) return true; } -bool NimBuildSystem::renameFile(Node *, const QString &filePath, const QString &newFilePath) +bool NimBuildSystem::renameFile(Node *, const FilePath &oldFilePath, const FilePath &newFilePath) { - return m_projectScanner.renameFile(filePath, newFilePath); + return m_projectScanner.renameFile(oldFilePath.toString(), newFilePath.toString()); } } // namespace Nim diff --git a/src/plugins/nim/project/nimbuildsystem.h b/src/plugins/nim/project/nimbuildsystem.h index a743fa0fd70..634f475ba31 100644 --- a/src/plugins/nim/project/nimbuildsystem.h +++ b/src/plugins/nim/project/nimbuildsystem.h @@ -86,7 +86,7 @@ public: QStringList *) override; bool deleteFiles(ProjectExplorer::Node *, const QStringList &) final; bool renameFile(ProjectExplorer::Node *, - const QString &filePath, const QString &newFilePath) final; + const Utils::FilePath &oldFilePath, const Utils::FilePath &newFilePath) final; void triggerParsing() override; diff --git a/src/plugins/projectexplorer/buildsystem.cpp b/src/plugins/projectexplorer/buildsystem.cpp index a5a027b21f0..cafe6d69540 100644 --- a/src/plugins/projectexplorer/buildsystem.cpp +++ b/src/plugins/projectexplorer/buildsystem.cpp @@ -221,16 +221,16 @@ bool BuildSystem::deleteFiles(Node *, const QStringList &filePaths) return false; } -bool BuildSystem::canRenameFile(Node *, const QString &filePath, const QString &newFilePath) +bool BuildSystem::canRenameFile(Node *, const FilePath &oldFilePath, const FilePath &newFilePath) { - Q_UNUSED(filePath) + Q_UNUSED(oldFilePath) Q_UNUSED(newFilePath) return true; } -bool BuildSystem::renameFile(Node *, const QString &filePath, const QString &newFilePath) +bool BuildSystem::renameFile(Node *, const FilePath &oldFilePath, const FilePath &newFilePath) { - Q_UNUSED(filePath) + Q_UNUSED(oldFilePath) Q_UNUSED(newFilePath) return false; } diff --git a/src/plugins/projectexplorer/buildsystem.h b/src/plugins/projectexplorer/buildsystem.h index a545d969b4b..d24c3b7eaca 100644 --- a/src/plugins/projectexplorer/buildsystem.h +++ b/src/plugins/projectexplorer/buildsystem.h @@ -90,8 +90,12 @@ public: virtual RemovedFilesFromProject removeFiles(Node *context, const QStringList &filePaths, QStringList *notRemoved = nullptr); virtual bool deleteFiles(Node *context, const QStringList &filePaths); - virtual bool canRenameFile(Node *context, const QString &filePath, const QString &newFilePath); - virtual bool renameFile(Node *context, const QString &filePath, const QString &newFilePath); + virtual bool canRenameFile(Node *context, + const Utils::FilePath &oldFilePath, + const Utils::FilePath &newFilePath); + virtual bool renameFile(Node *context, + const Utils::FilePath &oldFilePath, + const Utils::FilePath &newFilePath); virtual bool addDependencies(Node *context, const QStringList &dependencies); virtual bool supportsAction(Node *context, ProjectAction action, const Node *node) const; diff --git a/src/plugins/projectexplorer/foldernavigationwidget.cpp b/src/plugins/projectexplorer/foldernavigationwidget.cpp index dafb1b8255d..ba74074bb9a 100644 --- a/src/plugins/projectexplorer/foldernavigationwidget.cpp +++ b/src/plugins/projectexplorer/foldernavigationwidget.cpp @@ -204,7 +204,7 @@ static QVector renamableFolderNodes(const Utils::FilePath &before, if (node->asFileNode() && node->filePath() == before && node->parentFolderNode() - && node->parentFolderNode()->canRenameFile(before.toString(), after.toString())) { + && node->parentFolderNode()->canRenameFile(before, after)) { folderNodes.append(node->parentFolderNode()); } }); @@ -225,9 +225,9 @@ bool FolderNavigationModel::setData(const QModelIndex &index, const QVariant &va && role == Qt::EditRole && value.canConvert(), return false); const QString afterFileName = value.toString(); - const QString beforeFilePath = filePath(index); - const QString parentPath = filePath(parent(index)); - const QString afterFilePath = parentPath + '/' + afterFileName; + const Utils::FilePath beforeFilePath = Utils::FilePath::fromString(filePath(index)); + const Utils::FilePath parentPath = Utils::FilePath::fromString(filePath(parent(index))); + const Utils::FilePath afterFilePath = parentPath.pathAppended(afterFileName); if (beforeFilePath == afterFilePath) return false; // need to rename through file system model, which takes care of not changing our selection @@ -235,9 +235,8 @@ bool FolderNavigationModel::setData(const QModelIndex &index, const QVariant &va // for files we can do more than just rename on disk, for directories the user is on his/her own if (success && fileInfo(index).isFile()) { Core::DocumentManager::renamedFile(beforeFilePath, afterFilePath); - const QVector folderNodes - = renamableFolderNodes(Utils::FilePath::fromString(beforeFilePath), - Utils::FilePath::fromString(afterFilePath)); + const QVector folderNodes = renamableFolderNodes(beforeFilePath, + afterFilePath); QVector failedNodes; for (FolderNode *folder : folderNodes) { if (!folder->renameFile(beforeFilePath, afterFilePath)) @@ -248,7 +247,7 @@ bool FolderNavigationModel::setData(const QModelIndex &index, const QVariant &va const QString errorMessage = FolderNavigationWidget::tr("The file \"%1\" was renamed to \"%2\", " "but the following projects could not be automatically changed: %3") - .arg(beforeFilePath, afterFilePath, projects); + .arg(beforeFilePath.toUserOutput(), afterFilePath.toUserOutput(), projects); QTimer::singleShot(0, Core::ICore::instance(), [errorMessage] { QMessageBox::warning(Core::ICore::dialogParent(), ProjectExplorerPlugin::tr("Project Editing Failed"), diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 1e009dbf570..0033c72bd9c 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -3853,13 +3853,15 @@ void ProjectExplorerPluginPrivate::handleRenameFile() } } -void ProjectExplorerPlugin::renameFile(Node *node, const QString &newFilePath) +void ProjectExplorerPlugin::renameFile(Node *node, const QString &newFileName) { - const QString oldFilePath = node->filePath().toFileInfo().absoluteFilePath(); + const FilePath oldFilePath = node->filePath().absoluteFilePath(); FolderNode *folderNode = node->parentFolderNode(); QTC_ASSERT(folderNode, return); const QString projectFileName = folderNode->managingProject()->filePath().fileName(); + const FilePath newFilePath = FilePath::fromString(newFileName); + if (oldFilePath == newFilePath) return; @@ -3873,8 +3875,8 @@ void ProjectExplorerPlugin::renameFile(Node *node, const QString &newFilePath) tr("The project file %1 cannot be automatically changed.\n\n" "Rename %2 to %3 anyway?") .arg(projectFileName) - .arg(QDir::toNativeSeparators(oldFilePath)) - .arg(QDir::toNativeSeparators(newFilePath))); + .arg(oldFilePath.toUserOutput()) + .arg(newFilePath.toUserOutput())); if (res == QMessageBox::Yes) { QTC_CHECK(Core::FileUtils::renameFile(oldFilePath, newFilePath, handleGuards)); } @@ -3885,11 +3887,11 @@ void ProjectExplorerPlugin::renameFile(Node *node, const QString &newFilePath) if (Core::FileUtils::renameFile(oldFilePath, newFilePath, handleGuards)) { // Tell the project plugin about rename if (!folderNode->renameFile(oldFilePath, newFilePath)) { - const QString renameFileError - = tr("The file %1 was renamed to %2, but the project file %3 could not be automatically changed.") - .arg(QDir::toNativeSeparators(oldFilePath)) - .arg(QDir::toNativeSeparators(newFilePath)) - .arg(projectFileName); + const QString renameFileError = tr("The file %1 was renamed to %2, but the project " + "file %3 could not be automatically changed.") + .arg(oldFilePath.toUserOutput()) + .arg(newFilePath.toUserOutput()) + .arg(projectFileName); QTimer::singleShot(0, [renameFileError]() { QMessageBox::warning(ICore::dialogParent(), @@ -3899,8 +3901,8 @@ void ProjectExplorerPlugin::renameFile(Node *node, const QString &newFilePath) } } else { const QString renameFileError = tr("The file %1 could not be renamed %2.") - .arg(QDir::toNativeSeparators(oldFilePath)) - .arg(QDir::toNativeSeparators(newFilePath)); + .arg(oldFilePath.toUserOutput()) + .arg(newFilePath.toUserOutput()); QTimer::singleShot(0, [renameFileError]() { QMessageBox::warning(ICore::dialogParent(), tr("Cannot Rename File"), renameFileError); diff --git a/src/plugins/projectexplorer/projectnodes.cpp b/src/plugins/projectexplorer/projectnodes.cpp index 82118822302..be434510ca8 100644 --- a/src/plugins/projectexplorer/projectnodes.cpp +++ b/src/plugins/projectexplorer/projectnodes.cpp @@ -823,19 +823,19 @@ bool FolderNode::deleteFiles(const QStringList &filePaths) return false; } -bool FolderNode::canRenameFile(const QString &filePath, const QString &newFilePath) +bool FolderNode::canRenameFile(const Utils::FilePath &oldFilePath, const Utils::FilePath &newFilePath) { ProjectNode *pn = managingProject(); if (pn) - return pn->canRenameFile(filePath, newFilePath); + return pn->canRenameFile(oldFilePath, newFilePath); return false; } -bool FolderNode::renameFile(const QString &filePath, const QString &newFilePath) +bool FolderNode::renameFile(const Utils::FilePath &oldFilePath, const Utils::FilePath &newFilePath) { ProjectNode *pn = managingProject(); if (pn) - return pn->renameFile(filePath, newFilePath); + return pn->renameFile(oldFilePath, newFilePath); return false; } @@ -965,17 +965,17 @@ bool ProjectNode::deleteFiles(const QStringList &filePaths) return false; } -bool ProjectNode::canRenameFile(const QString &filePath, const QString &newFilePath) +bool ProjectNode::canRenameFile(const Utils::FilePath &oldFilePath, const Utils::FilePath &newFilePath) { if (BuildSystem *bs = buildSystem()) - return bs->canRenameFile(this, filePath, newFilePath); + return bs->canRenameFile(this, oldFilePath, newFilePath); return true; } -bool ProjectNode::renameFile(const QString &filePath, const QString &newFilePath) +bool ProjectNode::renameFile(const Utils::FilePath &oldFilePath, const Utils::FilePath &newFilePath) { if (BuildSystem *bs = buildSystem()) - return bs->renameFile(this, filePath, newFilePath); + return bs->renameFile(this, oldFilePath, newFilePath); return false; } diff --git a/src/plugins/projectexplorer/projectnodes.h b/src/plugins/projectexplorer/projectnodes.h index beb609a3c46..f6b8e0d9d96 100644 --- a/src/plugins/projectexplorer/projectnodes.h +++ b/src/plugins/projectexplorer/projectnodes.h @@ -306,8 +306,9 @@ public: virtual RemovedFilesFromProject removeFiles(const QStringList &filePaths, QStringList *notRemoved = nullptr); virtual bool deleteFiles(const QStringList &filePaths); - virtual bool canRenameFile(const QString &filePath, const QString &newFilePath); - virtual bool renameFile(const QString &filePath, const QString &newFilePath); + virtual bool canRenameFile(const Utils::FilePath &oldFilePath, + const Utils::FilePath &newFilePath); + virtual bool renameFile(const Utils::FilePath &oldFilePath, const Utils::FilePath &newFilePath); virtual bool addDependencies(const QStringList &dependencies); class AddNewInformation @@ -383,8 +384,8 @@ public: RemovedFilesFromProject removeFiles(const QStringList &filePaths, QStringList *notRemoved = nullptr) final; bool deleteFiles(const QStringList &filePaths) final; - bool canRenameFile(const QString &filePath, const QString &newFilePath) final; - bool renameFile(const QString &filePath, const QString &newFilePath) final; + bool canRenameFile(const Utils::FilePath &oldFilePath, const Utils::FilePath &newFilePath) final; + bool renameFile(const Utils::FilePath &oldFilePath, const Utils::FilePath &newFilePath) final; bool addDependencies(const QStringList &dependencies) final; bool supportsAction(ProjectAction action, const Node *node) const final; diff --git a/src/plugins/python/pythonproject.cpp b/src/plugins/python/pythonproject.cpp index e1304188ad6..e453d5c366d 100644 --- a/src/plugins/python/pythonproject.cpp +++ b/src/plugins/python/pythonproject.cpp @@ -66,7 +66,9 @@ public: bool addFiles(Node *, const QStringList &filePaths, QStringList *) override; RemovedFilesFromProject removeFiles(Node *, const QStringList &filePaths, QStringList *) override; bool deleteFiles(Node *, const QStringList &) override; - bool renameFile(Node *, const QString &filePath, const QString &newFilePath) override; + bool renameFile(Node *, + const Utils::FilePath &oldFilePath, + const Utils::FilePath &newFilePath) override; bool saveRawFileList(const QStringList &rawFileList); bool saveRawList(const QStringList &rawList, const QString &fileName); @@ -378,16 +380,16 @@ bool PythonBuildSystem::deleteFiles(Node *, const QStringList &) return true; } -bool PythonBuildSystem::renameFile(Node *, const QString &filePath, const QString &newFilePath) +bool PythonBuildSystem::renameFile(Node *, const FilePath &oldFilePath, const FilePath &newFilePath) { QStringList newList = m_rawFileList; - const QHash::iterator i = m_rawListEntries.find(filePath); + const QHash::iterator i = m_rawListEntries.find(oldFilePath.toString()); if (i != m_rawListEntries.end()) { const int index = newList.indexOf(i.value()); if (index != -1) { const QDir baseDir(projectDirectory().toString()); - newList.replace(index, baseDir.relativeFilePath(newFilePath)); + newList.replace(index, baseDir.relativeFilePath(newFilePath.toString())); } } diff --git a/src/plugins/qbsprojectmanager/qbsproject.cpp b/src/plugins/qbsprojectmanager/qbsproject.cpp index df30c39331c..dcf5552468d 100644 --- a/src/plugins/qbsprojectmanager/qbsproject.cpp +++ b/src/plugins/qbsprojectmanager/qbsproject.cpp @@ -286,19 +286,27 @@ RemovedFilesFromProject QbsBuildSystem::removeFiles(Node *context, const QString return BuildSystem::removeFiles(context, filePaths, notRemoved); } -bool QbsBuildSystem::renameFile(Node *context, const QString &filePath, const QString &newFilePath) +bool QbsBuildSystem::renameFile(Node *context, + const FilePath &oldFilePath, + const FilePath &newFilePath) { if (auto *n = dynamic_cast(context)) { const QbsProductNode * const prdNode = parentQbsProductNode(n); QTC_ASSERT(prdNode, return false); - return renameFileInProduct(filePath, newFilePath, prdNode->productData(), n->groupData()); + return renameFileInProduct(oldFilePath.toString(), + newFilePath.toString(), + prdNode->productData(), + n->groupData()); } if (auto *n = dynamic_cast(context)) { - return renameFileInProduct(filePath, newFilePath, n->productData(), n->mainGroup()); + return renameFileInProduct(oldFilePath.toString(), + newFilePath.toString(), + n->productData(), + n->mainGroup()); } - return BuildSystem::renameFile(context, filePath, newFilePath); + return BuildSystem::renameFile(context, oldFilePath, newFilePath); } QVariant QbsBuildSystem::additionalData(Id id) const diff --git a/src/plugins/qbsprojectmanager/qbsproject.h b/src/plugins/qbsprojectmanager/qbsproject.h index 4786f36981b..b7f216c210f 100644 --- a/src/plugins/qbsprojectmanager/qbsproject.h +++ b/src/plugins/qbsprojectmanager/qbsproject.h @@ -90,7 +90,7 @@ public: const QStringList &filePaths, QStringList *notRemoved = nullptr) final; bool renameFile(ProjectExplorer::Node *context, - const QString &filePath, const QString &newFilePath) final; + const Utils::FilePath &oldFilePath, const Utils::FilePath &newFilePath) final; QStringList filesGeneratedFrom(const QString &sourceFile) const final; QVariant additionalData(Utils::Id id) const final; diff --git a/src/plugins/qmakeprojectmanager/qmakenodes.cpp b/src/plugins/qmakeprojectmanager/qmakenodes.cpp index 6d358fe748c..5063d88ae74 100644 --- a/src/plugins/qmakeprojectmanager/qmakenodes.cpp +++ b/src/plugins/qmakeprojectmanager/qmakenodes.cpp @@ -264,24 +264,28 @@ bool QmakeBuildSystem::deleteFiles(Node *context, const QStringList &filePaths) return BuildSystem::deleteFiles(context, filePaths); } -bool QmakeBuildSystem::canRenameFile(Node *context, const QString &filePath, const QString &newFilePath) +bool QmakeBuildSystem::canRenameFile(Node *context, + const FilePath &oldFilePath, + const FilePath &newFilePath) { if (auto n = dynamic_cast(context)) { QmakePriFile *pri = n->priFile(); - return pri ? pri->canRenameFile(filePath, newFilePath) : false; + return pri ? pri->canRenameFile(oldFilePath, newFilePath) : false; } - return BuildSystem::canRenameFile(context, filePath, newFilePath); + return BuildSystem::canRenameFile(context, oldFilePath, newFilePath); } -bool QmakeBuildSystem::renameFile(Node *context, const QString &filePath, const QString &newFilePath) +bool QmakeBuildSystem::renameFile(Node *context, + const FilePath &oldFilePath, + const FilePath &newFilePath) { if (auto n = dynamic_cast(context)) { QmakePriFile *pri = n->priFile(); - return pri ? pri->renameFile(filePath, newFilePath) : false; + return pri ? pri->renameFile(oldFilePath, newFilePath) : false; } - return BuildSystem::renameFile(context, filePath, newFilePath); + return BuildSystem::renameFile(context, oldFilePath, newFilePath); } bool QmakeBuildSystem::addDependencies(Node *context, const QStringList &dependencies) diff --git a/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp b/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp index c29712c453e..76f3a08e3af 100644 --- a/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp +++ b/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp @@ -619,25 +619,25 @@ bool QmakePriFile::deleteFiles(const QStringList &filePaths) return true; } -bool QmakePriFile::canRenameFile(const QString &filePath, const QString &newFilePath) +bool QmakePriFile::canRenameFile(const FilePath &oldFilePath, const FilePath &newFilePath) { if (newFilePath.isEmpty()) return false; - bool changeProFileOptional = deploysFolder(QFileInfo(filePath).absolutePath()); + bool changeProFileOptional = deploysFolder(oldFilePath.absolutePath().toString()); if (changeProFileOptional) return true; - return renameFile(filePath, newFilePath, Change::TestOnly); + return renameFile(oldFilePath, newFilePath, Change::TestOnly); } -bool QmakePriFile::renameFile(const QString &filePath, const QString &newFilePath) +bool QmakePriFile::renameFile(const FilePath &oldFilePath, const FilePath &newFilePath) { if (newFilePath.isEmpty()) return false; - bool changeProFileOptional = deploysFolder(QFileInfo(filePath).absolutePath()); - if (renameFile(filePath, newFilePath, Change::Save)) + bool changeProFileOptional = deploysFolder(oldFilePath.absolutePath().toString()); + if (renameFile(oldFilePath, newFilePath, Change::Save)) return true; return changeProFileOptional; } @@ -798,7 +798,7 @@ bool QmakePriFile::prepareForChange() return saveModifiedEditors() && ensureWriteableProFile(filePath().toString()); } -bool QmakePriFile::renameFile(const QString &oldName, const QString &newName, Change mode) +bool QmakePriFile::renameFile(const FilePath &oldFilePath, const FilePath &newFilePath, Change mode) { if (!prepareForChange()) return false; @@ -812,14 +812,12 @@ bool QmakePriFile::renameFile(const QString &oldName, const QString &newName, Ch QDir priFileDir = QDir(m_qmakeProFile->directoryPath().toString()); ProWriter::VarLocations removedLocations; - const QStringList notChanged = ProWriter::removeFiles( - includeFile, - &lines, - priFileDir, - QStringList(oldName), - varNamesForRemoving(), - &removedLocations - ); + const QStringList notChanged = ProWriter::removeFiles(includeFile, + &lines, + priFileDir, + {oldFilePath.toString()}, + varNamesForRemoving(), + &removedLocations); includeFile->deref(); if (!notChanged.isEmpty()) @@ -828,7 +826,7 @@ bool QmakePriFile::renameFile(const QString &oldName, const QString &newName, Ch int endLine = lines.count(); reverseForeach(removedLocations, - [this, &newName, &lines, &endLine](const ProWriter::VarLocation &loc) { + [this, &newFilePath, &lines, &endLine](const ProWriter::VarLocation &loc) { QStringList currentLines = lines.mid(loc.second, endLine - loc.second); const QString currentContents = currentLines.join('\n'); @@ -841,7 +839,11 @@ bool QmakePriFile::renameFile(const QString &oldName, const QString &newName, Ch QMakeParser::FullGrammar); QTC_ASSERT(proFile, return); // The file should still be valid after what we did. - ProWriter::addFiles(proFile, ¤tLines, {newName}, loc.first, continuationIndent()); + ProWriter::addFiles(proFile, + ¤tLines, + {newFilePath.toString()}, + loc.first, + continuationIndent()); lines = lines.mid(0, loc.second) + currentLines + lines.mid(endLine); endLine = loc.second; proFile->deref(); diff --git a/src/plugins/qmakeprojectmanager/qmakeparsernodes.h b/src/plugins/qmakeprojectmanager/qmakeparsernodes.h index a5dcae96d69..b3e2dc4c579 100644 --- a/src/plugins/qmakeprojectmanager/qmakeparsernodes.h +++ b/src/plugins/qmakeprojectmanager/qmakeparsernodes.h @@ -165,8 +165,8 @@ public: bool addFiles(const QStringList &filePaths, QStringList *notAdded = nullptr); bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = nullptr); bool deleteFiles(const QStringList &filePaths); - bool canRenameFile(const QString &filePath, const QString &newFilePath); - bool renameFile(const QString &filePath, const QString &newFilePath); + bool canRenameFile(const Utils::FilePath &oldFilePath, const Utils::FilePath &newFilePath); + bool renameFile(const Utils::FilePath &oldFilePath, const Utils::FilePath &newFilePath); bool addDependencies(const QStringList &dependencies); bool setProVariable(const QString &var, const QStringList &values, @@ -203,7 +203,7 @@ protected: }; enum class Change { Save, TestOnly }; - bool renameFile(const QString &oldName, const QString &newName, Change mode); + bool renameFile(const Utils::FilePath &oldFilePath, const Utils::FilePath &newFilePath, Change mode); void changeFiles(const QString &mimeType, const QStringList &filePaths, QStringList *notChanged, diff --git a/src/plugins/qmakeprojectmanager/qmakeproject.h b/src/plugins/qmakeprojectmanager/qmakeproject.h index fba8c8db7a5..4fd0b7b33f2 100644 --- a/src/plugins/qmakeprojectmanager/qmakeproject.h +++ b/src/plugins/qmakeprojectmanager/qmakeproject.h @@ -98,9 +98,11 @@ public: bool deleteFiles(ProjectExplorer::Node *context, const QStringList &filePaths) override; bool canRenameFile(ProjectExplorer::Node *context, - const QString &filePath, const QString &newFilePath) override; + const Utils::FilePath &oldFilePath, + const Utils::FilePath &newFilePath) override; bool renameFile(ProjectExplorer::Node *context, - const QString &filePath, const QString &newFilePath) override; + const Utils::FilePath &oldFilePath, + const Utils::FilePath &newFilePath) override; bool addDependencies(ProjectExplorer::Node *context, const QStringList &dependencies) override; void triggerParsing() final; diff --git a/src/plugins/qmlprojectmanager/qmlproject.cpp b/src/plugins/qmlprojectmanager/qmlproject.cpp index 617173b09a7..77481cdbaea 100644 --- a/src/plugins/qmlprojectmanager/qmlproject.cpp +++ b/src/plugins/qmlprojectmanager/qmlproject.cpp @@ -521,11 +521,11 @@ bool QmlBuildSystem::deleteFiles(Node *context, const QStringList &filePaths) return BuildSystem::deleteFiles(context, filePaths); } -bool QmlBuildSystem::renameFile(Node * context, const QString &filePath, const QString &newFilePath) +bool QmlBuildSystem::renameFile(Node * context, const FilePath &oldFilePath, const FilePath &newFilePath) { if (dynamic_cast(context)) { - if (filePath.endsWith(mainFile())) { - setMainFile(newFilePath); + if (oldFilePath.endsWith(mainFile())) { + setMainFile(newFilePath.toString()); // make sure to change it also in the qmlproject file const Utils::FilePath qmlProjectFilePath = project()->projectFilePath(); @@ -549,12 +549,12 @@ bool QmlBuildSystem::renameFile(Node * context, const QString &filePath, const Q } // find the mainFile and do the file name with brackets in a capture group and mask the . with \. - QString originalFileName = QFileInfo(filePath).fileName(); + QString originalFileName = oldFilePath.fileName(); originalFileName.replace(".", "\\."); const QRegularExpression expression(QString("mainFile:\\s*\"(%1)\"").arg(originalFileName)); const QRegularExpressionMatch match = expression.match(fileContent); - fileContent.replace(match.capturedStart(1), match.capturedLength(1), QFileInfo(newFilePath).fileName()); + fileContent.replace(match.capturedStart(1), match.capturedLength(1), newFilePath.fileName()); if (!textFileFormat.writeFile(qmlProjectFilePath, fileContent, &error)) qWarning() << "Failed to write file" << qmlProjectFilePath << ":" << error; @@ -565,7 +565,7 @@ bool QmlBuildSystem::renameFile(Node * context, const QString &filePath, const Q return true; } - return BuildSystem::renameFile(context, filePath, newFilePath); + return BuildSystem::renameFile(context, oldFilePath, newFilePath); } } // namespace QmlProjectManager diff --git a/src/plugins/qmlprojectmanager/qmlproject.h b/src/plugins/qmlprojectmanager/qmlproject.h index 4fc4d49242d..002982e5897 100644 --- a/src/plugins/qmlprojectmanager/qmlproject.h +++ b/src/plugins/qmlprojectmanager/qmlproject.h @@ -58,7 +58,7 @@ public: bool deleteFiles(ProjectExplorer::Node *context, const QStringList &filePaths) override; bool renameFile(ProjectExplorer::Node *context, - const QString &filePath, const QString &newFilePath) override; + const Utils::FilePath &oldFilePath, const Utils::FilePath &newFilePath) override; QmlProject *qmlProject() const; diff --git a/src/plugins/resourceeditor/qrceditor/resourcefile.cpp b/src/plugins/resourceeditor/qrceditor/resourcefile.cpp index 7b48f88ef22..bfc77ad26fe 100644 --- a/src/plugins/resourceeditor/qrceditor/resourcefile.cpp +++ b/src/plugins/resourceeditor/qrceditor/resourcefile.cpp @@ -382,7 +382,8 @@ bool ResourceFile::renameFile(const QString &fileName, const QString &newFileNam if (entries.at(0)->exists()) { foreach (File *file, entries) file->setExists(true); - success = Core::FileUtils::renameFile(entries.at(0)->name, newFileName); + success = Core::FileUtils::renameFile(Utils::FilePath::fromString(entries.at(0)->name), + Utils::FilePath::fromString(newFileName)); } if (success) { diff --git a/src/plugins/resourceeditor/resourcenode.cpp b/src/plugins/resourceeditor/resourcenode.cpp index c00475e8503..dd2265693fe 100644 --- a/src/plugins/resourceeditor/resourcenode.cpp +++ b/src/plugins/resourceeditor/resourcenode.cpp @@ -177,8 +177,8 @@ public: bool addFiles(const QStringList &filePaths, QStringList *notAdded) final; RemovedFilesFromProject removeFiles(const QStringList &filePaths, QStringList *notRemoved) final; - bool canRenameFile(const QString &filePath, const QString &newFilePath) override; - bool renameFile(const QString &filePath, const QString &newFilePath) final; + bool canRenameFile(const Utils::FilePath &oldFilePath, const Utils::FilePath &newFilePath) override; + bool renameFile(const Utils::FilePath &oldFilePath, const Utils::FilePath &newFilePath) final; QString prefix() const { return m_prefix; } ResourceTopLevelNode *resourceNode() const { return m_topLevelNode; } @@ -226,14 +226,15 @@ RemovedFilesFromProject SimpleResourceFolderNode::removeFiles(const QStringList return prefixNode()->removeFiles(filePaths, notRemoved); } -bool SimpleResourceFolderNode::canRenameFile(const QString &filePath, const QString &newFilePath) +bool SimpleResourceFolderNode::canRenameFile(const FilePath &oldFilePath, + const FilePath &newFilePath) { - return prefixNode()->canRenameFile(filePath, newFilePath); + return prefixNode()->canRenameFile(oldFilePath, newFilePath); } -bool SimpleResourceFolderNode::renameFile(const QString &filePath, const QString &newFilePath) +bool SimpleResourceFolderNode::renameFile(const FilePath &oldFilePath, const FilePath &newFilePath) { - return prefixNode()->renameFile(filePath, newFilePath); + return prefixNode()->renameFile(oldFilePath, newFilePath); } } // Internal @@ -529,7 +530,7 @@ RemovedFilesFromProject ResourceFolderNode::removeFiles(const QStringList &fileP } // QTCREATORBUG-15280 -bool ResourceFolderNode::canRenameFile(const QString &filePath, const QString &newFilePath) +bool ResourceFolderNode::canRenameFile(const FilePath &oldFilePath, const FilePath &newFilePath) { Q_UNUSED(newFilePath) @@ -539,7 +540,7 @@ bool ResourceFolderNode::canRenameFile(const QString &filePath, const QString &n int index = (file.load() != IDocument::OpenResult::Success) ? -1 :file.indexOfPrefix(m_prefix, m_lang); if (index != -1) { for (int j = 0; j < file.fileCount(index); ++j) { - if (file.file(index, j) == filePath) { + if (file.file(index, j) == oldFilePath.toString()) { fileEntryExists = true; break; } @@ -549,7 +550,7 @@ bool ResourceFolderNode::canRenameFile(const QString &filePath, const QString &n return fileEntryExists; } -bool ResourceFolderNode::renameFile(const QString &filePath, const QString &newFilePath) +bool ResourceFolderNode::renameFile(const FilePath &oldFilePath, const FilePath &newFilePath) { ResourceFile file(m_topLevelNode->filePath().toString()); if (file.load() != IDocument::OpenResult::Success) @@ -559,8 +560,8 @@ bool ResourceFolderNode::renameFile(const QString &filePath, const QString &newF return false; for (int j = 0; j < file.fileCount(index); ++j) { - if (file.file(index, j) == filePath) { - file.replaceFile(index, j, newFilePath); + if (file.file(index, j) == oldFilePath.toString()) { + file.replaceFile(index, j, newFilePath.toString()); FileChangeBlocker changeGuard(m_topLevelNode->filePath()); file.save(); return true; diff --git a/src/plugins/resourceeditor/resourcenode.h b/src/plugins/resourceeditor/resourcenode.h index daa0442bd9c..d73da8db86e 100644 --- a/src/plugins/resourceeditor/resourcenode.h +++ b/src/plugins/resourceeditor/resourcenode.h @@ -73,8 +73,8 @@ public: bool addFiles(const QStringList &filePaths, QStringList *notAdded) override; ProjectExplorer::RemovedFilesFromProject removeFiles(const QStringList &filePaths, QStringList *notRemoved) override; - bool canRenameFile(const QString &filePath, const QString &newFilePath) override; - bool renameFile(const QString &filePath, const QString &newFilePath) override; + bool canRenameFile(const Utils::FilePath &oldFilePath, const Utils::FilePath &newFilePath) override; + bool renameFile(const Utils::FilePath &oldFilePath, const Utils::FilePath &newFilePath) override; bool renamePrefix(const QString &prefix, const QString &lang); diff --git a/src/plugins/texteditor/textmark.cpp b/src/plugins/texteditor/textmark.cpp index 94137d9ade4..110f451eed9 100644 --- a/src/plugins/texteditor/textmark.cpp +++ b/src/plugins/texteditor/textmark.cpp @@ -59,8 +59,10 @@ private: TextMarkRegistry(QObject *parent); static TextMarkRegistry* instance(); void editorOpened(Core::IEditor *editor); - void documentRenamed(Core::IDocument *document, const QString &oldName, const QString &newName); - void allDocumentsRenamed(const QString &oldName, const QString &newName); + void documentRenamed(Core::IDocument *document, + const FilePath &oldPath, + const FilePath &newPath); + void allDocumentsRenamed(const FilePath &oldPath, const FilePath &newPath); QHash > m_marks; }; @@ -448,42 +450,39 @@ void TextMarkRegistry::editorOpened(IEditor *editor) document->addMark(mark); } -void TextMarkRegistry::documentRenamed(IDocument *document, const - QString &oldName, const QString &newName) +void TextMarkRegistry::documentRenamed(IDocument *document, + const FilePath &oldPath, + const FilePath &newPath) { auto baseTextDocument = qobject_cast(document); if (!baseTextDocument) return; - FilePath oldFileName = FilePath::fromString(oldName); - FilePath newFileName = FilePath::fromString(newName); - if (!m_marks.contains(oldFileName)) + if (!m_marks.contains(oldPath)) return; QSet toBeMoved; foreach (TextMark *mark, baseTextDocument->marks()) toBeMoved.insert(mark); - m_marks[oldFileName].subtract(toBeMoved); - m_marks[newFileName].unite(toBeMoved); + m_marks[oldPath].subtract(toBeMoved); + m_marks[newPath].unite(toBeMoved); foreach (TextMark *mark, toBeMoved) - mark->updateFileName(newFileName); + mark->updateFileName(newPath); } -void TextMarkRegistry::allDocumentsRenamed(const QString &oldName, const QString &newName) +void TextMarkRegistry::allDocumentsRenamed(const FilePath &oldPath, const FilePath &newPath) { - FilePath oldFileName = FilePath::fromString(oldName); - FilePath newFileName = FilePath::fromString(newName); - if (!m_marks.contains(oldFileName)) + if (!m_marks.contains(oldPath)) return; - QSet oldFileNameMarks = m_marks.value(oldFileName); + QSet oldFileNameMarks = m_marks.value(oldPath); - m_marks[newFileName].unite(oldFileNameMarks); - m_marks[oldFileName].clear(); + m_marks[newPath].unite(oldFileNameMarks); + m_marks[oldPath].clear(); foreach (TextMark *mark, oldFileNameMarks) - mark->updateFileName(newFileName); + mark->updateFileName(newPath); } QHash AnnotationColors::m_colorCache;