forked from qt-creator/qt-creator
ProjectExplorer: Re-organize RunConfiguration constructors
The idea is to massage the setup in a way to make implementation of new configurations less error prone by identifying recurring patterns and sharing repetitive code that tends to be forgotten (see Android cloning). The former two lines of constructors (owner-and-id, owner-and-source) are split into a simple, shared, constructor and new setId() and copyFrom() functions. The change is mostly mechanical, some multiple calls to fromMap have been removed, though, some consts added. Otherwise, to keep the patch small it temporarily introduces two helper templates in IRunConfigurationFactory. Also, setId() signatures have not been unified yet. These won't be needed in the final setup. Change-Id: I8c0734496caae744a9883fe6d92c1d8f8e0234ea Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -189,26 +189,40 @@ void IRunConfigurationAspect::resetProjectToGlobalSettings()
|
||||
|
||||
static std::vector<RunConfiguration::AspectFactory> theAspectFactories;
|
||||
|
||||
RunConfiguration::RunConfiguration(Target *target, Core::Id id) :
|
||||
StatefulProjectConfiguration(target, id)
|
||||
RunConfiguration::RunConfiguration(Target *target)
|
||||
: StatefulProjectConfiguration(target)
|
||||
{
|
||||
Q_ASSERT(target);
|
||||
ctor();
|
||||
|
||||
for (const AspectFactory &factory : theAspectFactories)
|
||||
addExtraAspect(factory(this));
|
||||
}
|
||||
connect(target->project(), &Project::parsingStarted,
|
||||
this, [this]() { updateEnabledState(); });
|
||||
connect(target->project(), &Project::parsingFinished,
|
||||
this, [this]() { updateEnabledState(); });
|
||||
|
||||
RunConfiguration::RunConfiguration(Target *target, RunConfiguration *source) :
|
||||
StatefulProjectConfiguration(target, source)
|
||||
{
|
||||
Q_ASSERT(target);
|
||||
ctor();
|
||||
foreach (IRunConfigurationAspect *aspect, source->m_aspects) {
|
||||
IRunConfigurationAspect *clone = aspect->clone(this);
|
||||
if (clone)
|
||||
m_aspects.append(clone);
|
||||
}
|
||||
connect(target, &Target::addedRunConfiguration,
|
||||
this, [this](const RunConfiguration *rc) {
|
||||
if (rc == this)
|
||||
updateEnabledState();
|
||||
});
|
||||
|
||||
connect(this, &RunConfiguration::enabledChanged,
|
||||
this, &RunConfiguration::requestRunActionsUpdate);
|
||||
|
||||
Utils::MacroExpander *expander = macroExpander();
|
||||
expander->setDisplayName(tr("Run Settings"));
|
||||
expander->setAccumulating(true);
|
||||
expander->registerSubProvider([target] {
|
||||
BuildConfiguration *bc = target->activeBuildConfiguration();
|
||||
return bc ? bc->macroExpander() : target->macroExpander();
|
||||
});
|
||||
expander->registerPrefix("CurrentRun:Env", tr("Variables in the current run environment"),
|
||||
[this](const QString &var) {
|
||||
const auto envAspect = extraAspect<EnvironmentAspect>();
|
||||
return envAspect ? envAspect->environment().value(var) : QString();
|
||||
});
|
||||
expander->registerVariable(Constants::VAR_CURRENTRUN_NAME,
|
||||
QCoreApplication::translate("ProjectExplorer", "The currently active run configuration's name."),
|
||||
[this] { return displayName(); }, false);
|
||||
}
|
||||
|
||||
RunConfiguration::~RunConfiguration()
|
||||
@@ -216,6 +230,25 @@ RunConfiguration::~RunConfiguration()
|
||||
qDeleteAll(m_aspects);
|
||||
}
|
||||
|
||||
void RunConfiguration::initialize(Core::Id id)
|
||||
{
|
||||
StatefulProjectConfiguration::initialize(id);
|
||||
|
||||
for (const AspectFactory &factory : theAspectFactories)
|
||||
addExtraAspect(factory(this));
|
||||
}
|
||||
|
||||
void RunConfiguration::copyFrom(const RunConfiguration *source)
|
||||
{
|
||||
StatefulProjectConfiguration::copyFrom(source);
|
||||
|
||||
foreach (IRunConfigurationAspect *aspect, source->m_aspects) {
|
||||
IRunConfigurationAspect *clone = aspect->clone(this);
|
||||
if (clone)
|
||||
m_aspects.append(clone);
|
||||
}
|
||||
}
|
||||
|
||||
bool RunConfiguration::isActive() const
|
||||
{
|
||||
return target()->isActive() && target()->activeRunConfiguration() == this;
|
||||
@@ -248,39 +281,6 @@ void RunConfiguration::addExtraAspect(IRunConfigurationAspect *aspect)
|
||||
m_aspects += aspect;
|
||||
}
|
||||
|
||||
void RunConfiguration::ctor()
|
||||
{
|
||||
connect(target()->project(), &Project::parsingStarted,
|
||||
this, [this]() { updateEnabledState(); });
|
||||
connect(target()->project(), &Project::parsingFinished,
|
||||
this, [this]() { updateEnabledState(); });
|
||||
|
||||
connect(target(), &Target::addedRunConfiguration,
|
||||
this, [this](const RunConfiguration *rc) {
|
||||
if (rc == this)
|
||||
updateEnabledState();
|
||||
});
|
||||
|
||||
connect(this, &RunConfiguration::enabledChanged,
|
||||
this, &RunConfiguration::requestRunActionsUpdate);
|
||||
|
||||
Utils::MacroExpander *expander = macroExpander();
|
||||
expander->setDisplayName(tr("Run Settings"));
|
||||
expander->setAccumulating(true);
|
||||
expander->registerSubProvider([this]() -> Utils::MacroExpander * {
|
||||
BuildConfiguration *bc = target()->activeBuildConfiguration();
|
||||
return bc ? bc->macroExpander() : target()->macroExpander();
|
||||
});
|
||||
expander->registerPrefix("CurrentRun:Env", tr("Variables in the current run environment"),
|
||||
[this](const QString &var) {
|
||||
const auto envAspect = extraAspect<EnvironmentAspect>();
|
||||
return envAspect ? envAspect->environment().value(var) : QString();
|
||||
});
|
||||
expander->registerVariable(Constants::VAR_CURRENTRUN_NAME,
|
||||
QCoreApplication::translate("ProjectExplorer", "The currently active run configuration's name."),
|
||||
[this] { return displayName(); }, false);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the RunConfiguration of the currently active target
|
||||
* of the startup project, if such exists, or \c nullptr otherwise.
|
||||
|
||||
Reference in New Issue
Block a user