2009-05-04 12:19:22 +02:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2009-05-04 12:19:22 +02:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2009-05-04 12:19:22 +02:00
|
|
|
**
|
|
|
|
** Commercial Usage
|
|
|
|
**
|
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and Nokia.
|
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
**
|
|
|
|
** Alternatively, 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.
|
|
|
|
**
|
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2009-05-04 12:19:22 +02:00
|
|
|
**
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
#include "qmlproject.h"
|
2010-02-16 13:39:13 +01:00
|
|
|
#include "qmlprojectfile.h"
|
|
|
|
#include "qmlprojectmanagerconstants.h"
|
|
|
|
#include "fileformat/qmlprojectitem.h"
|
2010-03-08 14:36:44 +01:00
|
|
|
#include "qmlprojectrunconfiguration.h"
|
2010-02-17 13:37:00 +01:00
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
#include <coreplugin/messagemanager.h>
|
2009-05-04 12:19:22 +02:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2010-02-16 13:39:13 +01:00
|
|
|
#include <projectexplorer/filewatcher.h>
|
2010-02-15 13:49:00 +01:00
|
|
|
#include <qmljseditor/qmljsmodelmanagerinterface.h>
|
2009-09-04 17:54:38 +02:00
|
|
|
|
2010-02-16 13:39:13 +01:00
|
|
|
#include <QTextStream>
|
2010-02-26 14:46:04 +01:00
|
|
|
#include <QDeclarativeComponent>
|
2010-02-16 13:39:13 +01:00
|
|
|
#include <QtDebug>
|
2010-01-19 13:41:02 +01:00
|
|
|
|
2010-02-16 13:39:13 +01:00
|
|
|
namespace QmlProjectManager {
|
2010-01-18 16:32:14 +01:00
|
|
|
|
2010-02-16 13:39:13 +01:00
|
|
|
QmlProject::QmlProject(Internal::Manager *manager, const QString &fileName)
|
2009-05-04 12:19:22 +02:00
|
|
|
: m_manager(manager),
|
2009-09-04 17:54:38 +02:00
|
|
|
m_fileName(fileName),
|
2010-02-15 13:49:00 +01:00
|
|
|
m_modelManager(ExtensionSystem::PluginManager::instance()->getObject<QmlJSEditor::ModelManagerInterface>()),
|
2010-02-08 15:50:06 +01:00
|
|
|
m_fileWatcher(new ProjectExplorer::FileWatcher(this)),
|
2010-02-16 13:39:13 +01:00
|
|
|
m_targetFactory(new Internal::QmlProjectTargetFactory(this))
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
2010-02-16 13:39:13 +01:00
|
|
|
setSupportedTargetIds(QSet<QString>() << QLatin1String(Constants::QML_VIEWER_TARGET_ID));
|
2009-05-04 12:19:22 +02:00
|
|
|
QFileInfo fileInfo(m_fileName);
|
2009-05-06 15:56:54 +02:00
|
|
|
m_projectName = fileInfo.completeBaseName();
|
2009-05-04 12:19:22 +02:00
|
|
|
|
2010-02-16 13:39:13 +01:00
|
|
|
m_file = new Internal::QmlProjectFile(this, fileName);
|
|
|
|
m_rootNode = new Internal::QmlProjectNode(this, m_file);
|
2009-05-04 12:19:22 +02:00
|
|
|
|
2010-01-19 13:53:48 +01:00
|
|
|
m_fileWatcher->addFile(fileName),
|
|
|
|
connect(m_fileWatcher, SIGNAL(fileChanged(QString)),
|
|
|
|
this, SLOT(refreshProjectFile()));
|
|
|
|
|
2009-05-04 12:19:22 +02:00
|
|
|
m_manager->registerProject(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
QmlProject::~QmlProject()
|
|
|
|
{
|
|
|
|
m_manager->unregisterProject(this);
|
|
|
|
|
|
|
|
delete m_rootNode;
|
|
|
|
}
|
|
|
|
|
2009-05-06 16:13:44 +02:00
|
|
|
QDir QmlProject::projectDir() const
|
|
|
|
{
|
|
|
|
return QFileInfo(file()->fileName()).dir();
|
|
|
|
}
|
|
|
|
|
2009-05-04 12:19:22 +02:00
|
|
|
QString QmlProject::filesFileName() const
|
2009-05-06 15:56:54 +02:00
|
|
|
{ return m_fileName; }
|
2009-05-04 12:19:22 +02:00
|
|
|
|
|
|
|
void QmlProject::parseProject(RefreshOptions options)
|
|
|
|
{
|
|
|
|
if (options & Files) {
|
2010-01-19 13:53:48 +01:00
|
|
|
if (options & ProjectFile)
|
|
|
|
delete m_projectItem.data();
|
2010-01-18 16:32:14 +01:00
|
|
|
if (!m_projectItem) {
|
2010-01-19 13:53:48 +01:00
|
|
|
QFile file(m_fileName);
|
|
|
|
if (file.open(QFile::ReadOnly)) {
|
2010-02-26 14:46:04 +01:00
|
|
|
QDeclarativeComponent *component = new QDeclarativeComponent(&m_engine, this);
|
2010-01-19 13:53:48 +01:00
|
|
|
component->setData(file.readAll(), QUrl::fromLocalFile(m_fileName));
|
|
|
|
if (component->isReady()
|
|
|
|
&& qobject_cast<QmlProjectItem*>(component->create())) {
|
|
|
|
m_projectItem = qobject_cast<QmlProjectItem*>(component->create());
|
|
|
|
connect(m_projectItem.data(), SIGNAL(qmlFilesChanged()), this, SLOT(refreshFiles()));
|
2010-03-21 09:36:54 +01:00
|
|
|
connect(m_projectItem.data(), SIGNAL(importPathsChanged()), this, SLOT(refreshImportPaths()));
|
2010-03-16 16:34:33 +01:00
|
|
|
refreshImportPaths();
|
2010-01-19 13:53:48 +01:00
|
|
|
} else {
|
2010-02-17 13:37:00 +01:00
|
|
|
Core::MessageManager *messageManager = Core::ICore::instance()->messageManager();
|
|
|
|
messageManager->printToOutputPane(tr("Error while loading project file!"));
|
|
|
|
messageManager->printToOutputPane(component->errorsString(), true);
|
2010-01-19 13:53:48 +01:00
|
|
|
}
|
2010-01-18 16:32:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_projectItem) {
|
|
|
|
m_projectItem.data()->setSourceDirectory(projectDir().path());
|
2010-04-06 09:52:29 +02:00
|
|
|
m_modelManager->updateSourceFiles(m_projectItem.data()->files());
|
2010-01-18 16:32:14 +01:00
|
|
|
}
|
|
|
|
m_rootNode->refresh();
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options & Configuration) {
|
|
|
|
// update configuration
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options & Files)
|
|
|
|
emit fileListChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProject::refresh(RefreshOptions options)
|
|
|
|
{
|
|
|
|
QSet<QString> oldFileList;
|
|
|
|
if (!(options & Configuration))
|
|
|
|
oldFileList = m_files.toSet();
|
|
|
|
|
|
|
|
parseProject(options);
|
|
|
|
|
|
|
|
if (options & Files)
|
|
|
|
m_rootNode->refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList QmlProject::convertToAbsoluteFiles(const QStringList &paths) const
|
|
|
|
{
|
|
|
|
const QDir projectDir(QFileInfo(m_fileName).dir());
|
|
|
|
QStringList absolutePaths;
|
|
|
|
foreach (const QString &file, paths) {
|
|
|
|
QFileInfo fileInfo(projectDir, file);
|
|
|
|
absolutePaths.append(fileInfo.absoluteFilePath());
|
|
|
|
}
|
|
|
|
absolutePaths.removeDuplicates();
|
|
|
|
return absolutePaths;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList QmlProject::files() const
|
2010-01-18 16:32:14 +01:00
|
|
|
{
|
|
|
|
QStringList files;
|
|
|
|
if (m_projectItem) {
|
2010-01-28 17:12:07 +01:00
|
|
|
files = m_projectItem.data()->files();
|
2010-01-18 16:32:14 +01:00
|
|
|
} else {
|
|
|
|
files = m_files;
|
|
|
|
}
|
|
|
|
return files;
|
|
|
|
}
|
2009-05-04 12:19:22 +02:00
|
|
|
|
2010-02-17 13:37:00 +01:00
|
|
|
bool QmlProject::validProjectFile() const
|
|
|
|
{
|
|
|
|
return !m_projectItem.isNull();
|
|
|
|
}
|
|
|
|
|
2010-03-21 09:36:54 +01:00
|
|
|
QStringList QmlProject::importPaths() const
|
2010-02-03 09:13:23 +01:00
|
|
|
{
|
2010-03-21 09:36:54 +01:00
|
|
|
QStringList importPaths;
|
2010-02-03 09:13:23 +01:00
|
|
|
if (m_projectItem)
|
2010-03-21 09:36:54 +01:00
|
|
|
importPaths = m_projectItem.data()->importPaths();
|
|
|
|
return importPaths;
|
2010-02-03 09:13:23 +01:00
|
|
|
}
|
|
|
|
|
2010-02-17 11:20:35 +01:00
|
|
|
bool QmlProject::addFiles(const QStringList &filePaths)
|
|
|
|
{
|
|
|
|
QStringList toAdd;
|
|
|
|
foreach (const QString &filePath, filePaths) {
|
|
|
|
if (!m_projectItem.data()->matchesFile(filePath))
|
|
|
|
toAdd << filePaths;
|
|
|
|
}
|
|
|
|
return toAdd.isEmpty();
|
|
|
|
}
|
|
|
|
|
2010-01-19 13:53:48 +01:00
|
|
|
void QmlProject::refreshProjectFile()
|
|
|
|
{
|
|
|
|
refresh(QmlProject::ProjectFile | Files);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProject::refreshFiles()
|
|
|
|
{
|
|
|
|
refresh(Files);
|
|
|
|
}
|
|
|
|
|
2010-03-16 16:34:33 +01:00
|
|
|
void QmlProject::refreshImportPaths()
|
|
|
|
{
|
2010-03-21 09:36:54 +01:00
|
|
|
m_modelManager->setProjectImportPaths(importPaths());
|
2010-03-16 16:34:33 +01:00
|
|
|
}
|
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
QString QmlProject::displayName() const
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
|
|
|
return m_projectName;
|
|
|
|
}
|
|
|
|
|
2010-01-22 15:59:44 +01:00
|
|
|
QString QmlProject::id() const
|
|
|
|
{
|
|
|
|
return QLatin1String("QmlProjectManager.QmlProject");
|
|
|
|
}
|
|
|
|
|
2009-05-04 12:19:22 +02:00
|
|
|
Core::IFile *QmlProject::file() const
|
|
|
|
{
|
|
|
|
return m_file;
|
|
|
|
}
|
|
|
|
|
2010-02-16 13:39:13 +01:00
|
|
|
Internal::Manager *QmlProject::projectManager() const
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
|
|
|
return m_manager;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<ProjectExplorer::Project *> QmlProject::dependsOn()
|
|
|
|
{
|
|
|
|
return QList<Project *>();
|
|
|
|
}
|
|
|
|
|
2009-08-06 15:31:32 +02:00
|
|
|
ProjectExplorer::BuildConfigWidget *QmlProject::createConfigWidget()
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
2009-05-07 12:27:52 +02:00
|
|
|
return 0;
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
2009-08-06 15:31:32 +02:00
|
|
|
QList<ProjectExplorer::BuildConfigWidget*> QmlProject::subConfigWidgets()
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
2009-08-06 15:31:32 +02:00
|
|
|
return QList<ProjectExplorer::BuildConfigWidget*>();
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
2010-02-16 13:39:13 +01:00
|
|
|
Internal::QmlProjectTargetFactory *QmlProject::targetFactory() const
|
2009-05-04 13:38:03 +02:00
|
|
|
{
|
2010-02-08 15:50:06 +01:00
|
|
|
return m_targetFactory;
|
|
|
|
}
|
|
|
|
|
2010-02-16 13:39:13 +01:00
|
|
|
Internal::QmlProjectTarget *QmlProject::activeTarget() const
|
2010-02-08 15:50:06 +01:00
|
|
|
{
|
2010-02-16 13:39:13 +01:00
|
|
|
return static_cast<Internal::QmlProjectTarget *>(Project::activeTarget());
|
2009-05-04 13:38:03 +02:00
|
|
|
}
|
2009-05-04 12:19:22 +02:00
|
|
|
|
2010-02-16 13:39:13 +01:00
|
|
|
Internal::QmlProjectNode *QmlProject::rootProjectNode() const
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
|
|
|
return m_rootNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList QmlProject::files(FilesMode) const
|
|
|
|
{
|
2010-01-18 16:32:14 +01:00
|
|
|
return files();
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
2010-01-19 16:33:44 +01:00
|
|
|
bool QmlProject::fromMap(const QVariantMap &map)
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
2010-02-04 11:51:35 +01:00
|
|
|
if (!Project::fromMap(map))
|
|
|
|
return false;
|
2009-05-04 12:19:22 +02:00
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
if (targets().isEmpty()) {
|
2010-02-16 13:39:13 +01:00
|
|
|
Internal::QmlProjectTarget *target(targetFactory()->create(this, QLatin1String(Constants::QML_VIEWER_TARGET_ID)));
|
2010-02-08 15:50:06 +01:00
|
|
|
addTarget(target);
|
2009-05-07 12:27:52 +02:00
|
|
|
}
|
|
|
|
|
2009-05-04 12:19:22 +02:00
|
|
|
refresh(Everything);
|
2010-03-08 14:36:44 +01:00
|
|
|
// FIXME workaround to guarantee that run/debug actions are enabled if a valid file exists
|
|
|
|
QmlProjectRunConfiguration *runConfig = static_cast<QmlProjectRunConfiguration*>(activeTarget()->activeRunConfiguration());
|
2010-03-11 11:29:51 +01:00
|
|
|
if (runConfig)
|
|
|
|
runConfig->changeCurrentFile(0);
|
2010-03-08 14:36:44 +01:00
|
|
|
|
2009-07-03 16:46:01 +02:00
|
|
|
return true;
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
2010-02-16 13:39:13 +01:00
|
|
|
} // namespace QmlProjectManager
|
2009-12-17 09:54:16 +01:00
|
|
|
|