From 925b7a356655ce8a9a57ca34a15f3785c617541b Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Thu, 24 Aug 2023 18:11:01 +0200 Subject: [PATCH] CMakePM: Replace QDir with Utils::FilePath in editor This way we could handle remote files. Change-Id: I7062445cb743a2838f3c9f1bcff89611127011ca Reviewed-by: Eike Ziller --- .../cmakeprojectmanager/cmakeeditor.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp index 4425281a9ee..65b69bce2dd 100644 --- a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include @@ -186,7 +185,7 @@ void CMakeEditorWidget::findLinkAt(const QTextCursor &cursor, if (buffer.isEmpty()) return processLinkCallback(link); - QDir dir(textDocument()->filePath().toFileInfo().absolutePath()); + const Utils::FilePath dir = textDocument()->filePath().absolutePath(); buffer.replace("${CMAKE_CURRENT_SOURCE_DIR}", dir.path()); buffer.replace("${CMAKE_CURRENT_LIST_DIR}", dir.path()); @@ -211,18 +210,18 @@ void CMakeEditorWidget::findLinkAt(const QTextCursor &cursor, } // TODO: Resolve more variables - QString fileName = dir.filePath(unescape(buffer)); - QFileInfo fi(fileName); - if (fi.exists()) { - if (fi.isDir()) { - QDir subDir(fi.absoluteFilePath()); - QString subProject = subDir.filePath(QLatin1String("CMakeLists.txt")); - if (QFileInfo::exists(subProject)) + Utils::FilePath fileName = dir.withNewPath(unescape(buffer)); + if (fileName.isRelativePath()) + fileName = dir.pathAppended(fileName.path()); + if (fileName.exists()) { + if (fileName.isDir()) { + Utils::FilePath subProject = fileName.pathAppended("CMakeLists.txt"); + if (subProject.exists()) fileName = subProject; else return processLinkCallback(link); } - link.targetFilePath = Utils::FilePath::fromString(fileName); + link.targetFilePath = fileName; link.linkTextStart = cursor.position() - column + beginPos + 1; link.linkTextEnd = cursor.position() - column + endPos; }