forked from qt-creator/qt-creator
ProjectExplorer: Simplify node creation
Simplifies node creation by not trying to manually split / concatenate paths. Change-Id: I5cb4e9391eb8aef6e6942b8b424ac6ef451d1aff Reviewed-by: hjk <hjk@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -39,37 +39,24 @@ static FolderNode *recursiveFindOrCreateFolderNode(FolderNode *folder,
|
|||||||
const FilePath &overrideBaseDir,
|
const FilePath &overrideBaseDir,
|
||||||
const FolderNode::FolderNodeFactory &factory)
|
const FolderNode::FolderNodeFactory &factory)
|
||||||
{
|
{
|
||||||
Utils::FilePath path = overrideBaseDir.isEmpty() ? folder->filePath() : overrideBaseDir;
|
QList<FilePath> paths;
|
||||||
|
const Utils::FilePath basePath = overrideBaseDir.isEmpty() ? folder->filePath()
|
||||||
|
: overrideBaseDir;
|
||||||
|
Utils::FilePath path = basePath.isEmpty() ? directory : basePath.relativeChildPath(directory);
|
||||||
|
|
||||||
Utils::FilePath directoryWithoutPrefix;
|
while (!path.isEmpty()) {
|
||||||
bool isRelative = false;
|
paths.append(path);
|
||||||
|
path = path.parentDir();
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
QStringList parts = directoryWithoutPrefix.path().split('/', Qt::SkipEmptyParts);
|
std::reverse(std::begin(paths), std::end(paths));
|
||||||
if (directory.osType() != OsTypeWindows && !isRelative && !parts.isEmpty())
|
|
||||||
parts[0].prepend('/');
|
|
||||||
|
|
||||||
ProjectExplorer::FolderNode *parent = folder;
|
FolderNode *parent = folder;
|
||||||
for (const QString &part : std::as_const(parts)) {
|
for (const auto ¤tPath : paths) {
|
||||||
path = path.pathAppended(part);
|
FolderNode *next = parent->folderNode(currentPath);
|
||||||
// Find folder in subFolders
|
|
||||||
FolderNode *next = parent->folderNode(path);
|
|
||||||
if (!next) {
|
if (!next) {
|
||||||
// No FolderNode yet, so create it
|
// No FolderNode yet, so create it
|
||||||
auto tmp = factory(path);
|
auto tmp = factory(currentPath);
|
||||||
tmp->setDisplayName(part);
|
tmp->setDisplayName(currentPath.fileName());
|
||||||
next = tmp.get();
|
next = tmp.get();
|
||||||
parent->addNode(std::move(tmp));
|
parent->addNode(std::move(tmp));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user