ProjectExplorer: Clean up variables

Global variables with names such as "CurrentProject*", "CurrentKit*" etc
are harmful, because the term "current project" as used in Qt Creator
does not refer to the "active project", but simply stands for the
project that contains the node that is currently selected in the project
tree, which in turn may or may not correspond to the current editor
document, depending on the "sync with editor" setting. In other words,
the "current project" is almost a random value with little meaning
outside the project tree itself.
Therefore, we remove "CurrentProject*" and friends, except the ones that
are currently intentionally in use. The latter get renamed to
"CurrentDocument:Project*", so their purpose becomes clear. Their old
names are kept around for backward compatibility, but are not suggested
by the variable chooser anymore, so new usages are unlikely and we can
remove them at some point.
We also add some ActiveProject* variants that have been requested in the
past.
Also remove the "CurrentSession" prefix that was deprecated six years
ago.

Fixes: QTCREATORBUG-12724
Fixes: QTCREATORBUG-24606
Change-Id: Ibba5d0e0ce3d2beb444a5eec01fbb9b745d90a1d
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Christian Kandeler
2020-09-28 16:18:44 +02:00
parent da8db0f24d
commit b55825a420
19 changed files with 190 additions and 205 deletions

View File

@@ -34,6 +34,7 @@
#include "deployconfiguration.h"
#include "deploymentdata.h"
#include "devicesupport/devicemanager.h"
#include "environmentaspect.h"
#include "kit.h"
#include "kitinformation.h"
#include "kitmanager.h"
@@ -43,6 +44,7 @@
#include "projectexplorericons.h"
#include "projectexplorersettings.h"
#include "runconfiguration.h"
#include "runconfigurationaspects.h"
#include "session.h"
#include <coreplugin/coreconstants.h>
@@ -157,11 +159,46 @@ Target::Target(Project *project, Kit *k, _constructor_tag) :
d->m_macroExpander.registerVariable("sourceDir", tr("Source directory"),
[project] { return project->projectDirectory().toUserOutput(); });
// Legacy support.
// TODO: Remove in ~4.16.
d->m_macroExpander.registerVariable(Constants::VAR_CURRENTPROJECT_NAME,
QCoreApplication::translate("ProjectExplorer", "Name of current project"),
[project] { return project->displayName(); },
false);
d->m_macroExpander.registerVariable("Project:Name",
QCoreApplication::translate("ProjectExplorer", "Name of current project"),
[project] { return project->displayName(); });
d->m_macroExpander.registerVariable("CurrentRun:Name",
tr("The currently active run configuration's name."),
[this]() -> QString {
if (RunConfiguration * const rc = activeRunConfiguration())
return rc->displayName();
return QString();
});
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();
});
d->m_macroExpander.registerPrefix("CurrentRun:Env", tr("Variables in the current run environment"),
[this](const QString &var) {
if (RunConfiguration * const rc = activeRunConfiguration()) {
if (const auto envAspect = rc->aspect<EnvironmentAspect>())
return envAspect->environment().expandedValueForKey(var);
}
return QString();
});
d->m_macroExpander.registerVariable("CurrentRun:WorkingDir",
tr("The currently active run configuration's working directory"),
[this] {
if (RunConfiguration * const rc = activeRunConfiguration()) {
if (const auto wdAspect = rc->aspect<WorkingDirectoryAspect>())
return wdAspect->workingDirectory(&d->m_macroExpander).toString();
}
return QString();
});
}
Target::~Target()