ProjectExplorer: Show near paths as relative

Previously if a path was not a child of the directory it was inserted
into it would be displayed as an absolute path.

This changes it to show it relative with ".." as long as there are no
more than 5 "../"'s.

Fixes: QTCREATORBUG-288
Change-Id: I456138e97298d58ac6d95e69443c8e187fb8782c
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Marcus Tillmanns
2022-10-27 12:09:05 +02:00
parent 1caade7333
commit d01c22b805

View File

@@ -52,9 +52,15 @@ static FolderNode *recursiveFindOrCreateFolderNode(FolderNode *folder,
isRelative = true; isRelative = true;
directoryWithoutPrefix = directory.relativeChildPath(path); directoryWithoutPrefix = directory.relativeChildPath(path);
} else { } else {
isRelative = false; const FilePath relativePath = directory.relativePathFrom(path);
path.clear(); if (relativePath.path().count("../") < 5) {
directoryWithoutPrefix = directory; isRelative = true;
directoryWithoutPrefix = relativePath;
} else {
isRelative = false;
path.clear();
directoryWithoutPrefix = directory;
}
} }
} }
QStringList parts = directoryWithoutPrefix.path().split('/', Qt::SkipEmptyParts); QStringList parts = directoryWithoutPrefix.path().split('/', Qt::SkipEmptyParts);