Commit b191f154 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Implemented the run configration factory and removed some obsoleted code.

parent abafbb7a
......@@ -39,6 +39,7 @@
#include <coreplugin/editormanager/editormanager.h>
#include <utils/synchronousprocess.h>
#include <utils/pathchooser.h>
#include <QtCore/QtDebug>
#include <QtCore/QDir>
......@@ -49,62 +50,10 @@
#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
////////////////////////////////////////////////////////////////////////////////////
......@@ -120,9 +69,6 @@ QmlProject::QmlProject(Manager *manager, const QString &fileName)
m_rootNode = new QmlProjectNode(this, m_file);
m_manager->registerProject(this);
QSharedPointer<QmlApplicationRunConfiguration> runConf(new QmlApplicationRunConfiguration(this));
addRunConfiguration(runConf);
}
QmlProject::~QmlProject()
......@@ -254,7 +200,7 @@ QString QmlProject::buildDirectory(const QString &) const
ProjectExplorer::BuildStepConfigWidget *QmlProject::createConfigWidget()
{
return new QmlBuildSettingsWidget(this);
return 0;
}
QList<ProjectExplorer::BuildStepConfigWidget*> QmlProject::subConfigWidgets()
......@@ -291,6 +237,11 @@ void QmlProject::restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader &
{
Project::restoreSettingsImpl(reader);
if (runConfigurations().isEmpty()) {
QSharedPointer<QmlRunConfiguration> runConf(new QmlRunConfiguration(this));
addRunConfiguration(runConf);
}
refresh(Everything);
}
......@@ -299,25 +250,6 @@ void QmlProject::saveSettingsImpl(ProjectExplorer::PersistentSettingsWriter &wri
Project::saveSettingsImpl(writer);
}
////////////////////////////////////////////////////////////////////////////////////
// QmlBuildSettingsWidget
////////////////////////////////////////////////////////////////////////////////////
QmlBuildSettingsWidget::QmlBuildSettingsWidget(QmlProject *project)
: m_project(project)
{
}
QmlBuildSettingsWidget::~QmlBuildSettingsWidget()
{ }
QString QmlBuildSettingsWidget::displayName() const
{ return tr("QML Manager"); }
void QmlBuildSettingsWidget::init(const QString &)
{
}
////////////////////////////////////////////////////////////////////////////////////
// QmlProjectFile
////////////////////////////////////////////////////////////////////////////////////
......@@ -375,40 +307,42 @@ void QmlProjectFile::modified(ReloadBehavior *)
{
}
QmlApplicationRunConfiguration::QmlApplicationRunConfiguration(QmlProject *pro)
QmlRunConfiguration::QmlRunConfiguration(QmlProject *pro)
: ProjectExplorer::ApplicationRunConfiguration(pro),
m_project(pro)
m_project(pro),
m_type(Constants::QMLRUNCONFIGURATION)
{
setName(tr("QML Viewer"));
m_qmlViewer = Core::Utils::SynchronousProcess::locateBinary(QLatin1String("qmlviewer"));
}
QmlApplicationRunConfiguration::~QmlApplicationRunConfiguration()
QmlRunConfiguration::~QmlRunConfiguration()
{
}
QString QmlApplicationRunConfiguration::type() const
QString QmlRunConfiguration::type() const
{
return QLatin1String("QmlProject.QmlApplicationRunConfiguration");
return m_type;
}
QString QmlApplicationRunConfiguration::executable() const
QString QmlRunConfiguration::executable() const
{
const QString executable = Core::Utils::SynchronousProcess::locateBinary(QLatin1String("qmlviewer"));
return executable;
return m_qmlViewer;
}
QmlApplicationRunConfiguration::RunMode QmlApplicationRunConfiguration::runMode() const
QmlRunConfiguration::RunMode QmlRunConfiguration::runMode() const
{
return Gui;
}
QString QmlApplicationRunConfiguration::workingDirectory() const
QString QmlRunConfiguration::workingDirectory() const
{
QFileInfo projectFile(m_project->file()->fileName());
return projectFile.filePath();
}
QStringList QmlApplicationRunConfiguration::commandLineArguments() const
QStringList QmlRunConfiguration::commandLineArguments() const
{
QStringList args;
......@@ -419,44 +353,60 @@ QStringList QmlApplicationRunConfiguration::commandLineArguments() const
return args;
}
ProjectExplorer::Environment QmlApplicationRunConfiguration::environment() const
ProjectExplorer::Environment QmlRunConfiguration::environment() const
{
return ProjectExplorer::Environment::systemEnvironment();
}
QString QmlApplicationRunConfiguration::dumperLibrary() const
QString QmlRunConfiguration::dumperLibrary() const
{
return QString();
}
QWidget *QmlApplicationRunConfiguration::configurationWidget()
QWidget *QmlRunConfiguration::configurationWidget()
{
QWidget *config = new QWidget;
QFormLayout *form = new QFormLayout(config);
QComboBox *combo = new QComboBox;
combo->addItem(tr("<Current File>"));
connect(combo, SIGNAL(activated(QString)), this, SLOT(setMainScript(QString)));
QDir projectDir = m_project->projectDir();
QStringList files;
files.append(tr("<Current File>"));
int currentIndex = -1;
foreach (const QString &fn, m_project->files()) {
QFileInfo fileInfo(fn);
if (fileInfo.suffix() != QLatin1String("qml"))
continue;
files.append(projectDir.relativeFilePath(fn));
QString fileName = projectDir.relativeFilePath(fn);
if (fileName == m_scriptFile)
currentIndex = files.size();
files.append(fileName);
}
combo->addItems(files);
if (currentIndex != -1)
combo->setCurrentIndex(currentIndex);
connect(combo, SIGNAL(activated(QString)), this, SLOT(setMainScript(QString)));
Core::Utils::PathChooser *qmlViewer = new Core::Utils::PathChooser;
qmlViewer->setExpectedKind(Core::Utils::PathChooser::Command);
qmlViewer->setPath(executable());
connect(qmlViewer, SIGNAL(changed()), this, SLOT(onQmlViewerChanged()));
form->addRow(tr("QML Viewer"), qmlViewer);
form->addRow(tr("Main QML File:"), combo);
return config;
}
QString QmlApplicationRunConfiguration::mainScript() const
QString QmlRunConfiguration::mainScript() const
{
if (m_scriptFile.isEmpty() || m_scriptFile == tr("<Current File>")) {
Core::EditorManager *editorManager = Core::ICore::instance()->editorManager();
......@@ -468,17 +418,73 @@ QString QmlApplicationRunConfiguration::mainScript() const
return m_project->projectDir().absoluteFilePath(m_scriptFile);
}
void QmlApplicationRunConfiguration::setMainScript(const QString &scriptFile)
void QmlRunConfiguration::setMainScript(const QString &scriptFile)
{
m_scriptFile = scriptFile;
}
void QmlApplicationRunConfiguration::save(ProjectExplorer::PersistentSettingsWriter &writer) const
void QmlRunConfiguration::onQmlViewerChanged()
{
if (Core::Utils::PathChooser *chooser = qobject_cast<Core::Utils::PathChooser *>(sender())) {
m_qmlViewer = chooser->path();
}
}
void QmlRunConfiguration::save(ProjectExplorer::PersistentSettingsWriter &writer) const
{
ProjectExplorer::ApplicationRunConfiguration::save(writer);
writer.saveValue(QLatin1String("qmlviewer"), m_qmlViewer);
writer.saveValue(QLatin1String("mainscript"), m_scriptFile);
}
void QmlApplicationRunConfiguration::restore(const ProjectExplorer::PersistentSettingsReader &reader)
void QmlRunConfiguration::restore(const ProjectExplorer::PersistentSettingsReader &reader)
{
ProjectExplorer::ApplicationRunConfiguration::restore(reader);
m_qmlViewer = reader.restoreValue(QLatin1String("qmlviewer")).toString();
m_scriptFile = reader.restoreValue(QLatin1String("mainscript")).toString();
if (m_qmlViewer.isEmpty())
m_qmlViewer = Core::Utils::SynchronousProcess::locateBinary(QLatin1String("qmlviewer"));
if (m_scriptFile.isEmpty())
m_scriptFile = tr("<Current File>");
}
QmlRunConfigurationFactory::QmlRunConfigurationFactory()
: m_type(Constants::QMLRUNCONFIGURATION)
{
}
QmlRunConfigurationFactory::~QmlRunConfigurationFactory()
{
}
bool QmlRunConfigurationFactory::canCreate(const QString &type) const
{
if (type.startsWith(m_type))
return true;
return false;
}
QStringList QmlRunConfigurationFactory::canCreate(ProjectExplorer::Project *) const
{
return QStringList();
}
QString QmlRunConfigurationFactory::nameForType(const QString &type) const
{
return type;
}
QSharedPointer<ProjectExplorer::RunConfiguration> QmlRunConfigurationFactory::create(ProjectExplorer::Project *project,
const QString &)
{
QmlProject *pro = qobject_cast<QmlProject *>(project);
QSharedPointer<ProjectExplorer::RunConfiguration> rc(new QmlRunConfiguration(pro));
return rc;
}
......@@ -136,28 +136,12 @@ private:
QString m_fileName;
};
class QmlBuildSettingsWidget : public ProjectExplorer::BuildStepConfigWidget
class QmlRunConfiguration : public ProjectExplorer::ApplicationRunConfiguration
{
Q_OBJECT
public:
QmlBuildSettingsWidget(QmlProject *project);
virtual ~QmlBuildSettingsWidget();
virtual QString displayName() const;
virtual void init(const QString &buildConfiguration);
private:
QmlProject *m_project;
};
class QmlApplicationRunConfiguration : public ProjectExplorer::ApplicationRunConfiguration
{
Q_OBJECT
public:
QmlApplicationRunConfiguration(QmlProject *pro);
virtual ~QmlApplicationRunConfiguration();
QmlRunConfiguration(QmlProject *pro);
virtual ~QmlRunConfiguration();
virtual QString type() const;
virtual QString executable() const;
......@@ -173,6 +157,8 @@ public:
private Q_SLOTS:
void setMainScript(const QString &scriptFile);
void onQmlViewerChanged();
private:
QString mainScript() const;
......@@ -180,8 +166,35 @@ private:
private:
QmlProject *m_project;
QString m_scriptFile;
QString m_qmlViewer;
QLatin1String m_type;
};
class QmlRunConfigurationFactory : public ProjectExplorer::IRunConfigurationFactory
{
Q_OBJECT
public:
QmlRunConfigurationFactory();
virtual ~QmlRunConfigurationFactory();
// used to recreate the runConfigurations when restoring settings
virtual bool canCreate(const QString &type) const;
// used to show the list of possible additons to a project, returns a list of types
virtual QStringList canCreate(ProjectExplorer::Project *pro) const;
// used to translate the types to names to display to the user
virtual QString nameForType(const QString &type) const;
virtual QSharedPointer<ProjectExplorer::RunConfiguration> create(ProjectExplorer::Project *project,
const QString &type);
private:
QLatin1String m_type;
};
} // namespace Internal
} // namespace QmlProjectManager
......
......@@ -35,7 +35,8 @@ namespace Constants {
const char *const PROJECTCONTEXT = "QmlProject.ProjectContext";
const char *const QMLMIMETYPE = "text/x-qml-project"; // ### FIXME
const char *const MAKESTEP = "QmlProjectManager.MakeStep";
const char *const QMLRUNCONFIGURATION = "QmlProject.QmlApplicationRunConfiguration";
// contexts
const char *const C_FILESEDITOR = ".files Editor";
......
......@@ -32,6 +32,7 @@
#include "qmlprojectwizard.h"
#include "qmlprojectconstants.h"
#include "qmlprojectfileseditor.h"
#include "qmlproject.h"
#include <coreplugin/icore.h>
#include <coreplugin/mimedatabase.h>
......@@ -75,6 +76,7 @@ bool QmlProjectPlugin::initialize(const QStringList &, QString *errorMessage)
addObject(m_projectFilesEditorFactory);
addAutoReleasedObject(manager);
addAutoReleasedObject(new QmlRunConfigurationFactory);
addAutoReleasedObject(new QmlProjectWizard);
return true;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment