diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index c0ca9796673..616894fec3f 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -353,6 +353,12 @@ static BuildConfiguration *activeBuildConfiguration() return target ? target->activeBuildConfiguration() : nullptr; } +static RunConfiguration *activeRunConfiguration() +{ + const Target * const target = activeTarget(); + return target ? target->activeRunConfiguration() : nullptr; +} + static bool isTextFile(const QString &fileName) { return Utils::mimeTypeForFile(fileName).inherits( @@ -1912,6 +1918,39 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er return QString(); }); + expander->registerVariable("ActiveProject:RunConfig:Name", + tr("Name of the active project's active run configuration."), + []() -> QString { + if (const RunConfiguration * const rc = activeRunConfiguration()) + return rc->displayName(); + return QString(); + }); + expander->registerFileVariables("ActiveProject:RunConfig:Executable", + tr("The executable of the active project's active run configuration."), + []() -> QString { + if (const RunConfiguration * const rc = activeRunConfiguration()) + return rc->commandLine().executable().toString(); + return QString(); + }); + expander->registerPrefix("ActiveProject:RunConfig:Env", + tr("Variables in the environment of the active project's active run configuration."), + [](const QString &var) { + if (const RunConfiguration * const rc = activeRunConfiguration()) { + if (const auto envAspect = rc->aspect()) + return envAspect->environment().expandedValueForKey(var); + } + return QString(); + }); + expander->registerVariable("ActiveProject:RunConfig:WorkingDir", + tr("The working directory of the active project's active run configuration."), + [] { + if (const RunConfiguration * const rc = activeRunConfiguration()) { + if (const auto wdAspect = rc->aspect()) + return wdAspect->workingDirectory(rc->macroExpander()).toString(); + } + return QString(); + }); + const auto fileHandler = [] { return SessionManager::sessionNameToFileName(SessionManager::activeSession()).toString(); }; diff --git a/src/plugins/projectexplorer/runconfiguration.cpp b/src/plugins/projectexplorer/runconfiguration.cpp index 539cf2c8a87..55c89d0932c 100644 --- a/src/plugins/projectexplorer/runconfiguration.cpp +++ b/src/plugins/projectexplorer/runconfiguration.cpp @@ -188,6 +188,24 @@ RunConfiguration::RunConfiguration(Target *target, Utils::Id id) BuildConfiguration *bc = target->activeBuildConfiguration(); return bc ? bc->macroExpander() : target->macroExpander(); }); + m_expander.registerPrefix("RunConfig:Env", tr("Variables in the run environment"), + [this](const QString &var) { + const auto envAspect = aspect(); + return envAspect ? envAspect->environment().expandedValueForKey(var) : QString(); + }); + m_expander.registerVariable("RunConfig:WorkingDir", + tr("The run configuration's working directory"), + [this] { + const auto wdAspect = aspect(); + return wdAspect ? wdAspect->workingDirectory(&m_expander).toString() : QString(); + }); + m_expander.registerVariable("RunConfig:Name", tr("The run configuration's name."), + [this] { return displayName(); }); + m_expander.registerFileVariables("RunConfig:Executable", + tr("The run configuration's executable."), + [this] { return commandLine().executable().toString(); }); + + m_commandLineGetter = [this] { FilePath executable; if (const auto executableAspect = aspect()) diff --git a/src/plugins/projectexplorer/target.cpp b/src/plugins/projectexplorer/target.cpp index 967077ffd31..f2d79dec958 100644 --- a/src/plugins/projectexplorer/target.cpp +++ b/src/plugins/projectexplorer/target.cpp @@ -174,14 +174,14 @@ Target::Target(Project *project, Kit *k, _constructor_tag) : if (RunConfiguration * const rc = activeRunConfiguration()) return rc->displayName(); return QString(); - }); + }, false); d->m_macroExpander.registerFileVariables("CurrentRun:Executable", tr("The currently active run configuration's executable (if applicable)."), [this]() -> QString { if (RunConfiguration * const rc = activeRunConfiguration()) return rc->commandLine().executable().toString(); return QString(); - }); + }, false); d->m_macroExpander.registerPrefix("CurrentRun:Env", tr("Variables in the current run environment."), [this](const QString &var) { if (RunConfiguration * const rc = activeRunConfiguration()) { @@ -189,7 +189,7 @@ Target::Target(Project *project, Kit *k, _constructor_tag) : return envAspect->environment().expandedValueForKey(var); } return QString(); - }); + }, false); d->m_macroExpander.registerVariable("CurrentRun:WorkingDir", tr("The currently active run configuration's working directory."), [this] { @@ -198,7 +198,7 @@ Target::Target(Project *project, Kit *k, _constructor_tag) : return wdAspect->workingDirectory(&d->m_macroExpander).toString(); } return QString(); - }); + }, false); } Target::~Target()