forked from qt-creator/qt-creator
Use new mime database
Change-Id: I4305872b6b11ef3e8a364280ffa5209a5a793600 Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<alias type="text/x-qml"/>
|
||||
<sub-class-of type="text/plain"/>
|
||||
<comment>QML file</comment>
|
||||
<glob weight="50" pattern="*.qml"/>
|
||||
<glob pattern="*.qml"/>
|
||||
</mime-type>
|
||||
<mime-type type="application/x-qt.qbs+qml">
|
||||
<alias type="text/x-qt.qbs+qml"/>
|
||||
@@ -16,7 +16,7 @@
|
||||
<alias type="text/x-qt.ui+qml"/>
|
||||
<sub-class-of type="application/x-qml"/>
|
||||
<comment>QtQuick Designer ui file</comment>
|
||||
<glob weight="100" pattern="*.ui.qml"/>
|
||||
<glob pattern="*.ui.qml"/>
|
||||
</mime-type>
|
||||
<mime-type type="application/x-qmlproject">
|
||||
<alias type="text/x-qmlproject"/>
|
||||
@@ -30,16 +30,6 @@
|
||||
<comment>QML file</comment>
|
||||
<glob pattern="*.qmltypes"/>
|
||||
</mime-type>
|
||||
<mime-type type="application/javascript">
|
||||
<alias type="application/x-javascript"/>
|
||||
<alias type="text/javascript"/>
|
||||
<alias type="text/x-javascript"/>
|
||||
<sub-class-of type="text/plain"/>
|
||||
<comment>Qt Script file</comment>
|
||||
<glob pattern="*.js"/>
|
||||
<glob pattern="*.qs"/>
|
||||
<glob pattern="*.qtt"/>
|
||||
</mime-type>
|
||||
<mime-type type="application/json">
|
||||
<sub-class-of type="text/plain"/>
|
||||
<comment>JSON file</comment>
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
#include <qtsupport/qtsupportconstants.h>
|
||||
#include <texteditor/textdocument.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/mimetypes/mimedatabase.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
@@ -76,22 +77,18 @@ ModelManagerInterface::ProjectInfo QmlJSTools::Internal::ModelManager::defaultPr
|
||||
ModelManagerInterface::ProjectInfo projectInfo(project);
|
||||
ProjectExplorer::Target *activeTarget = 0;
|
||||
if (project) {
|
||||
QList<MimeGlobPattern> globs;
|
||||
foreach (const MimeType &mimeType, MimeDatabase::mimeTypes())
|
||||
if (mimeType.type() == QLatin1String(Constants::QML_MIMETYPE)
|
||||
|| mimeType.subClassesOf().contains(QLatin1String(Constants::QML_MIMETYPE)))
|
||||
globs << mimeType.globPatterns();
|
||||
if (globs.isEmpty()) {
|
||||
globs.append(MimeGlobPattern(QLatin1String("*.qbs")));
|
||||
globs.append(MimeGlobPattern(QLatin1String("*.qml")));
|
||||
globs.append(MimeGlobPattern(QLatin1String("*.qmltypes")));
|
||||
globs.append(MimeGlobPattern(QLatin1String("*.qmlproject")));
|
||||
Utils::MimeDatabase mdb;
|
||||
QList<Utils::MimeType> qmlTypes;
|
||||
foreach (const Utils::MimeType &mimeType, mdb.allMimeTypes()) {
|
||||
if (mimeType.matchesName(QLatin1String(Constants::QML_MIMETYPE))
|
||||
|| mimeType.allAncestors().contains(QLatin1String(Constants::QML_MIMETYPE)))
|
||||
qmlTypes.append(mimeType);
|
||||
}
|
||||
foreach (const QString &filePath,
|
||||
project->files(ProjectExplorer::Project::ExcludeGeneratedFiles))
|
||||
foreach (const MimeGlobPattern &glob, globs)
|
||||
if (glob.matches(filePath))
|
||||
projectInfo.sourceFiles << filePath;
|
||||
project->files(ProjectExplorer::Project::ExcludeGeneratedFiles)) {
|
||||
if (mdb.bestMatch(filePath, qmlTypes).isValid())
|
||||
projectInfo.sourceFiles << filePath;
|
||||
}
|
||||
activeTarget = project->activeTarget();
|
||||
}
|
||||
ProjectExplorer::Kit *activeKit = activeTarget ? activeTarget->kit() :
|
||||
@@ -179,22 +176,23 @@ QHash<QString,QmlJS::Dialect> ModelManager::languageForSuffix() const
|
||||
QHash<QString,QmlJS::Dialect> res = ModelManagerInterface::languageForSuffix();
|
||||
|
||||
if (ICore::instance()) {
|
||||
MimeType jsSourceTy = MimeDatabase::findByType(QLatin1String(Constants::JS_MIMETYPE));
|
||||
Utils::MimeDatabase mdb;
|
||||
Utils::MimeType jsSourceTy = mdb.mimeTypeForName(QLatin1String(Constants::JS_MIMETYPE));
|
||||
foreach (const QString &suffix, jsSourceTy.suffixes())
|
||||
res[suffix] = Dialect::JavaScript;
|
||||
MimeType qmlSourceTy = MimeDatabase::findByType(QLatin1String(Constants::QML_MIMETYPE));
|
||||
Utils::MimeType qmlSourceTy = mdb.mimeTypeForName(QLatin1String(Constants::QML_MIMETYPE));
|
||||
foreach (const QString &suffix, qmlSourceTy.suffixes())
|
||||
res[suffix] = Dialect::Qml;
|
||||
MimeType qbsSourceTy = MimeDatabase::findByType(QLatin1String(Constants::QBS_MIMETYPE));
|
||||
Utils::MimeType qbsSourceTy = mdb.mimeTypeForName(QLatin1String(Constants::QBS_MIMETYPE));
|
||||
foreach (const QString &suffix, qbsSourceTy.suffixes())
|
||||
res[suffix] = Dialect::QmlQbs;
|
||||
MimeType qmlProjectSourceTy = MimeDatabase::findByType(QLatin1String(Constants::QMLPROJECT_MIMETYPE));
|
||||
Utils::MimeType qmlProjectSourceTy = mdb.mimeTypeForName(QLatin1String(Constants::QMLPROJECT_MIMETYPE));
|
||||
foreach (const QString &suffix, qmlProjectSourceTy.suffixes())
|
||||
res[suffix] = Dialect::QmlProject;
|
||||
MimeType qmlUiSourceTy = MimeDatabase::findByType(QLatin1String(Constants::QMLUI_MIMETYPE));
|
||||
Utils::MimeType qmlUiSourceTy = mdb.mimeTypeForName(QLatin1String(Constants::QMLUI_MIMETYPE));
|
||||
foreach (const QString &suffix, qmlUiSourceTy.suffixes())
|
||||
res[suffix] = Dialect::QmlQtQuick2Ui;
|
||||
MimeType jsonSourceTy = MimeDatabase::findByType(QLatin1String(Constants::JSON_MIMETYPE));
|
||||
Utils::MimeType jsonSourceTy = mdb.mimeTypeForName(QLatin1String(Constants::JSON_MIMETYPE));
|
||||
foreach (const QString &suffix, jsonSourceTy.suffixes())
|
||||
res[suffix] = Dialect::Json;
|
||||
}
|
||||
@@ -269,23 +267,6 @@ void ModelManager::updateDefaultProjectInfo()
|
||||
}
|
||||
|
||||
|
||||
// Check whether fileMimeType is the same or extends knownMimeType
|
||||
bool ModelManager::matchesMimeType(const MimeType &fileMimeType, const MimeType &knownMimeType)
|
||||
{
|
||||
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(MimeDatabase::findByType(parentMimeType), knownMimeType))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ModelManager::addTaskInternal(QFuture<void> result, const QString &msg, const char *taskId) const
|
||||
{
|
||||
ProgressManager::addTask(result, msg, taskId);
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
QT_FORWARD_DECLARE_CLASS(QTimer)
|
||||
QT_FORWARD_DECLARE_CLASS(QLocale)
|
||||
|
||||
namespace Core { class MimeType; }
|
||||
namespace Utils { class MimeType; }
|
||||
|
||||
namespace QmlJSTools {
|
||||
namespace Internal {
|
||||
@@ -70,7 +70,6 @@ private slots:
|
||||
void updateDefaultProjectInfo();
|
||||
private:
|
||||
void loadDefaultQmlTypeDescriptions();
|
||||
static bool matchesMimeType(const Core::MimeType &fileMimeType, const Core::MimeType &knownMimeType);
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -42,8 +42,8 @@
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||
#include <coreplugin/mimedatabase.h>
|
||||
#include <coreplugin/progressmanager/progressmanager.h>
|
||||
#include <utils/mimetypes/mimedatabase.h>
|
||||
|
||||
#include <QtPlugin>
|
||||
#include <QMenu>
|
||||
@@ -72,9 +72,9 @@ QmlJSToolsPlugin::~QmlJSToolsPlugin()
|
||||
bool QmlJSToolsPlugin::initialize(const QStringList &arguments, QString *error)
|
||||
{
|
||||
Q_UNUSED(arguments)
|
||||
Q_UNUSED(error)
|
||||
|
||||
if (!MimeDatabase::addMimeTypes(QLatin1String(":/qmljstools/QmlJSTools.mimetypes.xml"), error))
|
||||
return false;
|
||||
Utils::MimeDatabase::addMimeTypes(QLatin1String(":/qmljstools/QmlJSTools.mimetypes.xml"));
|
||||
|
||||
m_settings = new QmlJSToolsSettings(this); // force registration of qmljstools settings
|
||||
|
||||
|
||||
Reference in New Issue
Block a user