forked from qt-creator/qt-creator
Mimetypes v3: Re-implement MimeType setPreferredSuffix
Used by the CppEditor to set the preferred suffix for C/C++ files according to Options > C++ > File Naming. Change-Id: I1b0c862a17febf742202433ee677fcccc1aa511b Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -54,6 +54,17 @@
|
|||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
|
static QString suffixFromPattern(const QString &pattern)
|
||||||
|
{
|
||||||
|
// Not a simple suffix if it looks like: README or *. or *.* or *.JP*G or *.JP?
|
||||||
|
if (pattern.startsWith(QLatin1String("*.")) &&
|
||||||
|
pattern.length() > 2 &&
|
||||||
|
pattern.indexOf(QLatin1Char('*'), 2) < 0 && pattern.indexOf(QLatin1Char('?'), 2) < 0) {
|
||||||
|
return pattern.mid(2);
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
MimeTypePrivate::MimeTypePrivate()
|
MimeTypePrivate::MimeTypePrivate()
|
||||||
: loaded(false), fromCache(false)
|
: loaded(false), fromCache(false)
|
||||||
{}
|
{}
|
||||||
@@ -445,13 +456,9 @@ QStringList MimeType::suffixes() const
|
|||||||
|
|
||||||
QStringList result;
|
QStringList result;
|
||||||
for (const QString &pattern : qAsConst(d->globPatterns)) {
|
for (const QString &pattern : qAsConst(d->globPatterns)) {
|
||||||
// Not a simple suffix if it looks like: README or *. or *.* or *.JP*G or *.JP?
|
const QString suffix = suffixFromPattern(pattern);
|
||||||
if (pattern.startsWith(QLatin1String("*.")) &&
|
if (!suffix.isEmpty())
|
||||||
pattern.length() > 2 &&
|
|
||||||
pattern.indexOf(QLatin1Char('*'), 2) < 0 && pattern.indexOf(QLatin1Char('?'), 2) < 0) {
|
|
||||||
const QString suffix = pattern.mid(2);
|
|
||||||
result.append(suffix);
|
result.append(suffix);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -533,15 +540,16 @@ bool MimeType::matchesName(const QString &nameOrAlias) const
|
|||||||
*/
|
*/
|
||||||
void MimeType::setPreferredSuffix(const QString &suffix)
|
void MimeType::setPreferredSuffix(const QString &suffix)
|
||||||
{
|
{
|
||||||
// MimeDatabasePrivate::instance()->provider()->loadMimeTypePrivate(*d);
|
MimeDatabasePrivate::instance()->loadMimeTypePrivate(const_cast<MimeTypePrivate&>(*d));
|
||||||
|
|
||||||
// auto it = std::find_if(d->globPatterns.begin(), d->globPatterns.end(),
|
auto it = std::find_if(d->globPatterns.begin(),
|
||||||
// [suffix](const QString &pattern) {
|
d->globPatterns.end(),
|
||||||
// return suffixFromPattern(pattern) == suffix;
|
[suffix](const QString &pattern) {
|
||||||
// });
|
return suffixFromPattern(pattern) == suffix;
|
||||||
// if (it != d->globPatterns.end())
|
});
|
||||||
// d->globPatterns.erase(it);
|
if (it != d->globPatterns.end())
|
||||||
// d->globPatterns.prepend(QLatin1String("*.") + suffix);
|
d->globPatterns.erase(it);
|
||||||
|
d->globPatterns.prepend(QLatin1String("*.") + suffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
|||||||
Reference in New Issue
Block a user