From 39e2c013dd9ba8da79e8f37e69b9b53d8310e175 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Mon, 7 Nov 2016 21:03:24 +0100 Subject: [PATCH] ProjectExplorer: Handle root directory when creating folders Handle root directory properly (a empty filePath in the base node) when creating folder nodes in the project tree. Change-Id: Iad761b94ee210406ed5ab9ceb2d00ce25db90046 Reviewed-by: Tim Jenssen --- src/plugins/projectexplorer/projectnodes.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/plugins/projectexplorer/projectnodes.cpp b/src/plugins/projectexplorer/projectnodes.cpp index a8ecb9ee94b..d106f2697e8 100644 --- a/src/plugins/projectexplorer/projectnodes.cpp +++ b/src/plugins/projectexplorer/projectnodes.cpp @@ -383,12 +383,17 @@ FolderNode *FolderNode::folderNode(const Utils::FileName &directory) const FolderNode *FolderNode::recursiveFindOrCreateFolderNode(const QString &directory) { Utils::FileName path = filePath(); - QDir parentDir(path.toString()); - QString relativePath = parentDir.relativeFilePath(directory); - if (relativePath == ".") - relativePath.clear(); + QString workPath; + if (path.isEmpty() || path.toFileInfo().isRoot()) { + workPath = directory; + } else { + QDir parentDir(path.toString()); + workPath = parentDir.relativeFilePath(directory); + if (workPath == ".") + workPath.clear(); + } + const QStringList parts = workPath.split('/', QString::SkipEmptyParts); - QStringList parts = relativePath.split('/', QString::SkipEmptyParts); ProjectExplorer::FolderNode *parent = this; foreach (const QString &part, parts) { path.appendPath(part);