forked from qt-creator/qt-creator
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 <tim.jenssen@qt.io>
This commit is contained in:
@@ -383,12 +383,17 @@ FolderNode *FolderNode::folderNode(const Utils::FileName &directory) const
|
|||||||
FolderNode *FolderNode::recursiveFindOrCreateFolderNode(const QString &directory)
|
FolderNode *FolderNode::recursiveFindOrCreateFolderNode(const QString &directory)
|
||||||
{
|
{
|
||||||
Utils::FileName path = filePath();
|
Utils::FileName path = filePath();
|
||||||
|
QString workPath;
|
||||||
|
if (path.isEmpty() || path.toFileInfo().isRoot()) {
|
||||||
|
workPath = directory;
|
||||||
|
} else {
|
||||||
QDir parentDir(path.toString());
|
QDir parentDir(path.toString());
|
||||||
QString relativePath = parentDir.relativeFilePath(directory);
|
workPath = parentDir.relativeFilePath(directory);
|
||||||
if (relativePath == ".")
|
if (workPath == ".")
|
||||||
relativePath.clear();
|
workPath.clear();
|
||||||
|
}
|
||||||
|
const QStringList parts = workPath.split('/', QString::SkipEmptyParts);
|
||||||
|
|
||||||
QStringList parts = relativePath.split('/', QString::SkipEmptyParts);
|
|
||||||
ProjectExplorer::FolderNode *parent = this;
|
ProjectExplorer::FolderNode *parent = this;
|
||||||
foreach (const QString &part, parts) {
|
foreach (const QString &part, parts) {
|
||||||
path.appendPath(part);
|
path.appendPath(part);
|
||||||
|
|||||||
Reference in New Issue
Block a user