forked from qt-creator/qt-creator
Getting the QmlJsModelManager working stand alone
Getting the QmlJsModelManager working stand alone for auto testing Reviewed-by: Christian Kamm
This commit is contained in:
committed by
Christian Kamm
parent
fda2124fbf
commit
e9fd078e45
@@ -79,8 +79,10 @@ ModelManager::ModelManager(QObject *parent):
|
|||||||
|
|
||||||
void ModelManager::loadQmlTypeDescriptions()
|
void ModelManager::loadQmlTypeDescriptions()
|
||||||
{
|
{
|
||||||
loadQmlTypeDescriptions(Core::ICore::instance()->resourcePath());
|
if (Core::ICore::instance()) {
|
||||||
loadQmlTypeDescriptions(Core::ICore::instance()->userResourcePath());
|
loadQmlTypeDescriptions(Core::ICore::instance()->resourcePath());
|
||||||
|
loadQmlTypeDescriptions(Core::ICore::instance()->userResourcePath());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelManager::loadQmlTypeDescriptions(const QString &resourcePath)
|
void ModelManager::loadQmlTypeDescriptions(const QString &resourcePath)
|
||||||
@@ -104,6 +106,9 @@ void ModelManager::loadQmlTypeDescriptions(const QString &resourcePath)
|
|||||||
ModelManagerInterface::WorkingCopy ModelManager::workingCopy() const
|
ModelManagerInterface::WorkingCopy ModelManager::workingCopy() const
|
||||||
{
|
{
|
||||||
WorkingCopy workingCopy;
|
WorkingCopy workingCopy;
|
||||||
|
if (!m_core)
|
||||||
|
return workingCopy;
|
||||||
|
|
||||||
Core::EditorManager *editorManager = m_core->editorManager();
|
Core::EditorManager *editorManager = m_core->editorManager();
|
||||||
|
|
||||||
foreach (Core::IEditor *editor, editorManager->openedEditors()) {
|
foreach (Core::IEditor *editor, editorManager->openedEditors()) {
|
||||||
@@ -257,16 +262,21 @@ void ModelManager::updateLibraryInfo(const QString &path, const LibraryInfo &inf
|
|||||||
|
|
||||||
static QStringList qmlFilesInDirectory(const QString &path)
|
static QStringList qmlFilesInDirectory(const QString &path)
|
||||||
{
|
{
|
||||||
// ### It would suffice to build pattern once. This function needs to be thread-safe.
|
|
||||||
Core::MimeDatabase *db = Core::ICore::instance()->mimeDatabase();
|
|
||||||
Core::MimeType jsSourceTy = db->findByType(Constants::JS_MIMETYPE);
|
|
||||||
Core::MimeType qmlSourceTy = db->findByType(Constants::QML_MIMETYPE);
|
|
||||||
|
|
||||||
QStringList pattern;
|
QStringList pattern;
|
||||||
foreach (const Core::MimeGlobPattern &glob, jsSourceTy.globPatterns())
|
if (Core::ICore::instance()) {
|
||||||
pattern << glob.regExp().pattern();
|
// ### It would suffice to build pattern once. This function needs to be thread-safe.
|
||||||
foreach (const Core::MimeGlobPattern &glob, qmlSourceTy.globPatterns())
|
Core::MimeDatabase *db = Core::ICore::instance()->mimeDatabase();
|
||||||
pattern << glob.regExp().pattern();
|
Core::MimeType jsSourceTy = db->findByType(Constants::JS_MIMETYPE);
|
||||||
|
Core::MimeType qmlSourceTy = db->findByType(Constants::QML_MIMETYPE);
|
||||||
|
|
||||||
|
QStringList pattern;
|
||||||
|
foreach (const Core::MimeGlobPattern &glob, jsSourceTy.globPatterns())
|
||||||
|
pattern << glob.regExp().pattern();
|
||||||
|
foreach (const Core::MimeGlobPattern &glob, qmlSourceTy.globPatterns())
|
||||||
|
pattern << glob.regExp().pattern();
|
||||||
|
} else {
|
||||||
|
pattern << "*.qml" << "*.js";
|
||||||
|
}
|
||||||
|
|
||||||
QStringList files;
|
QStringList files;
|
||||||
|
|
||||||
@@ -363,9 +373,14 @@ void ModelManager::parse(QFutureInterface<void> &future,
|
|||||||
ModelManager *modelManager,
|
ModelManager *modelManager,
|
||||||
bool emitDocChangedOnDisk)
|
bool emitDocChangedOnDisk)
|
||||||
{
|
{
|
||||||
Core::MimeDatabase *db = Core::ICore::instance()->mimeDatabase();
|
Core::MimeDatabase *db = 0;
|
||||||
Core::MimeType jsSourceTy = db->findByType(QLatin1String("application/javascript"));
|
Core::MimeType jsSourceTy;
|
||||||
Core::MimeType qmlSourceTy = db->findByType(QLatin1String("application/x-qml"));
|
Core::MimeType qmlSourceTy;
|
||||||
|
if (Core::ICore::instance()) {
|
||||||
|
db = Core::ICore::instance()->mimeDatabase();
|
||||||
|
jsSourceTy = db->findByType(QLatin1String("application/javascript"));
|
||||||
|
qmlSourceTy = db->findByType(QLatin1String("application/x-qml"));
|
||||||
|
}
|
||||||
|
|
||||||
int progressRange = files.size();
|
int progressRange = files.size();
|
||||||
future.setProgressRange(0, progressRange);
|
future.setProgressRange(0, progressRange);
|
||||||
@@ -381,15 +396,24 @@ void ModelManager::parse(QFutureInterface<void> &future,
|
|||||||
const QString fileName = files.at(i);
|
const QString fileName = files.at(i);
|
||||||
|
|
||||||
const QFileInfo fileInfo(fileName);
|
const QFileInfo fileInfo(fileName);
|
||||||
Core::MimeType fileMimeTy = db->findByFile(fileInfo);
|
Core::MimeType fileMimeTy;
|
||||||
|
|
||||||
bool isQmlFile = true;
|
bool isQmlFile = true;
|
||||||
|
|
||||||
if (matchesMimeType(fileMimeTy, jsSourceTy))
|
if (db) {
|
||||||
isQmlFile = false;
|
fileMimeTy = db->findByFile(fileInfo);
|
||||||
|
|
||||||
else if (! matchesMimeType(fileMimeTy, qmlSourceTy))
|
if (matchesMimeType(fileMimeTy, jsSourceTy))
|
||||||
continue; // skip it. it's not a QML or a JS file.
|
isQmlFile = false;
|
||||||
|
|
||||||
|
else if (! matchesMimeType(fileMimeTy, qmlSourceTy))
|
||||||
|
continue; // skip it. it's not a QML or a JS file.
|
||||||
|
} else {
|
||||||
|
if (fileName.contains(QLatin1String(".js"), Qt::CaseInsensitive))
|
||||||
|
isQmlFile = false;
|
||||||
|
else if (!fileName.contains(QLatin1String(".qml"), Qt::CaseInsensitive))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
QString contents;
|
QString contents;
|
||||||
int documentRevision = 0;
|
int documentRevision = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user