Commit 9d676f75 authored by Roberto Raggi's avatar Roberto Raggi

Initial work on the QML project manager.

parent eafa7a07
......@@ -31,6 +31,7 @@ SUBDIRS = plugin_coreplugin \
plugin_designer \
plugin_resourceeditor \
plugin_genericprojectmanager \
plugin_qmlprojectmanager \
debugger/dumper.pro
plugin_coreplugin.subdir = coreplugin
......@@ -162,3 +163,8 @@ plugin_genericprojectmanager.depends += plugin_projectexplorer
plugin_genericprojectmanager.depends += plugin_cpptools
plugin_genericprojectmanager.depends += plugin_cppeditor
plugin_genericprojectmanager.depends += plugin_help
plugin_qmlprojectmanager.subdir = qmlprojectmanager
plugin_qmlprojectmanager.depends = plugin_texteditor
plugin_qmlprojectmanager.depends += plugin_projectexplorer
plugin_qmlprojectmanager.depends += plugin_help
<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="text/x-qml-project">
<sub-class-of type="text/plain"/>
<comment>Qml Project file</comment>
<glob pattern="*.qmlproject"/>
</mime-type>
<mime-type type="application/vnd.nokia.qt.qml.files">
<sub-class-of type="text/plain"/>
<comment>Qml Project Files</comment>
<glob pattern="*.files"/>
</mime-type>
</mime-info>
<plugin name="QmlProjectManager" version="1.1.80" compatVersion="1.1.80">
<vendor>Nokia Corporation</vendor>
<copyright>(C) 2008-2009 Nokia Corporation</copyright>
<license>
Commercial Usage
Licensees holding valid Qt Commercial licenses may use this plugin 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 plugin may be used under the terms of the GNU Lesser
General Public License version 2.1 as published by the Free Software
Foundation. 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.</license>
<description>Qml support</description>
<url>http://www.qtsoftware.com</url>
<dependencyList>
<dependency name="TextEditor" version="1.1.80"/>
<dependency name="ProjectExplorer" version="1.1.80"/>
<dependency name="CppTools" version="1.1.80"/>
<dependency name="CppEditor" version="1.1.80"/>
<dependency name="Help" version="1.1.80"/>
</dependencyList>
</plugin>
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
** 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
** contact the sales department at qt-sales@nokia.com.
**
**************************************************************************/
#include "qmlproject.h"
#include "qmlprojectconstants.h"
#include <projectexplorer/toolchain.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/pathchooser.h>
#include <utils/qtcassert.h>
#include <coreplugin/icore.h>
#include <QtCore/QtDebug>
#include <QtCore/QDir>
#include <QtCore/QSettings>
#include <QtCore/QProcess>
#include <QtCore/QCoreApplication>
#include <QtGui/QFormLayout>
#include <QtGui/QMainWindow>
#include <QtGui/QComboBox>
#include <QtGui/QStringListModel>
#include <QtGui/QListWidget>
#include <QtGui/QPushButton>
using namespace QmlProjectManager;
using namespace QmlProjectManager::Internal;
namespace {
/**
* An editable string list model. New strings can be added by editing the entry
* called "<new>", displayed at the end.
*/
class ListModel: public QStringListModel
{
public:
ListModel(QObject *parent)
: QStringListModel(parent) {}
virtual ~ListModel() {}
virtual int rowCount(const QModelIndex &parent) const
{ return 1 + QStringListModel::rowCount(parent); }
virtual Qt::ItemFlags flags(const QModelIndex &index) const
{ return QStringListModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; }
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
{
if (row == stringList().size())
return createIndex(row, column);
return QStringListModel::index(row, column, parent);
}
virtual QVariant data(const QModelIndex &index, int role) const
{
if (role == Qt::DisplayRole || role == Qt::EditRole) {
if (index.row() == stringList().size())
return QCoreApplication::translate("QmlProject", "<new>");
}
return QStringListModel::data(index, role);
}
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
{
if (role == Qt::EditRole && index.row() == stringList().size())
insertRow(index.row(), QModelIndex());
return QStringListModel::setData(index, value, role);
}
};
} // end of anonymous namespace
////////////////////////////////////////////////////////////////////////////////////
// QmlProject
////////////////////////////////////////////////////////////////////////////////////
QmlProject::QmlProject(Manager *manager, const QString &fileName)
: m_manager(manager),
m_fileName(fileName)
{
QFileInfo fileInfo(m_fileName);
QDir dir = fileInfo.dir();
m_projectName = fileInfo.completeBaseName();
m_filesFileName = QFileInfo(dir, m_projectName + QLatin1String(".files")).absoluteFilePath();
m_file = new QmlProjectFile(this, fileName);
m_rootNode = new QmlProjectNode(this, m_file);
m_manager->registerProject(this);
}
QmlProject::~QmlProject()
{
m_manager->unregisterProject(this);
delete m_rootNode;
}
QString QmlProject::filesFileName() const
{ return m_filesFileName; }
static QStringList readLines(const QString &absoluteFileName)
{
QStringList lines;
QFile file(absoluteFileName);
if (file.open(QFile::ReadOnly)) {
QTextStream stream(&file);
forever {
QString line = stream.readLine();
if (line.isNull())
break;
line = line.trimmed();
if (line.isEmpty())
continue;
lines.append(line);
}
}
return lines;
}
void QmlProject::parseProject(RefreshOptions options)
{
if (options & Files) {
m_files = convertToAbsoluteFiles(readLines(filesFileName()));
m_files.removeDuplicates();
}
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
{ return m_files; }
QString QmlProject::buildParser(const QString &) const
{
return QString();
}
QString QmlProject::name() const
{
return m_projectName;
}
Core::IFile *QmlProject::file() const
{
return m_file;
}
ProjectExplorer::IProjectManager *QmlProject::projectManager() const
{
return m_manager;
}
QList<ProjectExplorer::Project *> QmlProject::dependsOn()
{
return QList<Project *>();
}
bool QmlProject::isApplication() const
{
return true;
}
ProjectExplorer::Environment QmlProject::environment(const QString &) const
{
return ProjectExplorer::Environment::systemEnvironment();
}
QString QmlProject::buildDirectory(const QString &buildConfiguration) const
{
QString buildDirectory = value(buildConfiguration, "buildDirectory").toString();
if (buildDirectory.isEmpty()) {
QFileInfo fileInfo(m_fileName);
buildDirectory = fileInfo.absolutePath();
}
return buildDirectory;
}
ProjectExplorer::BuildStepConfigWidget *QmlProject::createConfigWidget()
{
return new QmlBuildSettingsWidget(this);
}
QList<ProjectExplorer::BuildStepConfigWidget*> QmlProject::subConfigWidgets()
{
return QList<ProjectExplorer::BuildStepConfigWidget*>();
}
void QmlProject::newBuildConfiguration(const QString &)
{
}
QmlProjectNode *QmlProject::rootProjectNode() const
{
return m_rootNode;
}
QStringList QmlProject::files(FilesMode) const
{
return m_files;
}
QStringList QmlProject::targets() const
{
QStringList targets;
return targets;
}
QmlMakeStep *QmlProject::makeStep() const
{
return 0;
}
void QmlProject::restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader &reader)
{
Project::restoreSettingsImpl(reader);
refresh(Everything);
}
void QmlProject::saveSettingsImpl(ProjectExplorer::PersistentSettingsWriter &writer)
{
Project::saveSettingsImpl(writer);
}
////////////////////////////////////////////////////////////////////////////////////
// QmlBuildSettingsWidget
////////////////////////////////////////////////////////////////////////////////////
QmlBuildSettingsWidget::QmlBuildSettingsWidget(QmlProject *project)
: m_project(project)
{
QFormLayout *fl = new QFormLayout(this);
// build directory
m_pathChooser = new Core::Utils::PathChooser(this);
m_pathChooser->setEnabled(true);
fl->addRow(tr("Build directory:"), m_pathChooser);
connect(m_pathChooser, SIGNAL(changed()), this, SLOT(buildDirectoryChanged()));
}
QmlBuildSettingsWidget::~QmlBuildSettingsWidget()
{ }
QString QmlBuildSettingsWidget::displayName() const
{ return tr("Qml Manager"); }
void QmlBuildSettingsWidget::init(const QString &buildConfiguration)
{
m_buildConfiguration = buildConfiguration;
m_pathChooser->setPath(m_project->buildDirectory(buildConfiguration));
}
void QmlBuildSettingsWidget::buildDirectoryChanged()
{
m_project->setValue(m_buildConfiguration, "buildDirectory", m_pathChooser->path());
}
////////////////////////////////////////////////////////////////////////////////////
// QmlProjectFile
////////////////////////////////////////////////////////////////////////////////////
QmlProjectFile::QmlProjectFile(QmlProject *parent, QString fileName)
: Core::IFile(parent),
m_project(parent),
m_fileName(fileName)
{ }
QmlProjectFile::~QmlProjectFile()
{ }
bool QmlProjectFile::save(const QString &)
{
return false;
}
QString QmlProjectFile::fileName() const
{
return m_fileName;
}
QString QmlProjectFile::defaultPath() const
{
return QString();
}
QString QmlProjectFile::suggestedFileName() const
{
return QString();
}
QString QmlProjectFile::mimeType() const
{
return Constants::QMLMIMETYPE;
}
bool QmlProjectFile::isModified() const
{
return false;
}
bool QmlProjectFile::isReadOnly() const
{
return true;
}
bool QmlProjectFile::isSaveAsAllowed() const
{
return false;
}
void QmlProjectFile::modified(ReloadBehavior *)
{
}
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
** 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
** contact the sales department at qt-sales@nokia.com.
**
**************************************************************************/
#ifndef QMLPROJECT_H
#define QMLPROJECT_H
#include "qmlprojectmanager.h"
#include "qmlprojectnodes.h"
#include <projectexplorer/project.h>
#include <projectexplorer/projectnodes.h>
#include <projectexplorer/buildstep.h>
#include <coreplugin/ifile.h>
QT_BEGIN_NAMESPACE
class QPushButton;
class QStringListModel;
QT_END_NAMESPACE
namespace Core {
namespace Utils {
class PathChooser;
}
}
namespace QmlProjectManager {
namespace Internal {
class QmlMakeStep;
class QmlProjectFile;
class QmlProject : public ProjectExplorer::Project
{
Q_OBJECT
public:
QmlProject(Manager *manager, const QString &filename);
virtual ~QmlProject();
QString filesFileName() const;
virtual QString name() const;
virtual Core::IFile *file() const;
virtual ProjectExplorer::IProjectManager *projectManager() const;
virtual QList<ProjectExplorer::Project *> dependsOn();
virtual bool isApplication() const;
virtual ProjectExplorer::Environment environment(const QString &buildConfiguration) const;
virtual QString buildDirectory(const QString &buildConfiguration) const;
virtual ProjectExplorer::BuildStepConfigWidget *createConfigWidget();
virtual QList<ProjectExplorer::BuildStepConfigWidget*> subConfigWidgets();
virtual void newBuildConfiguration(const QString &buildConfiguration);
virtual QmlProjectNode *rootProjectNode() const;
virtual QStringList files(FilesMode fileMode) const;
QStringList targets() const;
QmlMakeStep *makeStep() const;
QString buildParser(const QString &buildConfiguration) const;
enum RefreshOptions {
Files = 0x01,
Configuration = 0x02,
Everything = Files | Configuration
};
void refresh(RefreshOptions options);
QStringList files() const;
protected:
virtual void saveSettingsImpl(ProjectExplorer::PersistentSettingsWriter &writer);
virtual void restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader &reader);
private:
void parseProject(RefreshOptions options);
QStringList convertToAbsoluteFiles(const QStringList &paths) const;
Manager *m_manager;
QString m_fileName;
QString m_filesFileName;
QmlProjectFile *m_file;
QString m_projectName;
QStringList m_files;
QmlProjectNode *m_rootNode;
};
class QmlProjectFile : public Core::IFile
{
Q_OBJECT
public:
QmlProjectFile(QmlProject *parent, QString fileName);
virtual ~QmlProjectFile();
virtual bool save(const QString &fileName = QString());
virtual QString fileName() const;
virtual QString defaultPath() const;
virtual QString suggestedFileName() const;
virtual QString mimeType() const;
virtual bool isModified() const;
virtual bool isReadOnly() const;
virtual bool isSaveAsAllowed() const;
virtual void modified(ReloadBehavior *behavior);
private:
QmlProject *m_project;
QString m_fileName;
};
class QmlBuildSettingsWidget : public ProjectExplorer::BuildStepConfigWidget
{
Q_OBJECT
public:
QmlBuildSettingsWidget(QmlProject *project);
virtual ~QmlBuildSettingsWidget();
virtual QString displayName() const;
virtual void init(const QString &buildConfiguration);
private Q_SLOTS:
void buildDirectoryChanged();
private:
QmlProject *m_project;
Core::Utils::PathChooser *m_pathChooser;
QString m_buildConfiguration;
};
} // namespace Internal
} // namespace QmlProjectManager
#endif // QMLPROJECT_H
<RCC>
<qresource prefix="/qmlproject" >
<file>QmlProject.mimetypes.xml</file>
</qresource>
</RCC>
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
** 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
** contact the sales department at qt-sales@nokia.com.
**
**************************************************************************/
#ifndef QMLPROJECTCONSTANTS_H
#define QMLPROJECTCONSTANTS_H
namespace QmlProjectManager {
namespace Constants {
const char *const PROJECTCONTEXT = "QmlProject.ProjectContext";
const char *const QMLMIMETYPE = "text/x-qml-project"; // ### FIXME
const char *const MAKESTEP = "QmlProjectManager.MakeStep";
// contexts
const char *const C_FILESEDITOR = ".files Editor";
// kinds
const char *const PROJECT_KIND = "Qml";
const char *const FILES_EDITOR = ".files Editor";
const char *const FILES_MIMETYPE = "application/vnd.nokia.qt.qml.files";