forked from qt-creator/qt-creator
LanguageClient: move match function to language filter
Change-Id: I9081d441fa2f48e5a1c5273e2de2620e0b88c4e0 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -674,21 +674,12 @@ void Client::setSupportedLanguage(const LanguageFilter &filter)
|
|||||||
bool Client::isSupportedDocument(const Core::IDocument *document) const
|
bool Client::isSupportedDocument(const Core::IDocument *document) const
|
||||||
{
|
{
|
||||||
QTC_ASSERT(document, return false);
|
QTC_ASSERT(document, return false);
|
||||||
return isSupportedFile(document->filePath(), document->mimeType());
|
return m_languagFilter.isSupported(document->filePath(), document->mimeType());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Client::isSupportedFile(const Utils::FileName &filePath, const QString &mimeType) const
|
bool Client::isSupportedFile(const Utils::FileName &filePath, const QString &mimeType) const
|
||||||
{
|
{
|
||||||
if (m_languagFilter.mimeTypes.isEmpty() && m_languagFilter.filePattern.isEmpty())
|
return m_languagFilter.isSupported(filePath, mimeType);
|
||||||
return true;
|
|
||||||
if (m_languagFilter.mimeTypes.contains(mimeType))
|
|
||||||
return true;
|
|
||||||
auto regexps = Utils::transform(m_languagFilter.filePattern, [](const QString &pattern){
|
|
||||||
return QRegExp(pattern, Utils::HostOsInfo::fileNameCaseSensitivity(), QRegExp::Wildcard);
|
|
||||||
});
|
|
||||||
return Utils::anyOf(regexps, [filePath](const QRegExp ®){
|
|
||||||
return reg.exactMatch(filePath.toString()) || reg.exactMatch(filePath.fileName());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Client::isSupportedUri(const DocumentUri &uri) const
|
bool Client::isSupportedUri(const DocumentUri &uri) const
|
||||||
|
|||||||
@@ -719,4 +719,18 @@ QString StdIOSettingsWidget::arguments() const
|
|||||||
return m_arguments->text();
|
return m_arguments->text();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LanguageFilter::isSupported(const Utils::FileName &filePath, const QString &mimeType) const
|
||||||
|
{
|
||||||
|
if (mimeTypes.isEmpty() && filePattern.isEmpty())
|
||||||
|
return true;
|
||||||
|
if (mimeTypes.contains(mimeType))
|
||||||
|
return true;
|
||||||
|
auto regexps = Utils::transform(filePattern, [](const QString &pattern){
|
||||||
|
return QRegExp(pattern, Utils::HostOsInfo::fileNameCaseSensitivity(), QRegExp::Wildcard);
|
||||||
|
});
|
||||||
|
return Utils::anyOf(regexps, [filePath](const QRegExp ®){
|
||||||
|
return reg.exactMatch(filePath.toString()) || reg.exactMatch(filePath.fileName());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace LanguageClient
|
} // namespace LanguageClient
|
||||||
|
|||||||
@@ -37,7 +37,10 @@ class QCheckBox;
|
|||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Utils { class PathChooser; }
|
namespace Utils {
|
||||||
|
class FileName;
|
||||||
|
class PathChooser;
|
||||||
|
} // namespace Utils
|
||||||
|
|
||||||
namespace LanguageClient {
|
namespace LanguageClient {
|
||||||
|
|
||||||
@@ -50,6 +53,7 @@ struct LanguageFilter
|
|||||||
{
|
{
|
||||||
QStringList mimeTypes;
|
QStringList mimeTypes;
|
||||||
QStringList filePattern;
|
QStringList filePattern;
|
||||||
|
bool isSupported(const Utils::FileName &filePath, const QString &mimeType) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BaseSettings
|
class BaseSettings
|
||||||
|
|||||||
Reference in New Issue
Block a user