forked from qt-creator/qt-creator
ProjectExplorer: (Re-)Add run config variables
As for the build config, we provide a global variant for use by external
tools, and one for use in the respective run configuration itself.
Also hide the deprecated "CurrentRun" variant, which was forgotten in
b55825a420
.
Fixes: QTCREATORBUG-25561
Change-Id: I51aaff10301f7ff1256abf1c09ac9f5be136ab00
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -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<EnvironmentAspect>())
|
||||
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<WorkingDirectoryAspect>())
|
||||
return wdAspect->workingDirectory(rc->macroExpander()).toString();
|
||||
}
|
||||
return QString();
|
||||
});
|
||||
|
||||
const auto fileHandler = [] {
|
||||
return SessionManager::sessionNameToFileName(SessionManager::activeSession()).toString();
|
||||
};
|
||||
|
@@ -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<EnvironmentAspect>();
|
||||
return envAspect ? envAspect->environment().expandedValueForKey(var) : QString();
|
||||
});
|
||||
m_expander.registerVariable("RunConfig:WorkingDir",
|
||||
tr("The run configuration's working directory"),
|
||||
[this] {
|
||||
const auto wdAspect = aspect<WorkingDirectoryAspect>();
|
||||
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<ExecutableAspect>())
|
||||
|
@@ -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()
|
||||
|
Reference in New Issue
Block a user