Utils: Make FileName::shortNativePath a member

Change-Id: If1ab02ae9dc7efb97792cdf3bbdce3bba18b3e3d
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2019-05-17 13:54:27 +02:00
parent c04370aa26
commit 535f0da977
10 changed files with 15 additions and 15 deletions

View File

@@ -254,16 +254,16 @@ FileName FileName::canonicalPath() const
Returns the possibly shortened path with native separators.
*/
QString FileUtils::shortNativePath(const FileName &path)
QString FileName::shortNativePath() const
{
if (HostOsInfo::isAnyUnixHost()) {
const FileName home = FileName::fromString(QDir::cleanPath(QDir::homePath()));
if (path.isChildOf(home)) {
if (isChildOf(home)) {
return QLatin1Char('~') + QDir::separator()
+ QDir::toNativeSeparators(path.relativeChildPath(home).toString());
+ QDir::toNativeSeparators(relativeChildPath(home).toString());
}
}
return path.toUserOutput();
return toUserOutput();
}
QString FileUtils::fileSystemFriendlyName(const QString &name)

View File

@@ -79,6 +79,8 @@ public:
QVariant toVariant() const;
QString toUserOutput() const;
QString shortNativePath() const;
QString fileName(int pathComponents = 0) const;
bool exists() const;
@@ -132,7 +134,6 @@ public:
const FileName &srcFilePath, const FileName &tgtFilePath, QString *error = nullptr,
const std::function<bool (QFileInfo, QFileInfo, QString *)> &copyHelper = nullptr);
static FileName resolveSymlinks(const FileName &path);
static QString shortNativePath(const FileName &path);
static QString fileSystemFriendlyName(const QString &name);
static int indexOfQmakeUnfriendly(const QString &name, int startpos = 0);
static QString qmakeFriendlyName(const QString &name);

View File

@@ -70,7 +70,7 @@ void CMakeLocatorFilter::prepareSearch(const QString &entry)
const int index = title.indexOf(entry);
if (index >= 0) {
Core::LocatorFilterEntry filterEntry(this, title, cmakeProject->projectFilePath().toString());
filterEntry.extraInfo = FileUtils::shortNativePath(cmakeProject->projectFilePath());
filterEntry.extraInfo = cmakeProject->projectFilePath().shortNativePath();
filterEntry.highlightInfo = {index, entry.length()};
m_result.append(filterEntry);
}

View File

@@ -403,7 +403,7 @@ void ReadOnlyFilesDialogPrivate::initDialog(const QStringList &fileNames)
auto item = new QTreeWidgetItem(ui.treeWidget);
item->setText(FileName, visibleName);
item->setIcon(FileName, FileIconProvider::icon(fileName));
item->setText(Folder, Utils::FileUtils::shortNativePath(Utils::FileName::fromFileInfo(directory)));
item->setText(Folder, Utils::FileName::fromFileInfo(directory).shortNativePath());
auto radioButtonGroup = new QButtonGroup;
// Add a button for opening the file with a version control system

View File

@@ -153,7 +153,7 @@ QList<LocatorFilterEntry> BaseFileFilter::matchesFor(QFutureInterface<LocatorFil
QFileInfo fi(path);
LocatorFilterEntry filterEntry(this, fi.fileName(), QString(path + fp.postfix));
filterEntry.fileName = path;
filterEntry.extraInfo = FileUtils::shortNativePath(FileName::fromFileInfo(fi));
filterEntry.extraInfo = FileName::fromFileInfo(fi).shortNativePath();
const int matchLevel = matchLevelFor(match, matchText);
if (hasPathSeparator) {

View File

@@ -142,8 +142,7 @@ QList<LocatorFilterEntry> FileSystemFilter::matchesFor(QFutureInterface<LocatorF
const QString fullFilePath = dirInfo.filePath(fileName);
if (!QFileInfo::exists(fullFilePath) && dirInfo.exists()) {
LocatorFilterEntry createAndOpen(this, tr("Create and Open \"%1\"").arg(entry), fullFilePath);
createAndOpen.extraInfo = Utils::FileUtils::shortNativePath(
Utils::FileName::fromString(dirInfo.absolutePath()));
createAndOpen.extraInfo = Utils::FileName::fromString(dirInfo.absolutePath()).shortNativePath();
betterEntries.append(createAndOpen);
}

View File

@@ -89,7 +89,7 @@ void Core::Internal::CorePlugin::test_basefilefilter()
void Core::Internal::CorePlugin::test_basefilefilter_data()
{
auto shortNativePath = [](const QString &file) {
return Utils::FileUtils::shortNativePath(Utils::FileName::fromString(file));
return Utils::FileName::fromString(file).shortNativePath();
};
QTest::addColumn<QStringList>("testFiles");

View File

@@ -76,7 +76,7 @@ QList<LocatorFilterEntry> OpenDocumentsFilter::matchesFor(QFutureInterface<Locat
const QRegularExpressionMatch match = regexp.match(displayName);
if (match.hasMatch()) {
LocatorFilterEntry filterEntry(this, displayName, QString(fileName + fp.postfix));
filterEntry.extraInfo = FileUtils::shortNativePath(FileName::fromString(fileName));
filterEntry.extraInfo = FileName::fromString(fileName).shortNativePath();
filterEntry.fileName = fileName;
filterEntry.highlightInfo = highlightInfo(match);
if (match.capturedStart() == 0)

View File

@@ -166,8 +166,8 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data()
MyTestDataDir testDirectory("testdata_basic");
const QString testFile = testDirectory.file("file1.cpp");
const QString objTestFile = testDirectory.file("file1.mm");
const QString testFileShort = FileUtils::shortNativePath(FileName::fromString(testFile));
const QString objTestFileShort = FileUtils::shortNativePath(FileName::fromString(objTestFile));
const QString testFileShort = FileName::fromString(testFile).shortNativePath();
const QString objTestFileShort = FileName::fromString(objTestFile).shortNativePath();
QTest::newRow("CppFunctionsFilter")
<< testFile

View File

@@ -88,7 +88,7 @@ QString IndexItem::representDeclaration() const
QString IndexItem::shortNativeFilePath() const
{
return Utils::FileUtils::shortNativePath(Utils::FileName::fromString(m_fileName));
return Utils::FileName::fromString(m_fileName).shortNativePath();
}
void IndexItem::squeeze()