| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | /**************************************************************************
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** This file is part of Qt Creator | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2011-01-11 16:28:15 +01:00
										 |  |  | ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2011-04-13 08:42:33 +02:00
										 |  |  | ** Contact: Nokia Corporation (info@qt.nokia.com) | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | ** | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** GNU Lesser General Public License Usage | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2011-04-13 08:42:33 +02:00
										 |  |  | ** This file may be used under the terms of the GNU Lesser General Public | 
					
						
							|  |  |  | ** License version 2.1 as published by the Free Software Foundation and | 
					
						
							|  |  |  | ** appearing in the file LICENSE.LGPL included in the packaging of this file. | 
					
						
							|  |  |  | ** Please review the following information to ensure the GNU Lesser General | 
					
						
							|  |  |  | ** Public License version 2.1 requirements will be met: | 
					
						
							|  |  |  | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2010-12-17 16:01:08 +01:00
										 |  |  | ** In addition, as a special exception, Nokia gives you certain additional | 
					
						
							| 
									
										
										
										
											2011-04-13 08:42:33 +02:00
										 |  |  | ** rights. These rights are described in the Nokia Qt LGPL Exception | 
					
						
							| 
									
										
										
										
											2010-12-17 16:01:08 +01:00
										 |  |  | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2011-04-13 08:42:33 +02:00
										 |  |  | ** Other Usage | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Alternatively, this file may be used in accordance with the terms and | 
					
						
							|  |  |  | ** conditions contained in a signed written agreement between you and Nokia. | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2010-12-17 16:01:08 +01:00
										 |  |  | ** If you have questions regarding the use of this file, please contact | 
					
						
							| 
									
										
										
										
											2011-05-06 15:05:37 +02:00
										 |  |  | ** Nokia at info@qt.nokia.com. | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | ** | 
					
						
							|  |  |  | **************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-15 13:49:00 +01:00
										 |  |  | #include "qmljsmodelmanager.h"
 | 
					
						
							| 
									
										
										
										
											2010-11-11 10:05:05 +01:00
										 |  |  | #include "qmljstoolsconstants.h"
 | 
					
						
							| 
									
										
										
										
											2010-11-10 15:07:53 +01:00
										 |  |  | #include "qmljsplugindumper.h"
 | 
					
						
							| 
									
										
										
										
											2011-08-23 12:02:29 +02:00
										 |  |  | #include "qmljsfindexportedcpptypes.h"
 | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <coreplugin/icore.h>
 | 
					
						
							|  |  |  | #include <coreplugin/editormanager/editormanager.h>
 | 
					
						
							|  |  |  | #include <coreplugin/progressmanager/progressmanager.h>
 | 
					
						
							| 
									
										
										
										
											2010-01-18 12:38:36 +01:00
										 |  |  | #include <coreplugin/mimedatabase.h>
 | 
					
						
							| 
									
										
										
										
											2011-05-30 12:56:24 +02:00
										 |  |  | #include <coreplugin/messagemanager.h>
 | 
					
						
							| 
									
										
										
										
											2010-12-03 10:13:15 +01:00
										 |  |  | #include <cplusplus/ModelManagerInterface.h>
 | 
					
						
							| 
									
										
										
										
											2011-01-06 10:01:45 +01:00
										 |  |  | #include <cplusplus/CppDocument.h>
 | 
					
						
							| 
									
										
										
										
											2011-07-01 13:51:53 +02:00
										 |  |  | #include <qmljs/qmljscontext.h>
 | 
					
						
							| 
									
										
										
										
											2010-04-06 09:52:29 +02:00
										 |  |  | #include <qmljs/qmljsbind.h>
 | 
					
						
							| 
									
										
										
										
											2010-03-18 15:43:33 +01:00
										 |  |  | #include <qmljs/parser/qmldirparser_p.h>
 | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | #include <texteditor/itexteditor.h>
 | 
					
						
							| 
									
										
										
										
											2010-11-11 10:05:05 +01:00
										 |  |  | #include <texteditor/basetexteditor.h>
 | 
					
						
							| 
									
										
										
										
											2010-06-22 12:54:19 +02:00
										 |  |  | #include <projectexplorer/project.h>
 | 
					
						
							| 
									
										
										
										
											2010-09-27 15:51:49 +02:00
										 |  |  | #include <projectexplorer/projectexplorer.h>
 | 
					
						
							| 
									
										
										
										
											2010-11-11 10:05:05 +01:00
										 |  |  | #include <projectexplorer/projectexplorerconstants.h>
 | 
					
						
							| 
									
										
										
										
											2011-06-28 12:01:56 +02:00
										 |  |  | #include <projectexplorer/session.h>
 | 
					
						
							|  |  |  | #include <qtsupport/baseqtversion.h>
 | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-24 12:29:48 +01:00
										 |  |  | #include <QtCore/QDir>
 | 
					
						
							|  |  |  | #include <QtCore/QFile>
 | 
					
						
							|  |  |  | #include <QtCore/QFileInfo>
 | 
					
						
							|  |  |  | #include <QtCore/QLibraryInfo>
 | 
					
						
							|  |  |  | #include <QtCore/QtConcurrentRun>
 | 
					
						
							| 
									
										
										
										
											2010-01-18 12:38:36 +01:00
										 |  |  | #include <qtconcurrent/runextensions.h>
 | 
					
						
							| 
									
										
										
										
											2011-01-24 12:29:48 +01:00
										 |  |  | #include <QtCore/QTextStream>
 | 
					
						
							|  |  |  | #include <QtCore/QCoreApplication>
 | 
					
						
							|  |  |  | #include <QtCore/QTimer>
 | 
					
						
							| 
									
										
										
										
											2009-10-01 16:38:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-24 12:29:48 +01:00
										 |  |  | #include <QtCore/QDebug>
 | 
					
						
							| 
									
										
										
										
											2010-03-01 13:01:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-25 14:18:53 +01:00
										 |  |  | using namespace QmlJS; | 
					
						
							| 
									
										
										
										
											2010-11-11 10:05:05 +01:00
										 |  |  | using namespace QmlJSTools; | 
					
						
							|  |  |  | using namespace QmlJSTools::Internal; | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-16 16:34:33 +01:00
										 |  |  | static QStringList environmentImportPaths(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-09 10:55:11 +02:00
										 |  |  | QmlJS::Document::Language QmlJSTools::languageOfFile(const QString &fileName) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QStringList jsSuffixes("js"); | 
					
						
							|  |  |  |     QStringList qmlSuffixes("qml"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (Core::ICore::instance()) { | 
					
						
							|  |  |  |         Core::MimeDatabase *db = Core::ICore::instance()->mimeDatabase(); | 
					
						
							|  |  |  |         Core::MimeType jsSourceTy = db->findByType(Constants::JS_MIMETYPE); | 
					
						
							|  |  |  |         jsSuffixes = jsSourceTy.suffixes(); | 
					
						
							|  |  |  |         Core::MimeType qmlSourceTy = db->findByType(Constants::QML_MIMETYPE); | 
					
						
							|  |  |  |         qmlSuffixes = qmlSourceTy.suffixes(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const QFileInfo info(fileName); | 
					
						
							|  |  |  |     const QString fileSuffix = info.suffix(); | 
					
						
							|  |  |  |     if (jsSuffixes.contains(fileSuffix)) | 
					
						
							|  |  |  |         return QmlJS::Document::JavaScriptLanguage; | 
					
						
							|  |  |  |     if (qmlSuffixes.contains(fileSuffix)) | 
					
						
							|  |  |  |         return QmlJS::Document::QmlLanguage; | 
					
						
							|  |  |  |     return QmlJS::Document::UnknownLanguage; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QStringList QmlJSTools::qmlAndJsGlobPatterns() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QStringList pattern; | 
					
						
							|  |  |  |     if (Core::ICore::instance()) { | 
					
						
							|  |  |  |         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; | 
					
						
							|  |  |  |         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"; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return pattern; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-15 13:49:00 +01:00
										 |  |  | ModelManager::ModelManager(QObject *parent): | 
					
						
							|  |  |  |         ModelManagerInterface(parent), | 
					
						
							| 
									
										
										
										
											2010-11-10 15:07:53 +01:00
										 |  |  |         m_core(Core::ICore::instance()), | 
					
						
							|  |  |  |         m_pluginDumper(new PluginDumper(this)) | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     m_synchronizer.setCancelOnWait(true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-03 10:13:15 +01:00
										 |  |  |     m_updateCppQmlTypesTimer = new QTimer(this); | 
					
						
							|  |  |  |     m_updateCppQmlTypesTimer->setInterval(1000); | 
					
						
							|  |  |  |     m_updateCppQmlTypesTimer->setSingleShot(true); | 
					
						
							| 
									
										
										
										
											2011-01-06 10:01:45 +01:00
										 |  |  |     connect(m_updateCppQmlTypesTimer, SIGNAL(timeout()), SLOT(startCppQmlTypeUpdate())); | 
					
						
							| 
									
										
										
										
											2010-12-03 10:13:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-18 16:15:23 +01:00
										 |  |  |     qRegisterMetaType<QmlJS::Document::Ptr>("QmlJS::Document::Ptr"); | 
					
						
							| 
									
										
										
										
											2010-03-18 15:43:33 +01:00
										 |  |  |     qRegisterMetaType<QmlJS::LibraryInfo>("QmlJS::LibraryInfo"); | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-01 13:01:05 +01:00
										 |  |  |     loadQmlTypeDescriptions(); | 
					
						
							| 
									
										
										
										
											2010-03-16 16:34:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     m_defaultImportPaths << environmentImportPaths(); | 
					
						
							| 
									
										
										
										
											2010-12-09 09:41:43 +01:00
										 |  |  |     updateImportPaths(); | 
					
						
							| 
									
										
										
										
											2010-03-01 13:01:05 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-03 10:13:15 +01:00
										 |  |  | void ModelManager::delayedInitialization() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     CPlusPlus::CppModelManagerInterface *cppModelManager = | 
					
						
							|  |  |  |             CPlusPlus::CppModelManagerInterface::instance(); | 
					
						
							|  |  |  |     if (cppModelManager) { | 
					
						
							| 
									
										
										
										
											2011-08-23 12:02:29 +02:00
										 |  |  |         // It's important to have a direct connection here so we can prevent
 | 
					
						
							|  |  |  |         // the source and AST of the cpp document being cleaned away.
 | 
					
						
							| 
									
										
										
										
											2010-12-03 10:13:15 +01:00
										 |  |  |         connect(cppModelManager, SIGNAL(documentUpdated(CPlusPlus::Document::Ptr)), | 
					
						
							| 
									
										
										
										
											2011-08-23 12:02:29 +02:00
										 |  |  |                 this, SLOT(maybeQueueCppQmlTypeUpdate(CPlusPlus::Document::Ptr)), Qt::DirectConnection); | 
					
						
							| 
									
										
										
										
											2010-12-03 10:13:15 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-08-26 13:31:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ProjectExplorer::SessionManager *sessionManager = ProjectExplorer::ProjectExplorerPlugin::instance()->session(); | 
					
						
							|  |  |  |     if (sessionManager) { | 
					
						
							|  |  |  |         connect(sessionManager, SIGNAL(projectRemoved(ProjectExplorer::Project*)), | 
					
						
							|  |  |  |                 this, SLOT(removeProjectInfo(ProjectExplorer::Project*))); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-12-03 10:13:15 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-01 13:01:05 +01:00
										 |  |  | void ModelManager::loadQmlTypeDescriptions() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-11-10 16:21:05 +01:00
										 |  |  |     if (Core::ICore::instance()) { | 
					
						
							|  |  |  |         loadQmlTypeDescriptions(Core::ICore::instance()->resourcePath()); | 
					
						
							|  |  |  |         loadQmlTypeDescriptions(Core::ICore::instance()->userResourcePath()); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-09-08 10:11:44 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ModelManager::loadQmlTypeDescriptions(const QString &resourcePath) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-03-01 13:01:05 +01:00
										 |  |  |     const QDir typeFileDir(resourcePath + QLatin1String("/qml-type-descriptions")); | 
					
						
							| 
									
										
										
										
											2011-02-08 13:22:34 +01:00
										 |  |  |     const QStringList qmlTypesExtensions = QStringList() << QLatin1String("*.qmltypes"); | 
					
						
							| 
									
										
										
										
											2011-06-28 12:01:56 +02:00
										 |  |  |     QFileInfoList qmlTypesFiles = typeFileDir.entryInfoList( | 
					
						
							| 
									
										
										
										
											2011-02-08 13:22:34 +01:00
										 |  |  |                 qmlTypesExtensions, | 
					
						
							|  |  |  |                 QDir::Files, | 
					
						
							|  |  |  |                 QDir::Name); | 
					
						
							| 
									
										
										
										
											2010-03-01 13:01:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-30 12:56:24 +02:00
										 |  |  |     QStringList errors; | 
					
						
							|  |  |  |     QStringList warnings; | 
					
						
							| 
									
										
										
										
											2011-06-28 12:01:56 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // filter out the actual Qt builtins
 | 
					
						
							|  |  |  |     for (int i = 0; i < qmlTypesFiles.size(); ++i) { | 
					
						
							|  |  |  |         if (qmlTypesFiles.at(i).baseName() == QLatin1String("builtins")) { | 
					
						
							|  |  |  |             QFileInfoList list; | 
					
						
							|  |  |  |             list.append(qmlTypesFiles.at(i)); | 
					
						
							| 
									
										
										
										
											2011-08-08 12:47:49 +02:00
										 |  |  |             CppQmlTypesLoader::defaultQtObjects = | 
					
						
							|  |  |  |                     CppQmlTypesLoader::loadQmlTypes(list, &errors, &warnings); | 
					
						
							| 
									
										
										
										
											2011-06-28 12:01:56 +02:00
										 |  |  |             qmlTypesFiles.removeAt(i); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // load the fallbacks for libraries
 | 
					
						
							| 
									
										
										
										
											2011-08-08 12:47:49 +02:00
										 |  |  |     CppQmlTypesLoader::defaultLibraryObjects.unite( | 
					
						
							|  |  |  |                 CppQmlTypesLoader::loadQmlTypes(qmlTypesFiles, &errors, &warnings)); | 
					
						
							| 
									
										
										
										
											2011-05-30 12:56:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     Core::MessageManager *messageManager = Core::MessageManager::instance(); | 
					
						
							|  |  |  |     foreach (const QString &error, errors) | 
					
						
							|  |  |  |         messageManager->printToOutputPane(error); | 
					
						
							|  |  |  |     foreach (const QString &warning, warnings) | 
					
						
							|  |  |  |         messageManager->printToOutputPane(warning); | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-24 14:05:34 +02:00
										 |  |  | ModelManagerInterface::WorkingCopy ModelManager::workingCopy() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     WorkingCopy workingCopy; | 
					
						
							| 
									
										
										
										
											2010-11-10 16:21:05 +01:00
										 |  |  |     if (!m_core) | 
					
						
							|  |  |  |         return workingCopy; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-24 14:05:34 +02:00
										 |  |  |     Core::EditorManager *editorManager = m_core->editorManager(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     foreach (Core::IEditor *editor, editorManager->openedEditors()) { | 
					
						
							|  |  |  |         const QString key = editor->file()->fileName(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor*>(editor)) { | 
					
						
							| 
									
										
										
										
											2010-11-11 10:05:05 +01:00
										 |  |  |             if (textEditor->context().contains(ProjectExplorer::Constants::LANG_QMLJS)) { | 
					
						
							| 
									
										
										
										
											2011-02-21 16:02:26 +01:00
										 |  |  |                 if (TextEditor::BaseTextEditorWidget *ed = qobject_cast<TextEditor::BaseTextEditorWidget *>(textEditor->widget())) { | 
					
						
							| 
									
										
										
										
											2010-11-11 10:05:05 +01:00
										 |  |  |                     workingCopy.insert(key, ed->toPlainText(), ed->document()->revision()); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2010-09-24 14:05:34 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return workingCopy; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-30 09:19:56 +02:00
										 |  |  | Snapshot ModelManager::snapshot() const | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-09-04 17:54:38 +02:00
										 |  |  |     QMutexLocker locker(&m_mutex); | 
					
						
							| 
									
										
										
										
											2011-08-30 09:19:56 +02:00
										 |  |  |     return _validSnapshot; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-09-04 17:54:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-30 09:19:56 +02:00
										 |  |  | Snapshot ModelManager::newestSnapshot() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QMutexLocker locker(&m_mutex); | 
					
						
							|  |  |  |     return _newestSnapshot; | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-16 13:08:59 +02:00
										 |  |  | void ModelManager::updateSourceFiles(const QStringList &files, | 
					
						
							|  |  |  |                                      bool emitDocumentOnDiskChanged) | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-04-16 13:08:59 +02:00
										 |  |  |     refreshSourceFiles(files, emitDocumentOnDiskChanged); | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-16 13:08:59 +02:00
										 |  |  | QFuture<void> ModelManager::refreshSourceFiles(const QStringList &sourceFiles, | 
					
						
							|  |  |  |                                                bool emitDocumentOnDiskChanged) | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-09-21 18:27:15 +02:00
										 |  |  |     if (sourceFiles.isEmpty()) { | 
					
						
							|  |  |  |         return QFuture<void>(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-15 13:49:00 +01:00
										 |  |  |     QFuture<void> result = QtConcurrent::run(&ModelManager::parse, | 
					
						
							| 
									
										
										
										
											2010-09-24 14:05:34 +02:00
										 |  |  |                                               workingCopy(), sourceFiles, | 
					
						
							| 
									
										
										
										
											2010-04-16 13:08:59 +02:00
										 |  |  |                                               this, | 
					
						
							|  |  |  |                                               emitDocumentOnDiskChanged); | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-21 18:27:15 +02:00
										 |  |  |     if (m_synchronizer.futures().size() > 10) { | 
					
						
							|  |  |  |         QList<QFuture<void> > futures = m_synchronizer.futures(); | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-21 18:27:15 +02:00
										 |  |  |         m_synchronizer.clearFutures(); | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-19 15:42:14 +02:00
										 |  |  |         foreach (const QFuture<void> &future, futures) { | 
					
						
							| 
									
										
										
										
											2009-09-21 18:27:15 +02:00
										 |  |  |             if (! (future.isFinished() || future.isCanceled())) | 
					
						
							|  |  |  |                 m_synchronizer.addFuture(future); | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-09-21 18:27:15 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-21 18:27:15 +02:00
										 |  |  |     m_synchronizer.addFuture(result); | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-21 18:27:15 +02:00
										 |  |  |     if (sourceFiles.count() > 1) { | 
					
						
							|  |  |  |         m_core->progressManager()->addTask(result, tr("Indexing"), | 
					
						
							| 
									
										
										
										
											2010-11-11 10:05:05 +01:00
										 |  |  |                         Constants::TASK_INDEX); | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-09-21 18:27:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return result; | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-16 12:42:12 +02:00
										 |  |  | void ModelManager::fileChangedOnDisk(const QString &path) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QtConcurrent::run(&ModelManager::parse, | 
					
						
							| 
									
										
										
										
											2010-09-24 14:05:34 +02:00
										 |  |  |                       workingCopy(), QStringList() << path, | 
					
						
							| 
									
										
										
										
											2010-04-16 12:42:12 +02:00
										 |  |  |                       this, true); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-18 13:40:35 +02:00
										 |  |  | void ModelManager::removeFiles(const QStringList &files) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     emit aboutToRemoveFiles(files); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QMutexLocker locker(&m_mutex); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-16 14:11:30 +02:00
										 |  |  |     foreach (const QString &file, files) { | 
					
						
							|  |  |  |         _validSnapshot.remove(file); | 
					
						
							|  |  |  |         _newestSnapshot.remove(file); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-05-18 13:40:35 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-22 12:54:19 +02:00
										 |  |  | QList<ModelManager::ProjectInfo> ModelManager::projectInfos() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QMutexLocker locker(&m_mutex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return m_projects.values(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ModelManager::ProjectInfo ModelManager::projectInfo(ProjectExplorer::Project *project) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QMutexLocker locker(&m_mutex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return m_projects.value(project, ProjectInfo(project)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ModelManager::updateProjectInfo(const ProjectInfo &pinfo) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (! pinfo.isValid()) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-09 14:29:43 +01:00
										 |  |  |     Snapshot snapshot; | 
					
						
							|  |  |  |     ProjectInfo oldInfo; | 
					
						
							| 
									
										
										
										
											2010-06-22 12:54:19 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         QMutexLocker locker(&m_mutex); | 
					
						
							| 
									
										
										
										
											2010-11-09 14:29:43 +01:00
										 |  |  |         oldInfo = m_projects.value(pinfo.project); | 
					
						
							| 
									
										
										
										
											2010-06-22 12:54:19 +02:00
										 |  |  |         m_projects.insert(pinfo.project, pinfo); | 
					
						
							| 
									
										
										
										
											2011-08-16 14:11:30 +02:00
										 |  |  |         snapshot = _validSnapshot; | 
					
						
							| 
									
										
										
										
											2011-06-28 12:01:56 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-11-24 09:30:46 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-28 12:01:56 +02:00
										 |  |  |     if (oldInfo.qmlDumpPath != pinfo.qmlDumpPath | 
					
						
							|  |  |  |             || oldInfo.qmlDumpEnvironment != pinfo.qmlDumpEnvironment) { | 
					
						
							|  |  |  |         m_pluginDumper->scheduleRedumpPlugins(); | 
					
						
							|  |  |  |         m_pluginDumper->scheduleMaybeRedumpBuiltins(pinfo); | 
					
						
							| 
									
										
										
										
											2010-06-22 12:54:19 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-28 12:01:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-22 12:54:19 +02:00
										 |  |  |     updateImportPaths(); | 
					
						
							| 
									
										
										
										
											2010-11-09 14:29:43 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // remove files that are no longer in the project and have been deleted
 | 
					
						
							|  |  |  |     QStringList deletedFiles; | 
					
						
							|  |  |  |     foreach (const QString &oldFile, oldInfo.sourceFiles) { | 
					
						
							|  |  |  |         if (snapshot.document(oldFile) | 
					
						
							|  |  |  |                 && !pinfo.sourceFiles.contains(oldFile) | 
					
						
							|  |  |  |                 && !QFile::exists(oldFile)) { | 
					
						
							|  |  |  |             deletedFiles += oldFile; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     removeFiles(deletedFiles); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // parse any files not yet in the snapshot
 | 
					
						
							|  |  |  |     QStringList newFiles; | 
					
						
							|  |  |  |     foreach (const QString &file, pinfo.sourceFiles) { | 
					
						
							|  |  |  |         if (!snapshot.document(file)) | 
					
						
							|  |  |  |             newFiles += file; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     updateSourceFiles(newFiles, false); | 
					
						
							| 
									
										
										
										
											2011-04-21 11:09:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-28 12:01:56 +02:00
										 |  |  |     // dump builtin types if the shipped definitions are probably outdated
 | 
					
						
							|  |  |  |     if (QtSupport::QtVersionNumber(pinfo.qtVersionString) > QtSupport::QtVersionNumber(4, 7, 3)) | 
					
						
							|  |  |  |         m_pluginDumper->loadBuiltinTypes(pinfo); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-21 11:09:29 +02:00
										 |  |  |     emit projectInfoUpdated(pinfo); | 
					
						
							| 
									
										
										
										
											2010-06-22 12:54:19 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-26 13:31:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | void ModelManager::removeProjectInfo(ProjectExplorer::Project *project) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ProjectInfo info(project); | 
					
						
							|  |  |  |     // update with an empty project info to clear data
 | 
					
						
							|  |  |  |     updateProjectInfo(info); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         QMutexLocker locker(&m_mutex); | 
					
						
							|  |  |  |         m_projects.remove(project); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-16 12:42:12 +02:00
										 |  |  | void ModelManager::emitDocumentChangedOnDisk(Document::Ptr doc) | 
					
						
							|  |  |  | { emit documentChangedOnDisk(doc); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-15 10:06:59 +02:00
										 |  |  | void ModelManager::updateDocument(Document::Ptr doc) | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-10-15 10:06:59 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         QMutexLocker locker(&m_mutex); | 
					
						
							| 
									
										
										
										
											2011-08-16 14:11:30 +02:00
										 |  |  |         _validSnapshot.insert(doc); | 
					
						
							|  |  |  |         _newestSnapshot.insert(doc, true); | 
					
						
							| 
									
										
										
										
											2010-10-15 10:06:59 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     emit documentUpdated(doc); | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-15 10:06:59 +02:00
										 |  |  | void ModelManager::updateLibraryInfo(const QString &path, const LibraryInfo &info) | 
					
						
							| 
									
										
										
										
											2010-03-18 15:43:33 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-10-15 10:06:59 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         QMutexLocker locker(&m_mutex); | 
					
						
							| 
									
										
										
										
											2011-08-16 14:11:30 +02:00
										 |  |  |         _validSnapshot.insertLibraryInfo(path, info); | 
					
						
							|  |  |  |         _newestSnapshot.insertLibraryInfo(path, info); | 
					
						
							| 
									
										
										
										
											2010-10-15 10:06:59 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-05-27 14:51:30 +02:00
										 |  |  |     // only emit if we got new useful information
 | 
					
						
							|  |  |  |     if (info.isValid()) | 
					
						
							|  |  |  |         emit libraryInfoUpdated(path, info); | 
					
						
							| 
									
										
										
										
											2010-03-18 15:43:33 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-06 09:52:29 +02:00
										 |  |  | static QStringList qmlFilesInDirectory(const QString &path) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-09-09 10:55:11 +02:00
										 |  |  |     const QStringList pattern = qmlAndJsGlobPatterns(); | 
					
						
							| 
									
										
										
										
											2010-04-06 09:52:29 +02:00
										 |  |  |     QStringList files; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const QDir dir(path); | 
					
						
							|  |  |  |     foreach (const QFileInfo &fi, dir.entryInfoList(pattern, QDir::Files)) | 
					
						
							|  |  |  |         files += fi.absoluteFilePath(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return files; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void findNewImplicitImports(const Document::Ptr &doc, const Snapshot &snapshot, | 
					
						
							|  |  |  |                             QStringList *importedFiles, QSet<QString> *scannedPaths) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // scan files that could be implicitly imported
 | 
					
						
							|  |  |  |     // it's important we also do this for JS files, otherwise the isEmpty check will fail
 | 
					
						
							|  |  |  |     if (snapshot.documentsInDirectory(doc->path()).isEmpty()) { | 
					
						
							|  |  |  |         if (! scannedPaths->contains(doc->path())) { | 
					
						
							|  |  |  |             *importedFiles += qmlFilesInDirectory(doc->path()); | 
					
						
							|  |  |  |             scannedPaths->insert(doc->path()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void findNewFileImports(const Document::Ptr &doc, const Snapshot &snapshot, | 
					
						
							|  |  |  |                         QStringList *importedFiles, QSet<QString> *scannedPaths) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // scan files and directories that are explicitly imported
 | 
					
						
							| 
									
										
										
										
											2011-08-08 12:47:49 +02:00
										 |  |  |     foreach (const ImportInfo &import, doc->bind()->imports()) { | 
					
						
							| 
									
										
										
										
											2011-09-21 12:42:27 +02:00
										 |  |  |         const QString &importName = import.path(); | 
					
						
							| 
									
										
										
										
											2011-08-08 12:47:49 +02:00
										 |  |  |         if (import.type() == ImportInfo::FileImport) { | 
					
						
							| 
									
										
										
										
											2010-09-16 15:29:37 +02:00
										 |  |  |             if (! snapshot.document(importName)) | 
					
						
							|  |  |  |                 *importedFiles += importName; | 
					
						
							| 
									
										
										
										
											2011-08-08 12:47:49 +02:00
										 |  |  |         } else if (import.type() == ImportInfo::DirectoryImport) { | 
					
						
							| 
									
										
										
										
											2010-09-16 15:29:37 +02:00
										 |  |  |             if (snapshot.documentsInDirectory(importName).isEmpty()) { | 
					
						
							|  |  |  |                 if (! scannedPaths->contains(importName)) { | 
					
						
							|  |  |  |                     *importedFiles += qmlFilesInDirectory(importName); | 
					
						
							|  |  |  |                     scannedPaths->insert(importName); | 
					
						
							| 
									
										
										
										
											2010-09-16 09:40:19 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2010-04-06 09:52:29 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-10 14:49:38 +01:00
										 |  |  | static bool findNewQmlLibraryInPath(const QString &path, | 
					
						
							|  |  |  |                                     const Snapshot &snapshot, | 
					
						
							|  |  |  |                                     ModelManager *modelManager, | 
					
						
							|  |  |  |                                     QStringList *importedFiles, | 
					
						
							|  |  |  |                                     QSet<QString> *scannedPaths, | 
					
						
							|  |  |  |                                     QSet<QString> *newLibraries) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // if we know there is a library, done
 | 
					
						
							| 
									
										
										
										
											2011-05-27 14:51:30 +02:00
										 |  |  |     const LibraryInfo &existingInfo = snapshot.libraryInfo(path); | 
					
						
							|  |  |  |     if (existingInfo.isValid()) | 
					
						
							| 
									
										
										
										
											2011-03-10 14:49:38 +01:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     if (newLibraries->contains(path)) | 
					
						
							|  |  |  |         return true; | 
					
						
							| 
									
										
										
										
											2011-05-27 14:51:30 +02:00
										 |  |  |     // if we looked at the path before, done
 | 
					
						
							|  |  |  |     if (existingInfo.wasScanned()) | 
					
						
							|  |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2011-03-10 14:49:38 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const QDir dir(path); | 
					
						
							|  |  |  |     QFile qmldirFile(dir.filePath(QLatin1String("qmldir"))); | 
					
						
							| 
									
										
										
										
											2011-05-27 14:51:30 +02:00
										 |  |  |     if (!qmldirFile.exists()) { | 
					
						
							|  |  |  |         LibraryInfo libraryInfo(LibraryInfo::NotFound); | 
					
						
							|  |  |  |         modelManager->updateLibraryInfo(path, libraryInfo); | 
					
						
							| 
									
										
										
										
											2011-03-10 14:49:38 +01:00
										 |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2011-05-27 14:51:30 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-03-10 14:49:38 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef Q_OS_WIN
 | 
					
						
							|  |  |  |     // QTCREATORBUG-3402 - be case sensitive even here?
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // found a new library!
 | 
					
						
							|  |  |  |     qmldirFile.open(QFile::ReadOnly); | 
					
						
							|  |  |  |     QString qmldirData = QString::fromUtf8(qmldirFile.readAll()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QmlDirParser qmldirParser; | 
					
						
							|  |  |  |     qmldirParser.setSource(qmldirData); | 
					
						
							|  |  |  |     qmldirParser.parse(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const QString libraryPath = QFileInfo(qmldirFile).absolutePath(); | 
					
						
							|  |  |  |     newLibraries->insert(libraryPath); | 
					
						
							| 
									
										
										
										
											2011-05-27 14:51:30 +02:00
										 |  |  |     modelManager->updateLibraryInfo(libraryPath, LibraryInfo(qmldirParser)); | 
					
						
							| 
									
										
										
										
											2011-03-10 14:49:38 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // scan the qml files in the library
 | 
					
						
							|  |  |  |     foreach (const QmlDirParser::Component &component, qmldirParser.components()) { | 
					
						
							|  |  |  |         if (! component.fileName.isEmpty()) { | 
					
						
							|  |  |  |             const QFileInfo componentFileInfo(dir.filePath(component.fileName)); | 
					
						
							|  |  |  |             const QString path = QDir::cleanPath(componentFileInfo.absolutePath()); | 
					
						
							|  |  |  |             if (! scannedPaths->contains(path)) { | 
					
						
							|  |  |  |                 *importedFiles += qmlFilesInDirectory(path); | 
					
						
							|  |  |  |                 scannedPaths->insert(path); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-27 14:51:30 +02:00
										 |  |  | static void findNewQmlLibrary( | 
					
						
							|  |  |  |     const QString &path, | 
					
						
							|  |  |  |     const LanguageUtils::ComponentVersion &version, | 
					
						
							|  |  |  |     const Snapshot &snapshot, | 
					
						
							|  |  |  |     ModelManager *modelManager, | 
					
						
							|  |  |  |     QStringList *importedFiles, | 
					
						
							|  |  |  |     QSet<QString> *scannedPaths, | 
					
						
							|  |  |  |     QSet<QString> *newLibraries) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QString libraryPath = QString("%1.%2.%3").arg( | 
					
						
							|  |  |  |                 path, | 
					
						
							|  |  |  |                 QString::number(version.majorVersion()), | 
					
						
							|  |  |  |                 QString::number(version.minorVersion())); | 
					
						
							|  |  |  |     findNewQmlLibraryInPath( | 
					
						
							|  |  |  |                 libraryPath, snapshot, modelManager, | 
					
						
							|  |  |  |                 importedFiles, scannedPaths, newLibraries); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     libraryPath = QString("%1.%2").arg( | 
					
						
							|  |  |  |                 path, | 
					
						
							|  |  |  |                 QString::number(version.majorVersion())); | 
					
						
							|  |  |  |     findNewQmlLibraryInPath( | 
					
						
							|  |  |  |                 libraryPath, snapshot, modelManager, | 
					
						
							|  |  |  |                 importedFiles, scannedPaths, newLibraries); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     findNewQmlLibraryInPath( | 
					
						
							|  |  |  |                 path, snapshot, modelManager, | 
					
						
							|  |  |  |                 importedFiles, scannedPaths, newLibraries); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-06 09:52:29 +02:00
										 |  |  | static void findNewLibraryImports(const Document::Ptr &doc, const Snapshot &snapshot, | 
					
						
							|  |  |  |                            ModelManager *modelManager, | 
					
						
							| 
									
										
										
										
											2011-01-12 13:58:24 +01:00
										 |  |  |                            QStringList *importedFiles, QSet<QString> *scannedPaths, QSet<QString> *newLibraries) | 
					
						
							| 
									
										
										
										
											2010-04-06 09:52:29 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-05-27 14:51:30 +02:00
										 |  |  |     // scan current dir
 | 
					
						
							|  |  |  |     findNewQmlLibraryInPath(doc->path(), snapshot, modelManager, | 
					
						
							|  |  |  |                             importedFiles, scannedPaths, newLibraries); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // scan dir and lib imports
 | 
					
						
							| 
									
										
										
										
											2010-04-26 10:40:18 +02:00
										 |  |  |     const QStringList importPaths = modelManager->importPaths(); | 
					
						
							| 
									
										
										
										
											2011-08-08 12:47:49 +02:00
										 |  |  |     foreach (const ImportInfo &import, doc->bind()->imports()) { | 
					
						
							|  |  |  |         if (import.type() == ImportInfo::DirectoryImport) { | 
					
						
							| 
									
										
										
										
											2011-09-21 12:42:27 +02:00
										 |  |  |             const QString targetPath = import.path(); | 
					
						
							| 
									
										
										
										
											2011-05-27 14:51:30 +02:00
										 |  |  |             findNewQmlLibraryInPath(targetPath, snapshot, modelManager, | 
					
						
							|  |  |  |                                     importedFiles, scannedPaths, newLibraries); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-08 12:47:49 +02:00
										 |  |  |         if (import.type() == ImportInfo::LibraryImport) { | 
					
						
							| 
									
										
										
										
											2011-05-27 14:51:30 +02:00
										 |  |  |             if (!import.version().isValid()) | 
					
						
							|  |  |  |                 continue; | 
					
						
							| 
									
										
										
										
											2011-03-10 14:49:38 +01:00
										 |  |  |             foreach (const QString &importPath, importPaths) { | 
					
						
							| 
									
										
										
										
											2011-09-21 12:42:27 +02:00
										 |  |  |                 const QString targetPath = QDir(importPath).filePath(import.path()); | 
					
						
							| 
									
										
										
										
											2011-05-27 14:51:30 +02:00
										 |  |  |                 findNewQmlLibrary(targetPath, import.version(), snapshot, modelManager, | 
					
						
							|  |  |  |                                   importedFiles, scannedPaths, newLibraries); | 
					
						
							| 
									
										
										
										
											2010-04-06 09:52:29 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-15 13:49:00 +01:00
										 |  |  | void ModelManager::parse(QFutureInterface<void> &future, | 
					
						
							| 
									
										
										
										
											2010-09-24 14:05:34 +02:00
										 |  |  |                             WorkingCopy workingCopy, | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  |                             QStringList files, | 
					
						
							| 
									
										
										
										
											2010-04-16 12:42:12 +02:00
										 |  |  |                             ModelManager *modelManager, | 
					
						
							|  |  |  |                             bool emitDocChangedOnDisk) | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-04-06 09:52:29 +02:00
										 |  |  |     int progressRange = files.size(); | 
					
						
							|  |  |  |     future.setProgressRange(0, progressRange); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // paths we have scanned for files and added to the files list
 | 
					
						
							|  |  |  |     QSet<QString> scannedPaths; | 
					
						
							| 
									
										
										
										
											2011-01-12 13:58:24 +01:00
										 |  |  |     // libraries we've found while scanning imports
 | 
					
						
							|  |  |  |     QSet<QString> newLibraries; | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     for (int i = 0; i < files.size(); ++i) { | 
					
						
							| 
									
										
										
										
											2010-04-06 09:52:29 +02:00
										 |  |  |         future.setProgressValue(qreal(i) / files.size() * progressRange); | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         const QString fileName = files.at(i); | 
					
						
							| 
									
										
										
										
											2010-02-15 14:07:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-09 10:55:11 +02:00
										 |  |  |         Document::Language language = languageOfFile(fileName); | 
					
						
							|  |  |  |         if (language == Document::UnknownLanguage) | 
					
						
							|  |  |  |             continue; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  |         QString contents; | 
					
						
							| 
									
										
										
										
											2010-01-25 14:18:53 +01:00
										 |  |  |         int documentRevision = 0; | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (workingCopy.contains(fileName)) { | 
					
						
							| 
									
										
										
										
											2010-09-24 14:05:34 +02:00
										 |  |  |             QPair<QString, int> entry = workingCopy.get(fileName); | 
					
						
							|  |  |  |             contents = entry.first; | 
					
						
							|  |  |  |             documentRevision = entry.second; | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             QFile inFile(fileName); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (inFile.open(QIODevice::ReadOnly)) { | 
					
						
							|  |  |  |                 QTextStream ins(&inFile); | 
					
						
							|  |  |  |                 contents = ins.readAll(); | 
					
						
							|  |  |  |                 inFile.close(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-09 10:55:11 +02:00
										 |  |  |         Document::Ptr doc = Document::create(fileName, language); | 
					
						
							| 
									
										
										
										
											2010-07-07 17:52:02 +02:00
										 |  |  |         doc->setEditorRevision(documentRevision); | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  |         doc->setSource(contents); | 
					
						
							| 
									
										
										
										
											2010-04-06 09:52:29 +02:00
										 |  |  |         doc->parse(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-27 14:51:30 +02:00
										 |  |  |         // update snapshot. requires synchronization, but significantly reduces amount of file
 | 
					
						
							|  |  |  |         // system queries for library imports because queries are cached in libraryInfo
 | 
					
						
							|  |  |  |         const Snapshot snapshot = modelManager->snapshot(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-06 09:52:29 +02:00
										 |  |  |         // get list of referenced files not yet in snapshot or in directories already scanned
 | 
					
						
							|  |  |  |         QStringList importedFiles; | 
					
						
							|  |  |  |         findNewImplicitImports(doc, snapshot, &importedFiles, &scannedPaths); | 
					
						
							|  |  |  |         findNewFileImports(doc, snapshot, &importedFiles, &scannedPaths); | 
					
						
							| 
									
										
										
										
											2011-01-12 13:58:24 +01:00
										 |  |  |         findNewLibraryImports(doc, snapshot, modelManager, &importedFiles, &scannedPaths, &newLibraries); | 
					
						
							| 
									
										
										
										
											2010-04-06 09:52:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // add new files to parse list
 | 
					
						
							|  |  |  |         foreach (const QString &file, importedFiles) { | 
					
						
							|  |  |  |             if (! files.contains(file)) | 
					
						
							|  |  |  |                 files.append(file); | 
					
						
							| 
									
										
										
										
											2010-03-18 15:43:33 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-15 10:06:59 +02:00
										 |  |  |         modelManager->updateDocument(doc); | 
					
						
							| 
									
										
										
										
											2010-04-16 12:42:12 +02:00
										 |  |  |         if (emitDocChangedOnDisk) | 
					
						
							|  |  |  |             modelManager->emitDocumentChangedOnDisk(doc); | 
					
						
							| 
									
										
										
										
											2010-03-16 16:34:33 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-06 09:52:29 +02:00
										 |  |  |     future.setProgressValue(progressRange); | 
					
						
							| 
									
										
										
										
											2010-03-16 16:34:33 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-20 16:43:50 +01:00
										 |  |  | // Check whether fileMimeType is the same or extends knownMimeType
 | 
					
						
							| 
									
										
										
										
											2010-02-15 13:49:00 +01:00
										 |  |  | bool ModelManager::matchesMimeType(const Core::MimeType &fileMimeType, const Core::MimeType &knownMimeType) | 
					
						
							| 
									
										
										
										
											2010-01-20 16:43:50 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     Core::MimeDatabase *db = Core::ICore::instance()->mimeDatabase(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const QStringList knownTypeNames = QStringList(knownMimeType.type()) + knownMimeType.aliases(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-19 15:42:14 +02:00
										 |  |  |     foreach (const QString &knownTypeName, knownTypeNames) | 
					
						
							| 
									
										
										
										
											2010-01-20 16:43:50 +01:00
										 |  |  |         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; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-03-16 16:34:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | QStringList ModelManager::importPaths() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-06-22 12:54:19 +02:00
										 |  |  |     return m_allImportPaths; | 
					
						
							| 
									
										
										
										
											2010-03-16 16:34:33 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static QStringList environmentImportPaths() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QStringList paths; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QByteArray envImportPath = qgetenv("QML_IMPORT_PATH"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if defined(Q_OS_WIN)
 | 
					
						
							|  |  |  |     QLatin1Char pathSep(';'); | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  |     QLatin1Char pathSep(':'); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |     foreach (const QString &path, QString::fromLatin1(envImportPath).split(pathSep, QString::SkipEmptyParts)) { | 
					
						
							|  |  |  |         QString canonicalPath = QDir(path).canonicalPath(); | 
					
						
							|  |  |  |         if (!canonicalPath.isEmpty() && !paths.contains(canonicalPath)) | 
					
						
							|  |  |  |             paths.append(canonicalPath); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return paths; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-06-09 14:27:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-22 12:54:19 +02:00
										 |  |  | void ModelManager::updateImportPaths() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-09-08 16:52:24 +02:00
										 |  |  |     m_allImportPaths.clear(); | 
					
						
							| 
									
										
										
										
											2010-06-22 12:54:19 +02:00
										 |  |  |     QMapIterator<ProjectExplorer::Project *, ProjectInfo> it(m_projects); | 
					
						
							|  |  |  |     while (it.hasNext()) { | 
					
						
							|  |  |  |         it.next(); | 
					
						
							| 
									
										
										
										
											2011-01-20 11:03:23 +01:00
										 |  |  |         foreach (const QString &path, it.value().importPaths) { | 
					
						
							|  |  |  |             const QString canonicalPath = QFileInfo(path).canonicalFilePath(); | 
					
						
							|  |  |  |             if (!canonicalPath.isEmpty()) | 
					
						
							|  |  |  |                 m_allImportPaths += canonicalPath; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-06-22 12:54:19 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     m_allImportPaths += m_defaultImportPaths; | 
					
						
							| 
									
										
										
										
											2010-09-08 16:52:24 +02:00
										 |  |  |     m_allImportPaths.removeDuplicates(); | 
					
						
							| 
									
										
										
										
											2010-06-22 12:54:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // check if any file in the snapshot imports something new in the new paths
 | 
					
						
							| 
									
										
										
										
											2011-08-16 14:11:30 +02:00
										 |  |  |     Snapshot snapshot = _validSnapshot; | 
					
						
							| 
									
										
										
										
											2010-06-22 12:54:19 +02:00
										 |  |  |     QStringList importedFiles; | 
					
						
							|  |  |  |     QSet<QString> scannedPaths; | 
					
						
							| 
									
										
										
										
											2011-01-12 13:58:24 +01:00
										 |  |  |     QSet<QString> newLibraries; | 
					
						
							| 
									
										
										
										
											2010-06-22 12:54:19 +02:00
										 |  |  |     foreach (const Document::Ptr &doc, snapshot) | 
					
						
							| 
									
										
										
										
											2011-01-12 13:58:24 +01:00
										 |  |  |         findNewLibraryImports(doc, snapshot, this, &importedFiles, &scannedPaths, &newLibraries); | 
					
						
							| 
									
										
										
										
											2010-06-22 12:54:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     updateSourceFiles(importedFiles, true); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-08 13:29:21 +01:00
										 |  |  | void ModelManager::loadPluginTypes(const QString &libraryPath, const QString &importPath, | 
					
						
							|  |  |  |                                    const QString &importUri, const QString &importVersion) | 
					
						
							| 
									
										
										
										
											2010-09-15 14:13:33 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-08 13:29:21 +01:00
										 |  |  |     m_pluginDumper->loadPluginTypes(libraryPath, importPath, importUri, importVersion); | 
					
						
							| 
									
										
										
										
											2010-09-15 14:13:33 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-12-03 10:13:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-23 12:02:29 +02:00
										 |  |  | // is called *inside a c++ parsing thread*, to allow hanging on to source and ast
 | 
					
						
							|  |  |  | void ModelManager::maybeQueueCppQmlTypeUpdate(const CPlusPlus::Document::Ptr &doc) | 
					
						
							| 
									
										
										
										
											2011-01-06 10:01:45 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-08-24 10:55:48 +02:00
										 |  |  |     // avoid scanning documents without source code available
 | 
					
						
							|  |  |  |     doc->keepSourceAndAST(); | 
					
						
							|  |  |  |     if (doc->source().isEmpty()) { | 
					
						
							|  |  |  |         doc->releaseSourceAndAST(); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-23 12:02:29 +02:00
										 |  |  |     // keep source and AST alive if we want to scan for register calls
 | 
					
						
							|  |  |  |     const bool scan = FindExportedCppTypes::maybeExportsTypes(doc); | 
					
						
							| 
									
										
										
										
											2011-08-24 10:55:48 +02:00
										 |  |  |     if (!scan) | 
					
						
							|  |  |  |         doc->releaseSourceAndAST(); | 
					
						
							| 
									
										
										
										
											2011-08-23 12:02:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // delegate actual queuing to the gui thread
 | 
					
						
							|  |  |  |     QMetaObject::invokeMethod(this, "queueCppQmlTypeUpdate", | 
					
						
							|  |  |  |                               Q_ARG(CPlusPlus::Document::Ptr, doc), Q_ARG(bool, scan)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ModelManager::queueCppQmlTypeUpdate(const CPlusPlus::Document::Ptr &doc, bool scan) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QPair<CPlusPlus::Document::Ptr, bool> prev = m_queuedCppDocuments.value(doc->fileName()); | 
					
						
							|  |  |  |     if (prev.first && prev.second) | 
					
						
							|  |  |  |         prev.first->releaseSourceAndAST(); | 
					
						
							|  |  |  |     m_queuedCppDocuments.insert(doc->fileName(), qMakePair(doc, scan)); | 
					
						
							| 
									
										
										
										
											2011-01-06 10:01:45 +01:00
										 |  |  |     m_updateCppQmlTypesTimer->start(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ModelManager::startCppQmlTypeUpdate() | 
					
						
							| 
									
										
										
										
											2010-12-03 10:13:15 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     CPlusPlus::CppModelManagerInterface *cppModelManager = | 
					
						
							|  |  |  |             CPlusPlus::CppModelManagerInterface::instance(); | 
					
						
							|  |  |  |     if (!cppModelManager) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-06 10:01:45 +01:00
										 |  |  |     QtConcurrent::run(&ModelManager::updateCppQmlTypes, | 
					
						
							|  |  |  |                       this, cppModelManager, m_queuedCppDocuments); | 
					
						
							|  |  |  |     m_queuedCppDocuments.clear(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-23 12:02:29 +02:00
										 |  |  | void ModelManager::updateCppQmlTypes(ModelManager *qmlModelManager, | 
					
						
							|  |  |  |                                      CPlusPlus::CppModelManagerInterface *cppModelManager, | 
					
						
							| 
									
										
										
										
											2011-09-16 10:35:48 +02:00
										 |  |  |                                      QHash<QString, QPair<CPlusPlus::Document::Ptr, bool> > documents) | 
					
						
							| 
									
										
										
										
											2011-01-06 10:01:45 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-08-25 12:35:55 +02:00
										 |  |  |     CppDataHash newData = qmlModelManager->cppData(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-06 10:01:45 +01:00
										 |  |  |     CPlusPlus::Snapshot snapshot = cppModelManager->snapshot(); | 
					
						
							| 
									
										
										
										
											2011-08-23 12:02:29 +02:00
										 |  |  |     FindExportedCppTypes finder(snapshot); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     typedef QPair<CPlusPlus::Document::Ptr, bool> DocScanPair; | 
					
						
							|  |  |  |     foreach (const DocScanPair &pair, documents) { | 
					
						
							|  |  |  |         CPlusPlus::Document::Ptr doc = pair.first; | 
					
						
							|  |  |  |         const bool scan = pair.second; | 
					
						
							|  |  |  |         const QString fileName = doc->fileName(); | 
					
						
							|  |  |  |         if (!scan) { | 
					
						
							| 
									
										
										
										
											2011-08-25 12:35:55 +02:00
										 |  |  |             newData.remove(fileName); | 
					
						
							| 
									
										
										
										
											2011-08-23 12:02:29 +02:00
										 |  |  |             continue; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-25 12:35:55 +02:00
										 |  |  |         finder(doc); | 
					
						
							| 
									
										
										
										
											2011-01-06 10:01:45 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-25 12:35:55 +02:00
										 |  |  |         QList<LanguageUtils::FakeMetaObject::ConstPtr> exported = finder.exportedTypes(); | 
					
						
							| 
									
										
										
										
											2011-09-16 10:35:48 +02:00
										 |  |  |         QHash<QString, QString> contextProperties = finder.contextProperties(); | 
					
						
							| 
									
										
										
										
											2011-08-25 12:35:55 +02:00
										 |  |  |         if (exported.isEmpty() && contextProperties.isEmpty()) { | 
					
						
							|  |  |  |             newData.remove(fileName); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             CppData &data = newData[fileName]; | 
					
						
							|  |  |  |             data.exportedTypes = exported; | 
					
						
							|  |  |  |             data.contextProperties = contextProperties; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-08-23 12:02:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         doc->releaseSourceAndAST(); | 
					
						
							| 
									
										
										
										
											2011-01-06 10:01:45 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-25 12:35:55 +02:00
										 |  |  |     QMutexLocker locker(&qmlModelManager->m_cppDataMutex); | 
					
						
							|  |  |  |     qmlModelManager->m_cppDataHash = newData; | 
					
						
							| 
									
										
										
										
											2011-01-06 10:01:45 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-25 12:35:55 +02:00
										 |  |  | ModelManager::CppDataHash ModelManager::cppData() const | 
					
						
							| 
									
										
										
										
											2011-01-06 10:01:45 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-08-25 12:35:55 +02:00
										 |  |  |     QMutexLocker locker(&m_cppDataMutex); | 
					
						
							|  |  |  |     return m_cppDataHash; | 
					
						
							| 
									
										
										
										
											2010-12-03 10:13:15 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-04-12 09:14:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-28 12:01:56 +02:00
										 |  |  | LibraryInfo ModelManager::builtins(const Document::Ptr &doc) const | 
					
						
							| 
									
										
										
										
											2011-04-12 09:14:31 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-28 12:01:56 +02:00
										 |  |  |     ProjectExplorer::SessionManager *sessionManager = ProjectExplorer::ProjectExplorerPlugin::instance()->session(); | 
					
						
							|  |  |  |     if (!sessionManager) | 
					
						
							|  |  |  |         return LibraryInfo(); | 
					
						
							|  |  |  |     ProjectExplorer::Project *project = sessionManager->projectForFile(doc->fileName()); | 
					
						
							|  |  |  |     if (!project) | 
					
						
							|  |  |  |         return LibraryInfo(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QMutexLocker locker(&m_mutex); | 
					
						
							|  |  |  |     ProjectInfo info = m_projects.value(project); | 
					
						
							|  |  |  |     if (!info.isValid()) | 
					
						
							|  |  |  |         return LibraryInfo(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-16 14:11:30 +02:00
										 |  |  |     return _validSnapshot.libraryInfo(info.qtImportsPath); | 
					
						
							| 
									
										
										
										
											2011-04-12 09:14:31 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-06-23 15:12:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-12 11:11:26 +02:00
										 |  |  | void ModelManager::joinAllThreads() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     foreach (QFuture<void> future, m_synchronizer.futures()) | 
					
						
							|  |  |  |         future.waitForFinished(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-23 15:12:03 +02:00
										 |  |  | void ModelManager::resetCodeModel() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QStringList documents; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         QMutexLocker locker(&m_mutex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // find all documents currently in the code model
 | 
					
						
							| 
									
										
										
										
											2011-08-16 14:11:30 +02:00
										 |  |  |         foreach (Document::Ptr doc, _validSnapshot) | 
					
						
							| 
									
										
										
										
											2011-06-23 15:12:03 +02:00
										 |  |  |             documents.append(doc->fileName()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // reset the snapshot
 | 
					
						
							| 
									
										
										
										
											2011-08-16 14:11:30 +02:00
										 |  |  |         _validSnapshot = Snapshot(); | 
					
						
							|  |  |  |         _newestSnapshot = Snapshot(); | 
					
						
							| 
									
										
										
										
											2011-06-23 15:12:03 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // start a reparse thread
 | 
					
						
							|  |  |  |     updateSourceFiles(documents, false); | 
					
						
							|  |  |  | } |