forked from qt-creator/qt-creator
MimeDatabase: add FilePath convenience function
Change-Id: I59c825490b3b5c49f3c177584ea4cc885c4f920b Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -116,7 +116,7 @@ static QVector<Tool> toolsForMimeType(const Utils::MimeType &mimeType)
|
||||
|
||||
static QVector<Tool> toolsForFilePath(const Utils::FilePath &fp)
|
||||
{
|
||||
return toolsForMimeType(Utils::mimeTypeForFile(fp.toString()));
|
||||
return toolsForMimeType(Utils::mimeTypeForFile(fp));
|
||||
}
|
||||
|
||||
static Utils::optional<Tool> resolveTool(const Tool &tool)
|
||||
|
@@ -47,6 +47,8 @@
|
||||
#include "mimeprovider_p.h"
|
||||
#include "mimetype_p.h"
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QFileInfo>
|
||||
@@ -733,6 +735,12 @@ MimeType Utils::mimeTypeForFile(const QFileInfo &fileInfo, MimeMatchMode mode)
|
||||
return mdb.mimeTypeForFile(fileInfo, MimeDatabase::MatchMode(mode));
|
||||
}
|
||||
|
||||
MimeType Utils::mimeTypeForFile(const FilePath &filePath, MimeMatchMode mode)
|
||||
{
|
||||
MimeDatabase mdb;
|
||||
return mdb.mimeTypeForFile(filePath.toString(), MimeDatabase::MatchMode(mode));
|
||||
}
|
||||
|
||||
QList<MimeType> Utils::mimeTypesForFileName(const QString &fileName)
|
||||
{
|
||||
MimeDatabase mdb;
|
||||
|
@@ -50,6 +50,8 @@ QT_END_NAMESPACE
|
||||
|
||||
namespace Utils {
|
||||
|
||||
class FilePath;
|
||||
|
||||
// Wrapped QMimeDataBase functions
|
||||
QTCREATOR_UTILS_EXPORT MimeType mimeTypeForName(const QString &nameOrAlias);
|
||||
|
||||
@@ -61,6 +63,7 @@ enum class MimeMatchMode {
|
||||
|
||||
QTCREATOR_UTILS_EXPORT MimeType mimeTypeForFile(const QString &fileName, MimeMatchMode mode = MimeMatchMode::MatchDefault);
|
||||
QTCREATOR_UTILS_EXPORT MimeType mimeTypeForFile(const QFileInfo &fileInfo, MimeMatchMode mode = MimeMatchMode::MatchDefault);
|
||||
QTCREATOR_UTILS_EXPORT MimeType mimeTypeForFile(const FilePath &filePath, MimeMatchMode mode = MimeMatchMode::MatchDefault);
|
||||
QTCREATOR_UTILS_EXPORT QList<MimeType> mimeTypesForFileName(const QString &fileName);
|
||||
QTCREATOR_UTILS_EXPORT MimeType mimeTypeForData(const QByteArray &data);
|
||||
QTCREATOR_UTILS_EXPORT QList<MimeType> allMimeTypes();
|
||||
|
@@ -1316,9 +1316,7 @@ bool InternalCppCompletionAssistProcessor::objcKeywordsWanted() const
|
||||
if (!m_interface->languageFeatures().objCEnabled)
|
||||
return false;
|
||||
|
||||
const QString fileName = m_interface->filePath().toString();
|
||||
|
||||
const Utils::MimeType mt = Utils::mimeTypeForFile(fileName);
|
||||
const Utils::MimeType mt = Utils::mimeTypeForFile(m_interface->filePath());
|
||||
return mt.matchesName(QLatin1String(CppTools::Constants::OBJECTIVE_C_SOURCE_MIMETYPE))
|
||||
|| mt.matchesName(QLatin1String(CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE));
|
||||
}
|
||||
|
@@ -145,7 +145,7 @@ Core::IDocument::OpenResult ImageViewerFile::openImpl(QString *errorString,
|
||||
}
|
||||
|
||||
setFilePath(filePath);
|
||||
setMimeType(Utils::mimeTypeForFile(fileName).name());
|
||||
setMimeType(Utils::mimeTypeForFile(filePath).name());
|
||||
return OpenResult::Success;
|
||||
}
|
||||
|
||||
|
@@ -972,8 +972,8 @@ bool Client::isSupportedFile(const Utils::FilePath &filePath, const QString &mim
|
||||
|
||||
bool Client::isSupportedUri(const DocumentUri &uri) const
|
||||
{
|
||||
return m_languagFilter.isSupported(uri.toFilePath(),
|
||||
Utils::mimeTypeForFile(uri.toFilePath().fileName()).name());
|
||||
const FilePath &filePath = uri.toFilePath();
|
||||
return m_languagFilter.isSupported(filePath, Utils::mimeTypeForFile(filePath).name());
|
||||
}
|
||||
|
||||
void Client::addAssistProcessor(TextEditor::IAssistProcessor *processor)
|
||||
|
@@ -642,8 +642,7 @@ BuildConfigurationFactory *BuildConfigurationFactory::find(const Kit *k, const F
|
||||
QTC_ASSERT(k, return nullptr);
|
||||
const Utils::Id deviceType = DeviceTypeKitAspect::deviceTypeId(k);
|
||||
for (BuildConfigurationFactory *factory : qAsConst(g_buildConfigurationFactories)) {
|
||||
if (Utils::mimeTypeForFile(projectPath.toString())
|
||||
.matchesName(factory->m_supportedProjectMimeTypeName)
|
||||
if (Utils::mimeTypeForFile(projectPath).matchesName(factory->m_supportedProjectMimeTypeName)
|
||||
&& factory->supportsTargetDeviceType(deviceType))
|
||||
return factory;
|
||||
}
|
||||
|
@@ -4024,7 +4024,7 @@ QStringList ProjectExplorerPlugin::projectFilePatterns()
|
||||
|
||||
bool ProjectExplorerPlugin::isProjectFile(const Utils::FilePath &filePath)
|
||||
{
|
||||
Utils::MimeType mt = Utils::mimeTypeForFile(filePath.toString());
|
||||
Utils::MimeType mt = Utils::mimeTypeForFile(filePath);
|
||||
for (auto it = dd->m_projectCreators.cbegin(); it != dd->m_projectCreators.cend(); ++it) {
|
||||
if (mt.inherits(it.key()))
|
||||
return true;
|
||||
|
@@ -307,8 +307,7 @@ FileType Node::fileTypeForMimeType(const Utils::MimeType &mt)
|
||||
|
||||
FileType Node::fileTypeForFileName(const Utils::FilePath &file)
|
||||
{
|
||||
return fileTypeForMimeType(Utils::mimeTypeForFile(file.toString(),
|
||||
Utils::MimeMatchMode::MatchExtension));
|
||||
return fileTypeForMimeType(Utils::mimeTypeForFile(file, Utils::MimeMatchMode::MatchExtension));
|
||||
}
|
||||
|
||||
QString Node::pathOrDirectory(bool dir) const
|
||||
|
@@ -150,7 +150,7 @@ void TreeScanner::scanForFiles(FutureInterface &fi, const Utils::FilePath& direc
|
||||
{
|
||||
Result nodes = FileNode::scanForFiles(fi, directory,
|
||||
[&filter, &factory](const Utils::FilePath &fn) -> FileNode * {
|
||||
const Utils::MimeType mimeType = Utils::mimeTypeForFile(fn.toString());
|
||||
const Utils::MimeType mimeType = Utils::mimeTypeForFile(fn);
|
||||
|
||||
// Skip some files during scan.
|
||||
if (filter && filter(mimeType, fn))
|
||||
|
@@ -119,7 +119,7 @@ ModelManagerInterface::ProjectInfo ModelManager::defaultProjectInfoForProject(
|
||||
return false;
|
||||
const FileNode *fn = n->asFileNode();
|
||||
return fn && fn->fileType() == FileType::QML
|
||||
&& qmlTypeNames.contains(Utils::mimeTypeForFile(fn->filePath().toString(),
|
||||
&& qmlTypeNames.contains(Utils::mimeTypeForFile(fn->filePath(),
|
||||
MimeMatchMode::MatchExtension).name());
|
||||
}), &FilePath::toString);
|
||||
activeTarget = project->activeTarget();
|
||||
|
@@ -719,7 +719,7 @@ Core::IDocument::OpenResult TextDocument::open(QString *errorString,
|
||||
emit aboutToOpen(filePath, realFilePath);
|
||||
OpenResult success = openImpl(errorString, filePath, realFilePath, /*reload =*/ false);
|
||||
if (success == OpenResult::Success) {
|
||||
setMimeType(Utils::mimeTypeForFile(filePath.toString()).name());
|
||||
setMimeType(Utils::mimeTypeForFile(filePath).name());
|
||||
emit openFinishedSuccessfully();
|
||||
}
|
||||
return success;
|
||||
|
@@ -3204,7 +3204,7 @@ void TextEditorWidgetPrivate::updateCodeFoldingVisible()
|
||||
|
||||
void TextEditorWidgetPrivate::reconfigure()
|
||||
{
|
||||
m_document->setMimeType(Utils::mimeTypeForFile(m_document->filePath().toString()).name());
|
||||
m_document->setMimeType(Utils::mimeTypeForFile(m_document->filePath()).name());
|
||||
q->configureGenericHighlighter();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user