From 0dd8d64060083ded0b499aba8a617f5ca12f90cd Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Tue, 18 Oct 2022 23:57:43 +0300 Subject: [PATCH] Revert "ProjectExplorer: Simplify node creation" It breaks the project tree, at least for Qt Creator CMake project. This reverts commit d1284570d6fe0712b1cc6fe4d0471d2871889af1. Change-Id: Ic5fe14cd4da476ca421551968e67fb8688433bbf Reviewed-by: Marcus Tillmanns Reviewed-by: hjk --- src/plugins/projectexplorer/projectnodes.cpp | 39 +++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/plugins/projectexplorer/projectnodes.cpp b/src/plugins/projectexplorer/projectnodes.cpp index 9245f7645ff..1b7c0546fe7 100644 --- a/src/plugins/projectexplorer/projectnodes.cpp +++ b/src/plugins/projectexplorer/projectnodes.cpp @@ -39,24 +39,37 @@ static FolderNode *recursiveFindOrCreateFolderNode(FolderNode *folder, const FilePath &overrideBaseDir, const FolderNode::FolderNodeFactory &factory) { - QList paths; - const Utils::FilePath basePath = overrideBaseDir.isEmpty() ? folder->filePath() - : overrideBaseDir; - Utils::FilePath path = basePath.isEmpty() ? directory : basePath.relativeChildPath(directory); + Utils::FilePath path = overrideBaseDir.isEmpty() ? folder->filePath() : overrideBaseDir; - while (!path.isEmpty()) { - paths.append(path); - path = path.parentDir(); + Utils::FilePath directoryWithoutPrefix; + bool isRelative = false; + + if (path.isEmpty() || path.isRootPath()) { + directoryWithoutPrefix = directory; + isRelative = false; + } else { + if (directory.isChildOf(path) || directory == path) { + isRelative = true; + directoryWithoutPrefix = directory.relativeChildPath(path); + } else { + isRelative = false; + path.clear(); + directoryWithoutPrefix = directory; + } } - std::reverse(std::begin(paths), std::end(paths)); + QStringList parts = directoryWithoutPrefix.path().split('/', Qt::SkipEmptyParts); + if (directory.osType() != OsTypeWindows && !isRelative && !parts.isEmpty()) + parts[0].prepend('/'); - FolderNode *parent = folder; - for (const auto ¤tPath : paths) { - FolderNode *next = parent->folderNode(currentPath); + ProjectExplorer::FolderNode *parent = folder; + for (const QString &part : std::as_const(parts)) { + path = path.pathAppended(part); + // Find folder in subFolders + FolderNode *next = parent->folderNode(path); if (!next) { // No FolderNode yet, so create it - auto tmp = factory(currentPath); - tmp->setDisplayName(currentPath.fileName()); + auto tmp = factory(path); + tmp->setDisplayName(part); next = tmp.get(); parent->addNode(std::move(tmp)); }