forked from qt-creator/qt-creator
qmljs: differnt language constants for the different qml flavors
Added separated qbs, qmltypes, QtQuick1, and QtQuick2 and "generic" Qml languages. Cleaned up the mime types a bit, preparing for registered mime types. Change-Id: I0e484c93e003176cd659acc546baa6d024defa19 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com> Reviewed-by: Fawzi Mohamed <fawzi.mohamed@digia.com>
This commit is contained in:
@@ -70,27 +70,41 @@ using namespace QmlJSTools::Internal;
|
||||
|
||||
static QStringList environmentImportPaths();
|
||||
|
||||
static void mergeSuffixes(QStringList &l1, const QStringList &l2)
|
||||
{
|
||||
if (!l2.isEmpty())
|
||||
l1 = l2;
|
||||
}
|
||||
|
||||
QmlJS::Document::Language QmlJSTools::languageOfFile(const QString &fileName)
|
||||
{
|
||||
QStringList jsSuffixes(QLatin1String("js"));
|
||||
QStringList qmlSuffixes(QLatin1String("qml"));
|
||||
QStringList qmlProjectSuffixes(QLatin1String("qmlproject"));
|
||||
QStringList jsonSuffixes(QLatin1String("json"));
|
||||
QStringList qbsSuffixes(QLatin1String("qbs"));
|
||||
|
||||
if (Core::ICore::instance()) {
|
||||
Core::MimeDatabase *db = Core::ICore::mimeDatabase();
|
||||
Core::MimeType jsSourceTy = db->findByType(QLatin1String(Constants::JS_MIMETYPE));
|
||||
jsSuffixes = jsSourceTy.suffixes();
|
||||
mergeSuffixes(jsSuffixes, jsSourceTy.suffixes());
|
||||
Core::MimeType qmlSourceTy = db->findByType(QLatin1String(Constants::QML_MIMETYPE));
|
||||
qmlSuffixes = qmlSourceTy.suffixes();
|
||||
mergeSuffixes(qmlSuffixes, qmlSourceTy.suffixes());
|
||||
Core::MimeType qbsSourceTy = db->findByType(QLatin1String(Constants::QBS_MIMETYPE));
|
||||
mergeSuffixes(qbsSuffixes, qbsSourceTy.suffixes());
|
||||
Core::MimeType qmlProjectSourceTy = db->findByType(QLatin1String(Constants::QMLPROJECT_MIMETYPE));
|
||||
mergeSuffixes(qbsSuffixes, qmlProjectSourceTy.suffixes());
|
||||
Core::MimeType jsonSourceTy = db->findByType(QLatin1String(Constants::JSON_MIMETYPE));
|
||||
jsonSuffixes = jsonSourceTy.suffixes();
|
||||
mergeSuffixes(jsonSuffixes, jsonSourceTy.suffixes());
|
||||
}
|
||||
|
||||
const QFileInfo info(fileName);
|
||||
const QString fileSuffix = info.suffix();
|
||||
if (jsSuffixes.contains(fileSuffix))
|
||||
return QmlJS::Document::JavaScriptLanguage;
|
||||
if (qmlSuffixes.contains(fileSuffix))
|
||||
if (qbsSuffixes.contains(fileSuffix))
|
||||
return QmlJS::Document::QmlQbsLanguage;
|
||||
if (qmlSuffixes.contains(fileSuffix) || qmlProjectSuffixes.contains(fileSuffix))
|
||||
return QmlJS::Document::QmlLanguage;
|
||||
if (jsonSuffixes.contains(fileSuffix))
|
||||
return QmlJS::Document::JsonLanguage;
|
||||
|
||||
@@ -35,7 +35,10 @@
|
||||
namespace QmlJSTools {
|
||||
namespace Constants {
|
||||
|
||||
const char QML_MIMETYPE[] = "application/x-qml";
|
||||
const char QML_MIMETYPE[] = "application/x-qml"; // separate def also in projectexplorerconstants.h
|
||||
const char QBS_MIMETYPE[] = "application/x-qt.qbs+qml";
|
||||
const char QMLPROJECT_MIMETYPE[] = "application/x-qmlproject";
|
||||
const char QMLTYPES_MIMETYPE[] = "application/x-qt.meta-info+qml";
|
||||
const char JS_MIMETYPE[] = "application/javascript";
|
||||
const char JSON_MIMETYPE[] = "application/json";
|
||||
|
||||
|
||||
@@ -140,6 +140,15 @@ QmlJSToolsSettings::QmlJSToolsSettings(QObject *parent)
|
||||
textEditorSettings->registerMimeTypeForLanguageId(
|
||||
QLatin1String(Constants::QML_MIMETYPE),
|
||||
Constants::QML_JS_SETTINGS_ID);
|
||||
textEditorSettings->registerMimeTypeForLanguageId(
|
||||
QLatin1String(Constants::QBS_MIMETYPE),
|
||||
Constants::QML_JS_SETTINGS_ID);
|
||||
textEditorSettings->registerMimeTypeForLanguageId(
|
||||
QLatin1String(Constants::QMLPROJECT_MIMETYPE),
|
||||
Constants::QML_JS_SETTINGS_ID);
|
||||
textEditorSettings->registerMimeTypeForLanguageId(
|
||||
QLatin1String(Constants::QMLTYPES_MIMETYPE),
|
||||
Constants::QML_JS_SETTINGS_ID);
|
||||
textEditorSettings->registerMimeTypeForLanguageId(
|
||||
QLatin1String(Constants::JS_MIMETYPE),
|
||||
Constants::QML_JS_SETTINGS_ID);
|
||||
|
||||
Reference in New Issue
Block a user