forked from qt-creator/qt-creator
Replace .qmlproject default editor with the .qml one
Extend logic for mimetype matching in QmlJsEditor: Also handle sub-mimetypes like x-application-qmlproject, which extends x-application-qml.
This commit is contained in:
@@ -170,10 +170,11 @@ void QmlModelManager::parse(QFutureInterface<void> &future,
|
||||
doc->setSource(contents);
|
||||
|
||||
const QFileInfo fileInfo(fileName);
|
||||
Core::MimeType fileMimeTy = db->findByFile(fileInfo);
|
||||
|
||||
if (jsSourceTy.matchesFile(fileInfo))
|
||||
if (matchesMimeType(fileMimeTy, jsSourceTy))
|
||||
doc->parseJavaScript();
|
||||
else if (qmlSourceTy.matchesFile(fileInfo))
|
||||
else if (matchesMimeType(fileMimeTy, qmlSourceTy))
|
||||
doc->parseQml();
|
||||
else
|
||||
qWarning() << "Don't know how to treat" << fileName;
|
||||
@@ -183,3 +184,23 @@ void QmlModelManager::parse(QFutureInterface<void> &future,
|
||||
|
||||
future.setProgressValue(files.size());
|
||||
}
|
||||
|
||||
// Check whether fileMimeType is the same or extends knownMimeType
|
||||
bool QmlModelManager::matchesMimeType(const Core::MimeType &fileMimeType, const Core::MimeType &knownMimeType)
|
||||
{
|
||||
Core::MimeDatabase *db = Core::ICore::instance()->mimeDatabase();
|
||||
|
||||
const QStringList knownTypeNames = QStringList(knownMimeType.type()) + knownMimeType.aliases();
|
||||
|
||||
foreach (const QString knownTypeName, knownTypeNames)
|
||||
if (fileMimeType.matchesType(knownTypeName))
|
||||
return true;
|
||||
|
||||
// recursion to parent types of fileMimeType
|
||||
foreach (const QString &parentMimeType, fileMimeType.subClassesOf()) {
|
||||
if (matchesMimeType(db->findByType(parentMimeType), knownMimeType))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
|
||||
namespace Core {
|
||||
class ICore;
|
||||
class MimeType;
|
||||
}
|
||||
|
||||
namespace QmlJSEditor {
|
||||
@@ -82,6 +83,8 @@ protected:
|
||||
QmlModelManager *modelManager);
|
||||
|
||||
private:
|
||||
static bool matchesMimeType(const Core::MimeType &fileMimeType, const Core::MimeType &knownMimeType);
|
||||
|
||||
mutable QMutex m_mutex;
|
||||
Core::ICore *m_core;
|
||||
QmlJS::Snapshot _snapshot;
|
||||
|
||||
Reference in New Issue
Block a user