forked from qt-creator/qt-creator
Utils: Make Utils::withTildeHomePath a FilePath member
Gets .osType() right in remote cases. Change-Id: I6397996062d976d7db690c5729dd4faa1f459563 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -1720,6 +1720,28 @@ FilePath FilePath::cleanPath() const
|
||||
return withNewPath(doCleanPath(path()));
|
||||
}
|
||||
|
||||
/*!
|
||||
On Linux/Mac replace user's home path with ~ in the \c toString()
|
||||
result for this path after cleaning.
|
||||
|
||||
If path is not sub of home path, or when running on Windows, returns the input
|
||||
*/
|
||||
QString FilePath::withTildeHomePath() const
|
||||
{
|
||||
if (osType() == OsTypeWindows)
|
||||
return toString();
|
||||
|
||||
if (needsDevice())
|
||||
return toString();
|
||||
|
||||
static const QString homePath = QDir::homePath();
|
||||
|
||||
QString outPath = cleanPath().absoluteFilePath().path();
|
||||
if (outPath.startsWith(homePath))
|
||||
outPath = '~' + outPath.mid(homePath.size());
|
||||
return outPath;
|
||||
}
|
||||
|
||||
QTextStream &operator<<(QTextStream &s, const FilePath &fn)
|
||||
{
|
||||
return s << fn.toString();
|
||||
|
||||
Reference in New Issue
Block a user