forked from qt-creator/qt-creator
QmlJSTools: De-noise QmlJSModelManager
Change-Id: Iede105188819b1f07efac76ec9a9b05a6ae6049a Reviewed-by: hjk <hjk@theqtcompany.com>
This commit is contained in:
@@ -66,34 +66,34 @@
|
|||||||
#include <QLibraryInfo>
|
#include <QLibraryInfo>
|
||||||
#include <qglobal.h>
|
#include <qglobal.h>
|
||||||
|
|
||||||
|
using namespace Utils;
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
|
using namespace ProjectExplorer;
|
||||||
using namespace QmlJS;
|
using namespace QmlJS;
|
||||||
using namespace QmlJSTools;
|
|
||||||
using namespace QmlJSTools::Internal;
|
|
||||||
|
|
||||||
|
namespace QmlJSTools {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
ModelManagerInterface::ProjectInfo ModelManager::defaultProjectInfoForProject(
|
ModelManagerInterface::ProjectInfo ModelManager::defaultProjectInfoForProject(
|
||||||
ProjectExplorer::Project *project) const
|
Project *project) const
|
||||||
{
|
{
|
||||||
ModelManagerInterface::ProjectInfo projectInfo(project);
|
ModelManagerInterface::ProjectInfo projectInfo(project);
|
||||||
ProjectExplorer::Target *activeTarget = 0;
|
Target *activeTarget = 0;
|
||||||
if (project) {
|
if (project) {
|
||||||
Utils::MimeDatabase mdb;
|
MimeDatabase mdb;
|
||||||
QList<Utils::MimeType> qmlTypes;
|
QList<MimeType> qmlTypes;
|
||||||
foreach (const Utils::MimeType &mimeType, mdb.allMimeTypes()) {
|
foreach (const MimeType &mimeType, mdb.allMimeTypes()) {
|
||||||
if (mimeType.matchesName(QLatin1String(Constants::QML_MIMETYPE))
|
if (mimeType.matchesName(QLatin1String(Constants::QML_MIMETYPE))
|
||||||
|| mimeType.allAncestors().contains(QLatin1String(Constants::QML_MIMETYPE)))
|
|| mimeType.allAncestors().contains(QLatin1String(Constants::QML_MIMETYPE)))
|
||||||
qmlTypes.append(mimeType);
|
qmlTypes.append(mimeType);
|
||||||
}
|
}
|
||||||
foreach (const QString &filePath,
|
foreach (const QString &filePath, project->files(Project::ExcludeGeneratedFiles)) {
|
||||||
project->files(ProjectExplorer::Project::ExcludeGeneratedFiles)) {
|
|
||||||
if (mdb.bestMatch(filePath, qmlTypes).isValid())
|
if (mdb.bestMatch(filePath, qmlTypes).isValid())
|
||||||
projectInfo.sourceFiles << filePath;
|
projectInfo.sourceFiles << filePath;
|
||||||
}
|
}
|
||||||
activeTarget = project->activeTarget();
|
activeTarget = project->activeTarget();
|
||||||
}
|
}
|
||||||
ProjectExplorer::Kit *activeKit = activeTarget ? activeTarget->kit() :
|
Kit *activeKit = activeTarget ? activeTarget->kit() : KitManager::defaultKit();
|
||||||
ProjectExplorer::KitManager::defaultKit();
|
|
||||||
QtSupport::BaseQtVersion *qtVersion = QtSupport::QtKitInformation::qtVersion(activeKit);
|
QtSupport::BaseQtVersion *qtVersion = QtSupport::QtKitInformation::qtVersion(activeKit);
|
||||||
|
|
||||||
bool preferDebugDump = false;
|
bool preferDebugDump = false;
|
||||||
@@ -101,8 +101,8 @@ ModelManagerInterface::ProjectInfo ModelManager::defaultProjectInfoForProject(
|
|||||||
projectInfo.tryQmlDump = false;
|
projectInfo.tryQmlDump = false;
|
||||||
|
|
||||||
if (activeTarget) {
|
if (activeTarget) {
|
||||||
if (ProjectExplorer::BuildConfiguration *bc = activeTarget->activeBuildConfiguration()) {
|
if (BuildConfiguration *bc = activeTarget->activeBuildConfiguration()) {
|
||||||
preferDebugDump = bc->buildType() == ProjectExplorer::BuildConfiguration::Debug;
|
preferDebugDump = bc->buildType() == BuildConfiguration::Debug;
|
||||||
setPreferDump = true;
|
setPreferDump = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -122,8 +122,7 @@ ModelManagerInterface::ProjectInfo ModelManager::defaultProjectInfoForProject(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (projectInfo.tryQmlDump) {
|
if (projectInfo.tryQmlDump) {
|
||||||
ProjectExplorer::ToolChain *toolChain =
|
ToolChain *toolChain = ToolChainKitInformation::toolChain(activeKit);
|
||||||
ProjectExplorer::ToolChainKitInformation::toolChain(activeKit);
|
|
||||||
QtSupport::QmlDumpTool::pathAndEnvironment(project, qtVersion,
|
QtSupport::QmlDumpTool::pathAndEnvironment(project, qtVersion,
|
||||||
toolChain,
|
toolChain,
|
||||||
preferDebugDump, &projectInfo.qmlDumpPath,
|
preferDebugDump, &projectInfo.qmlDumpPath,
|
||||||
@@ -138,13 +137,14 @@ ModelManagerInterface::ProjectInfo ModelManager::defaultProjectInfoForProject(
|
|||||||
return projectInfo;
|
return projectInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlJSTools::setupProjectInfoQmlBundles(ModelManagerInterface::ProjectInfo &projectInfo)
|
} // namespace Internal
|
||||||
|
|
||||||
|
void setupProjectInfoQmlBundles(ModelManagerInterface::ProjectInfo &projectInfo)
|
||||||
{
|
{
|
||||||
ProjectExplorer::Target *activeTarget = 0;
|
Target *activeTarget = 0;
|
||||||
if (projectInfo.project)
|
if (projectInfo.project)
|
||||||
activeTarget = projectInfo.project->activeTarget();
|
activeTarget = projectInfo.project->activeTarget();
|
||||||
ProjectExplorer::Kit *activeKit = activeTarget
|
Kit *activeKit = activeTarget ? activeTarget->kit() : KitManager::defaultKit();
|
||||||
? activeTarget->kit() : ProjectExplorer::KitManager::defaultKit();
|
|
||||||
QHash<QString, QString> replacements;
|
QHash<QString, QString> replacements;
|
||||||
replacements.insert(QLatin1String("$(QT_INSTALL_IMPORTS)"), projectInfo.qtImportsPath);
|
replacements.insert(QLatin1String("$(QT_INSTALL_IMPORTS)"), projectInfo.qtImportsPath);
|
||||||
replacements.insert(QLatin1String("$(QT_INSTALL_QML)"), projectInfo.qtQmlPath);
|
replacements.insert(QLatin1String("$(QT_INSTALL_QML)"), projectInfo.qtQmlPath);
|
||||||
@@ -159,12 +159,12 @@ void QmlJSTools::setupProjectInfoQmlBundles(ModelManagerInterface::ProjectInfo &
|
|||||||
projectInfo.extendedBundle = projectInfo.activeBundle;
|
projectInfo.extendedBundle = projectInfo.activeBundle;
|
||||||
|
|
||||||
if (projectInfo.project) {
|
if (projectInfo.project) {
|
||||||
QSet<ProjectExplorer::Kit *> currentKits;
|
QSet<Kit *> currentKits;
|
||||||
foreach (const ProjectExplorer::Target *t, projectInfo.project->targets())
|
foreach (const Target *t, projectInfo.project->targets())
|
||||||
if (t->kit())
|
if (t->kit())
|
||||||
currentKits.insert(t->kit());
|
currentKits.insert(t->kit());
|
||||||
currentKits.remove(activeKit);
|
currentKits.remove(activeKit);
|
||||||
foreach (ProjectExplorer::Kit *kit, currentKits) {
|
foreach (Kit *kit, currentKits) {
|
||||||
foreach (IBundleProvider *bp, bundleProviders)
|
foreach (IBundleProvider *bp, bundleProviders)
|
||||||
if (bp)
|
if (bp)
|
||||||
bp->mergeBundlesForKit(kit, projectInfo.extendedBundle, replacements);
|
bp->mergeBundlesForKit(kit, projectInfo.extendedBundle, replacements);
|
||||||
@@ -172,28 +172,30 @@ void QmlJSTools::setupProjectInfoQmlBundles(ModelManagerInterface::ProjectInfo &
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
QHash<QString,Dialect> ModelManager::languageForSuffix() const
|
QHash<QString,Dialect> ModelManager::languageForSuffix() const
|
||||||
{
|
{
|
||||||
QHash<QString,Dialect> res = ModelManagerInterface::languageForSuffix();
|
QHash<QString,Dialect> res = ModelManagerInterface::languageForSuffix();
|
||||||
|
|
||||||
if (ICore::instance()) {
|
if (ICore::instance()) {
|
||||||
Utils::MimeDatabase mdb;
|
MimeDatabase mdb;
|
||||||
Utils::MimeType jsSourceTy = mdb.mimeTypeForName(QLatin1String(Constants::JS_MIMETYPE));
|
MimeType jsSourceTy = mdb.mimeTypeForName(QLatin1String(Constants::JS_MIMETYPE));
|
||||||
foreach (const QString &suffix, jsSourceTy.suffixes())
|
foreach (const QString &suffix, jsSourceTy.suffixes())
|
||||||
res[suffix] = Dialect::JavaScript;
|
res[suffix] = Dialect::JavaScript;
|
||||||
Utils::MimeType qmlSourceTy = mdb.mimeTypeForName(QLatin1String(Constants::QML_MIMETYPE));
|
MimeType qmlSourceTy = mdb.mimeTypeForName(QLatin1String(Constants::QML_MIMETYPE));
|
||||||
foreach (const QString &suffix, qmlSourceTy.suffixes())
|
foreach (const QString &suffix, qmlSourceTy.suffixes())
|
||||||
res[suffix] = Dialect::Qml;
|
res[suffix] = Dialect::Qml;
|
||||||
Utils::MimeType qbsSourceTy = mdb.mimeTypeForName(QLatin1String(Constants::QBS_MIMETYPE));
|
MimeType qbsSourceTy = mdb.mimeTypeForName(QLatin1String(Constants::QBS_MIMETYPE));
|
||||||
foreach (const QString &suffix, qbsSourceTy.suffixes())
|
foreach (const QString &suffix, qbsSourceTy.suffixes())
|
||||||
res[suffix] = Dialect::QmlQbs;
|
res[suffix] = Dialect::QmlQbs;
|
||||||
Utils::MimeType qmlProjectSourceTy = mdb.mimeTypeForName(QLatin1String(Constants::QMLPROJECT_MIMETYPE));
|
MimeType qmlProjectSourceTy = mdb.mimeTypeForName(QLatin1String(Constants::QMLPROJECT_MIMETYPE));
|
||||||
foreach (const QString &suffix, qmlProjectSourceTy.suffixes())
|
foreach (const QString &suffix, qmlProjectSourceTy.suffixes())
|
||||||
res[suffix] = Dialect::QmlProject;
|
res[suffix] = Dialect::QmlProject;
|
||||||
Utils::MimeType qmlUiSourceTy = mdb.mimeTypeForName(QLatin1String(Constants::QMLUI_MIMETYPE));
|
MimeType qmlUiSourceTy = mdb.mimeTypeForName(QLatin1String(Constants::QMLUI_MIMETYPE));
|
||||||
foreach (const QString &suffix, qmlUiSourceTy.suffixes())
|
foreach (const QString &suffix, qmlUiSourceTy.suffixes())
|
||||||
res[suffix] = Dialect::QmlQtQuick2Ui;
|
res[suffix] = Dialect::QmlQtQuick2Ui;
|
||||||
Utils::MimeType jsonSourceTy = mdb.mimeTypeForName(QLatin1String(Constants::JSON_MIMETYPE));
|
MimeType jsonSourceTy = mdb.mimeTypeForName(QLatin1String(Constants::JSON_MIMETYPE));
|
||||||
foreach (const QString &suffix, jsonSourceTy.suffixes())
|
foreach (const QString &suffix, jsonSourceTy.suffixes())
|
||||||
res[suffix] = Dialect::Json;
|
res[suffix] = Dialect::Json;
|
||||||
}
|
}
|
||||||
@@ -219,9 +221,9 @@ void ModelManager::delayedInitialization()
|
|||||||
connect(cppModelManager, SIGNAL(documentUpdated(CPlusPlus::Document::Ptr)),
|
connect(cppModelManager, SIGNAL(documentUpdated(CPlusPlus::Document::Ptr)),
|
||||||
this, SLOT(maybeQueueCppQmlTypeUpdate(CPlusPlus::Document::Ptr)), Qt::DirectConnection);
|
this, SLOT(maybeQueueCppQmlTypeUpdate(CPlusPlus::Document::Ptr)), Qt::DirectConnection);
|
||||||
|
|
||||||
connect(ProjectExplorer::SessionManager::instance(), &ProjectExplorer::SessionManager::projectRemoved,
|
connect(SessionManager::instance(), &SessionManager::projectRemoved,
|
||||||
this, &ModelManager::removeProjectInfo);
|
this, &ModelManager::removeProjectInfo);
|
||||||
connect(ProjectExplorer::SessionManager::instance(), &ProjectExplorer::SessionManager::startupProjectChanged,
|
connect(SessionManager::instance(), &SessionManager::startupProjectChanged,
|
||||||
this, &ModelManager::updateDefaultProjectInfo);
|
this, &ModelManager::updateDefaultProjectInfo);
|
||||||
|
|
||||||
ViewerContext qbsVContext;
|
ViewerContext qbsVContext;
|
||||||
@@ -261,7 +263,7 @@ ModelManagerInterface::WorkingCopy ModelManager::workingCopyInternal() const
|
|||||||
void ModelManager::updateDefaultProjectInfo()
|
void ModelManager::updateDefaultProjectInfo()
|
||||||
{
|
{
|
||||||
// needs to be performed in the ui thread
|
// needs to be performed in the ui thread
|
||||||
ProjectExplorer::Project *currentProject = ProjectExplorer::SessionManager::startupProject();
|
Project *currentProject = SessionManager::startupProject();
|
||||||
ProjectInfo newDefaultProjectInfo = projectInfo(currentProject,
|
ProjectInfo newDefaultProjectInfo = projectInfo(currentProject,
|
||||||
defaultProjectInfoForProject(currentProject));
|
defaultProjectInfoForProject(currentProject));
|
||||||
setDefaultProject(projectInfo(currentProject,newDefaultProjectInfo), currentProject);
|
setDefaultProject(projectInfo(currentProject,newDefaultProjectInfo), currentProject);
|
||||||
@@ -272,3 +274,6 @@ void ModelManager::addTaskInternal(QFuture<void> result, const QString &msg, con
|
|||||||
{
|
{
|
||||||
ProgressManager::addTask(result, msg, taskId);
|
ProgressManager::addTask(result, msg, taskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace QmlJSTools
|
||||||
|
Reference in New Issue
Block a user