forked from qt-creator/qt-creator
Utils: Make FileName::shortNativePath a member
Change-Id: If1ab02ae9dc7efb97792cdf3bbdce3bba18b3e3d Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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 *)> ©Helper = 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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user