Commit 10151809 authored by dt's avatar dt
Browse files

Add Environment settings to CMakeRunConfiguration

parent efc865a4
...@@ -459,7 +459,10 @@ ProjectExplorer::Environment CMakeProject::environment(const QString &buildConfi ...@@ -459,7 +459,10 @@ ProjectExplorer::Environment CMakeProject::environment(const QString &buildConfi
void CMakeProject::setUseSystemEnvironment(const QString &buildConfiguration, bool b) void CMakeProject::setUseSystemEnvironment(const QString &buildConfiguration, bool b)
{ {
if (b == useSystemEnvironment(buildConfiguration))
return;
setValue(buildConfiguration, "clearSystemEnvironment", !b); setValue(buildConfiguration, "clearSystemEnvironment", !b);
emit environmentChanged(buildConfiguration);
} }
bool CMakeProject::useSystemEnvironment(const QString &buildConfiguration) const bool CMakeProject::useSystemEnvironment(const QString &buildConfiguration) const
...@@ -475,7 +478,11 @@ QList<ProjectExplorer::EnvironmentItem> CMakeProject::userEnvironmentChanges(con ...@@ -475,7 +478,11 @@ QList<ProjectExplorer::EnvironmentItem> CMakeProject::userEnvironmentChanges(con
void CMakeProject::setUserEnvironmentChanges(const QString &buildConfig, const QList<ProjectExplorer::EnvironmentItem> &diff) void CMakeProject::setUserEnvironmentChanges(const QString &buildConfig, const QList<ProjectExplorer::EnvironmentItem> &diff)
{ {
QStringList list = EnvironmentItem::toStringList(diff);
if (list == value(buildConfig, "userEnvironmentChanges"))
return;
setValue(buildConfig, "userEnvironmentChanges", EnvironmentItem::toStringList(diff)); setValue(buildConfig, "userEnvironmentChanges", EnvironmentItem::toStringList(diff));
emit environmentChanged(buildConfig);
} }
QString CMakeProject::buildDirectory(const QString &buildConfiguration) const QString CMakeProject::buildDirectory(const QString &buildConfiguration) const
......
...@@ -49,6 +49,12 @@ CMakeRunConfiguration::CMakeRunConfiguration(CMakeProject *pro, const QString &t ...@@ -49,6 +49,12 @@ CMakeRunConfiguration::CMakeRunConfiguration(CMakeProject *pro, const QString &t
, m_title(title) , m_title(title)
{ {
setName(title); setName(title);
connect(pro, SIGNAL(activeBuildConfigurationChanged()),
this, SIGNAL(baseEnvironmentChanged()));
connect(pro, SIGNAL(environmentChanged(QString)),
this, SIGNAL(baseEnvironmentChanged()));
} }
CMakeRunConfiguration::~CMakeRunConfiguration() CMakeRunConfiguration::~CMakeRunConfiguration()
...@@ -80,11 +86,6 @@ QStringList CMakeRunConfiguration::commandLineArguments() const ...@@ -80,11 +86,6 @@ QStringList CMakeRunConfiguration::commandLineArguments() const
return ProjectExplorer::Environment::parseCombinedArgString(m_arguments); return ProjectExplorer::Environment::parseCombinedArgString(m_arguments);
} }
ProjectExplorer::Environment CMakeRunConfiguration::environment() const
{
return project()->environment(project()->activeBuildConfiguration());
}
QString CMakeRunConfiguration::title() const QString CMakeRunConfiguration::title() const
{ {
return m_title; return m_title;
...@@ -108,6 +109,7 @@ void CMakeRunConfiguration::save(ProjectExplorer::PersistentSettingsWriter &writ ...@@ -108,6 +109,7 @@ void CMakeRunConfiguration::save(ProjectExplorer::PersistentSettingsWriter &writ
writer.saveValue("CMakeRunConfiguration.UseTerminal", m_runMode == Console); writer.saveValue("CMakeRunConfiguration.UseTerminal", m_runMode == Console);
writer.saveValue("CMakeRunConfiguation.Title", m_title); writer.saveValue("CMakeRunConfiguation.Title", m_title);
writer.saveValue("CMakeRunConfiguration.Arguments", m_arguments); writer.saveValue("CMakeRunConfiguration.Arguments", m_arguments);
writer.saveValue("CMakeRunConfiguration.UserEnvironmentChanges", ProjectExplorer::EnvironmentItem::toStringList(m_userEnvironmentChanges));
} }
void CMakeRunConfiguration::restore(const ProjectExplorer::PersistentSettingsReader &reader) void CMakeRunConfiguration::restore(const ProjectExplorer::PersistentSettingsReader &reader)
...@@ -118,19 +120,12 @@ void CMakeRunConfiguration::restore(const ProjectExplorer::PersistentSettingsRea ...@@ -118,19 +120,12 @@ void CMakeRunConfiguration::restore(const ProjectExplorer::PersistentSettingsRea
m_runMode = reader.restoreValue("CMakeRunConfiguration.UseTerminal").toBool() ? Console : Gui; m_runMode = reader.restoreValue("CMakeRunConfiguration.UseTerminal").toBool() ? Console : Gui;
m_title = reader.restoreValue("CMakeRunConfiguation.Title").toString(); m_title = reader.restoreValue("CMakeRunConfiguation.Title").toString();
m_arguments = reader.restoreValue("CMakeRunConfiguration.Arguments").toString(); m_arguments = reader.restoreValue("CMakeRunConfiguration.Arguments").toString();
m_userEnvironmentChanges = ProjectExplorer::EnvironmentItem::fromStringList(reader.restoreValue("CMakeRunConfiguration.UserEnvironmentChanges").toStringList());
} }
QWidget *CMakeRunConfiguration::configurationWidget() QWidget *CMakeRunConfiguration::configurationWidget()
{ {
QWidget *widget = new QWidget(); return new CMakeRunConfigurationWidget(this);
QFormLayout *fl = new QFormLayout();
widget->setLayout(fl);
QLineEdit *argumentsLineEdit = new QLineEdit(widget);
argumentsLineEdit->setText(m_arguments);
connect(argumentsLineEdit, SIGNAL(textChanged(QString)),
this, SLOT(setArguments(QString)));
fl->addRow(tr("Arguments:"), argumentsLineEdit);
return widget;
} }
void CMakeRunConfiguration::setArguments(const QString &newText) void CMakeRunConfiguration::setArguments(const QString &newText)
...@@ -145,6 +140,89 @@ QString CMakeRunConfiguration::dumperLibrary() const ...@@ -145,6 +140,89 @@ QString CMakeRunConfiguration::dumperLibrary() const
return dhl; return dhl;
} }
ProjectExplorer::Environment CMakeRunConfiguration::baseEnvironment() const
{
// TODO use either System Environment
// build environment
// or empty
//Environment env = Environment(QProcess::systemEnvironment());
QString config = project()->activeBuildConfiguration();
ProjectExplorer::Environment env = project()->environment(project()->activeBuildConfiguration());
return env;
}
ProjectExplorer::Environment CMakeRunConfiguration::environment() const
{
ProjectExplorer::Environment env = baseEnvironment();
env.modify(userEnvironmentChanges());
return env;
}
QList<ProjectExplorer::EnvironmentItem> CMakeRunConfiguration::userEnvironmentChanges() const
{
return m_userEnvironmentChanges;
}
void CMakeRunConfiguration::setUserEnvironmentChanges(const QList<ProjectExplorer::EnvironmentItem> &diff)
{
if (m_userEnvironmentChanges != diff) {
m_userEnvironmentChanges = diff;
emit userEnvironmentChangesChanged(diff);
}
}
// Configuration widget
CMakeRunConfigurationWidget::CMakeRunConfigurationWidget(CMakeRunConfiguration *cmakeRunConfiguration, QWidget *parent)
: QWidget(parent), m_cmakeRunConfiguration(cmakeRunConfiguration)
{
QFormLayout *fl = new QFormLayout();
QLineEdit *argumentsLineEdit = new QLineEdit();
argumentsLineEdit->setText(ProjectExplorer::Environment::joinArgumentList(cmakeRunConfiguration->commandLineArguments()));
connect(argumentsLineEdit, SIGNAL(textChanged(QString)),
this, SLOT(setArguments(QString)));
fl->addRow(tr("Arguments:"), argumentsLineEdit);
QVBoxLayout *vbx = new QVBoxLayout(this);
vbx->addLayout(fl);
m_environmentWidget = new ProjectExplorer::EnvironmentWidget(this);
vbx->addWidget(m_environmentWidget);
m_environmentWidget->setBaseEnvironment(m_cmakeRunConfiguration->baseEnvironment());
m_environmentWidget->setUserChanges(m_cmakeRunConfiguration->userEnvironmentChanges());
connect(m_environmentWidget, SIGNAL(userChangesUpdated()),
this, SLOT(userChangesUpdated()));
connect(m_cmakeRunConfiguration, SIGNAL(baseEnvironmentChanged()),
this, SLOT(baseEnvironmentChanged()));
connect(m_cmakeRunConfiguration, SIGNAL(userEnvironmentChangesChanged(QList<ProjectExplorer::EnvironmentItem>)),
this, SLOT(userEnvironmentChangesChanged()));
}
void CMakeRunConfigurationWidget::userChangesUpdated()
{
m_cmakeRunConfiguration->setUserEnvironmentChanges(m_environmentWidget->userChanges());
}
void CMakeRunConfigurationWidget::baseEnvironmentChanged()
{
m_environmentWidget->setBaseEnvironment(m_cmakeRunConfiguration->baseEnvironment());
}
void CMakeRunConfigurationWidget::userEnvironmentChangesChanged()
{
m_environmentWidget->setUserChanges(m_cmakeRunConfiguration->userEnvironmentChanges());
}
void CMakeRunConfigurationWidget::setArguments(const QString &args)
{
m_cmakeRunConfiguration->setArguments(args);
}
// Factory // Factory
CMakeRunConfigurationFactory::CMakeRunConfigurationFactory() CMakeRunConfigurationFactory::CMakeRunConfigurationFactory()
{ {
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <projectexplorer/applicationrunconfiguration.h> #include <projectexplorer/applicationrunconfiguration.h>
#include <projectexplorer/environment.h> #include <projectexplorer/environment.h>
#include <projectexplorer/persistentsettings.h> #include <projectexplorer/persistentsettings.h>
#include <projectexplorer/environmenteditmodel.h>
namespace CMakeProjectManager { namespace CMakeProjectManager {
namespace Internal { namespace Internal {
...@@ -41,6 +42,7 @@ class CMakeProject; ...@@ -41,6 +42,7 @@ class CMakeProject;
class CMakeRunConfiguration : public ProjectExplorer::ApplicationRunConfiguration class CMakeRunConfiguration : public ProjectExplorer::ApplicationRunConfiguration
{ {
friend class CMakeRunConfigurationWidget;
Q_OBJECT Q_OBJECT
public: public:
CMakeRunConfiguration(CMakeProject *pro, const QString &target, const QString &workingDirectory, const QString &title); CMakeRunConfiguration(CMakeProject *pro, const QString &target, const QString &workingDirectory, const QString &title);
...@@ -62,24 +64,41 @@ public: ...@@ -62,24 +64,41 @@ public:
virtual void restore(const ProjectExplorer::PersistentSettingsReader &reader); virtual void restore(const ProjectExplorer::PersistentSettingsReader &reader);
virtual QString dumperLibrary() const; virtual QString dumperLibrary() const;
signals:
void baseEnvironmentChanged();
void userEnvironmentChangesChanged(const QList<ProjectExplorer::EnvironmentItem> &diff);
private slots: private slots:
void setArguments(const QString &newText); void setArguments(const QString &newText);
private: private:
ProjectExplorer::Environment baseEnvironment() const;
void setUserEnvironmentChanges(const QList<ProjectExplorer::EnvironmentItem> &diff);
QList<ProjectExplorer::EnvironmentItem> userEnvironmentChanges() const;
RunMode m_runMode; RunMode m_runMode;
QString m_target; QString m_target;
QString m_workingDirectory; QString m_workingDirectory;
QString m_title; QString m_title;
QString m_arguments; QString m_arguments;
QList<ProjectExplorer::EnvironmentItem> m_userEnvironmentChanges;
};
class CMakeRunConfigurationWidget : public QWidget
{
Q_OBJECT
public:
CMakeRunConfigurationWidget(CMakeRunConfiguration *cmakeRunConfiguration, QWidget *parent = 0);
private slots:
void setArguments(const QString &args);
void baseEnvironmentChanged();
void userEnvironmentChangesChanged();
void userChangesUpdated();
private:
CMakeRunConfiguration *m_cmakeRunConfiguration;
ProjectExplorer::EnvironmentWidget *m_environmentWidget;
}; };
/* The run configuration factory is used for restoring run configurations from
* settings. And used to create new runconfigurations in the "Run Settings" Dialog.
* For the first case bool canCreate(const QString &type) and
* QSharedPointer<RunConfiguration> create(Project *project, QString type) are used.
* For the second type the functions QStringList canCreate(Project *pro) and
* QString nameForType(const QString&) are used to generate a list of creatable
* RunConfigurations, and create(..) is used to create it.
*/
class CMakeRunConfigurationFactory : public ProjectExplorer::IRunConfigurationFactory class CMakeRunConfigurationFactory : public ProjectExplorer::IRunConfigurationFactory
{ {
Q_OBJECT; Q_OBJECT;
......
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