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

@@ -230,8 +230,9 @@
%{variable}
\endcode
For example, the following variable expands to the name of the current
project: \c {%{CurrentProject:Name}}.
For example, the following variable expands to the name of the
project containing the file that is currently open in the editor:
\c {%{CurrentDocument:Project:Name}}.
Use unique variable names within a snippet, because all instances of a
variable are renamed when you specify a value for it.

View File

@@ -59,8 +59,8 @@ public:
<snippet group="C++" trigger="lic" id="license-configured" complement="" removed="false" modified="false">%{Cpp:LicenseTemplate}
$$</snippet>
<snippet group="C++" trigger="licbsd" id="license-bsd" complement="" removed="false" modified="false">/**
@if ('%{CurrentProject:Name}' !== '')
** This file is part of the %{CurrentProject:Name} project.
@if ('%{CurrentDocument:Project:Name}' !== '')
** This file is part of the %{CurrentDocument:Project:Name} project.
@endif
@if ('%{Env:QTC_COPYRIGHT_USER}' === '' || '%{Env:QTC_COPYRIGHT_EMAIL}' === '')
** Copyright %{CurrentDate:yyyy} $copyright_user$ &lt;$copyright_email$&gt;.
@@ -95,8 +95,8 @@ $$</snippet>
$$</snippet>
<snippet group="C++" trigger="licgpl" id="license-gpl" complement="" removed="false" modified="false">/**
@if ('%{CurrentProject:Name}' !== '')
** This file is part of the %{CurrentProject:Name} project.
@if ('%{CurrentDocument:Project:Name}' !== '')
** This file is part of the %{CurrentDocument:Project:Name} project.
@endif
@if ('%{Env:QTC_COPYRIGHT_USER}' === '' || '%{Env:QTC_COPYRIGHT_EMAIL}' === '')
** Copyright %{CurrentDate:yyyy} $copyright_user$ &lt;$copyright_email$&gt;.
@@ -120,8 +120,8 @@ $$</snippet>
$$</snippet>
<snippet group="C++" trigger="liclgpl" id="license-lgpl" complement="" removed="false" modified="false">/**
@if ('%{CurrentProject:Name}' !== '')
** This file is part of the %{CurrentProject:Name} project.
@if ('%{CurrentDocument:Project:Name}' !== '')
** This file is part of the %{CurrentDocument:Project:Name} project.
@endif
@if ('%{Env:QTC_COPYRIGHT_USER}' === '' || '%{Env:QTC_COPYRIGHT_EMAIL}' === '')
** Copyright %{CurrentDate:yyyy} $copyright_user$ &lt;$copyright_email$&gt;.
@@ -153,7 +153,7 @@ $$</snippet>
@endif
** Contact: https://www.qt.io/licensing/
**
** This file is part of %{CurrentProject:Name}
** This file is part of %{CurrentDocument:Project:Name}
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in

View File

@@ -343,9 +343,10 @@ static QByteArray fullPrefix(const QByteArray &prefix)
* \sa registerVariables(), registerIntVariable(), registerFileVariables()
*/
void MacroExpander::registerPrefix(const QByteArray &prefix, const QString &description,
const MacroExpander::PrefixFunction &value)
const MacroExpander::PrefixFunction &value, bool visible)
{
QByteArray tmp = fullPrefix(prefix);
if (visible)
d->m_descriptions.insert(tmp + "<value>", description);
d->m_prefixMap.insert(tmp, value);
}

View File

@@ -68,7 +68,7 @@ public:
using IntFunction = std::function<int()>;
void registerPrefix(const QByteArray &prefix,
const QString &description, const PrefixFunction &value);
const QString &description, const PrefixFunction &value, bool visible = true);
void registerVariable(const QByteArray &variable,
const QString &description, const StringFunction &value,

View File

@@ -97,7 +97,7 @@ void ExecuteFilter::accept(LocatorFilterEntry selection,
bool found;
QString workingDirectory = Utils::globalMacroExpander()->value("CurrentDocument:Path", &found);
if (!found || workingDirectory.isEmpty())
workingDirectory = Utils::globalMacroExpander()->value("CurrentProject:Path", &found);
workingDirectory = Utils::globalMacroExpander()->value("CurrentDocument:Project:Path", &found);
ExecuteData d;
d.workingDirectory = workingDirectory;

View File

@@ -172,11 +172,18 @@ BuildConfiguration::BuildConfiguration(Target *target, Utils::Id id)
expander->registerVariable("buildDir", tr("Build directory"),
[this] { return buildDirectory().toUserOutput(); });
// TODO: Remove "Current" variants in ~4.16.
expander->registerVariable(Constants::VAR_CURRENTBUILD_NAME, tr("Name of current build"),
[this] { return displayName(); }, false);
expander->registerVariable("BuildConfig:Name", tr("Name of the build configuration"),
[this] { return displayName(); });
expander->registerPrefix(Constants::VAR_CURRENTBUILD_ENV,
tr("Variables in the current build environment"),
[this](const QString &var) { return environment().expandedValueForKey(var); }, false);
expander->registerPrefix("BuildConfig:Env",
tr("Variables in the build configuration's environment"),
[this](const QString &var) { return environment().expandedValueForKey(var); });
updateCacheAndEmitEnvironmentChanged();

View File

@@ -98,20 +98,30 @@ public:
for (KitAspect *aspect : KitManager::kitAspects())
aspect->addToMacroExpander(kit, &m_macroExpander);
// This provides the same global fall back as the global expander
// without relying on the currentKit() discovery process there.
m_macroExpander.registerVariable(Constants::VAR_CURRENTKIT_NAME,
// TODO: Remove the "Current" variants in ~4.16
m_macroExpander.registerVariable("CurrentKit:Name",
tr("The name of the currently active kit."),
[kit] { return kit->displayName(); },
false);
m_macroExpander.registerVariable(Constants::VAR_CURRENTKIT_FILESYSTEMNAME,
m_macroExpander.registerVariable("Kit:Name",
tr("The name of the kit."),
[kit] { return kit->displayName(); });
m_macroExpander.registerVariable("CurrentKit:FileSystemName",
tr("The name of the currently active kit in a filesystem-friendly version."),
[kit] { return kit->fileSystemFriendlyName(); },
false);
m_macroExpander.registerVariable(Constants::VAR_CURRENTKIT_ID,
m_macroExpander.registerVariable("Kit:FileSystemName",
tr("The name of the kit in a filesystem-friendly version."),
[kit] { return kit->fileSystemFriendlyName(); });
m_macroExpander.registerVariable("CurrentKit:Id",
tr("The id of the currently active kit."),
[kit] { return kit->id().toString(); },
false);
m_macroExpander.registerVariable("Kit:Id",
tr("The id of the kit."),
[kit] { return kit->id().toString(); });
}
DisplayName m_unexpandedDisplayName;

View File

@@ -84,7 +84,7 @@ KitManagerConfigWidget::KitManagerConfigWidget(Kit *k) :
tr("<html><head/><body><p>The name of the kit suitable for generating "
"directory names. This value is used for the variable <i>%1</i>, "
"which for example determines the name of the shadow build directory."
"</p></body></html>").arg(QLatin1String(Constants::VAR_CURRENTKIT_FILESYSTEMNAME));
"</p></body></html>").arg(QLatin1String("Kit:FileSystemName"));
m_fileSystemFriendlyNameLineEdit->setToolTip(toolTip);
QRegularExpression fileSystemFriendlyNameRegexp(QLatin1String("^[A-Za-z0-9_-]*$"));
Q_ASSERT(fileSystemFriendlyNameRegexp.isValid());

View File

@@ -258,7 +258,7 @@ const char FOLDER_OPEN_LOCATIONS_CONTEXT_MENU[] = "Project.F.OpenLocation.CtxMe
const char PROJECT_OPEN_LOCATIONS_CONTEXT_MENU[] = "Project.P.OpenLocation.CtxMenu";
// Default directories:
const char DEFAULT_BUILD_DIRECTORY_TEMPLATE[] = "../%{JS: Util.asciify(\"build-%{CurrentProject:Name}-%{CurrentKit:FileSystemName}-%{CurrentBuild:Name}\")}";
const char DEFAULT_BUILD_DIRECTORY_TEMPLATE[] = "../%{JS: Util.asciify(\"build-%{Project:Name}-%{Kit:FileSystemName}-%{BuildConfig:Name}\")}";
const char DEFAULT_BUILD_DIRECTORY_TEMPLATE_KEY[] = "Directories/BuildDirectory.Template";
const char BUILD_BEFORE_DEPLOY_SETTINGS_KEY[] = "ProjectExplorer/Settings/BuildBeforeDeploy";
@@ -332,18 +332,6 @@ static BuildConfiguration *activeBuildConfiguration()
return target ? target->activeBuildConfiguration() : nullptr;
}
static RunConfiguration *activeRunConfiguration()
{
Target *target = activeTarget();
return target ? target->activeRunConfiguration() : nullptr;
}
static Kit *currentKit()
{
Target *target = activeTarget();
return target ? target->kit() : nullptr;
}
static bool isTextFile(const QString &fileName)
{
return Utils::mimeTypeForFile(fileName).inherits(
@@ -1543,10 +1531,18 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
= s->value(Constants::ABORT_BUILD_ALL_ON_ERROR_SETTINGS_KEY, true).toBool();
dd->m_projectExplorerSettings.lowBuildPriority
= s->value(Constants::LOW_BUILD_PRIORITY_SETTINGS_KEY, false).toBool();
dd->m_buildPropertiesSettings.buildDirectoryTemplate
= s->value(Constants::DEFAULT_BUILD_DIRECTORY_TEMPLATE_KEY).toString();
if (dd->m_buildPropertiesSettings.buildDirectoryTemplate.isEmpty())
dd->m_buildPropertiesSettings.buildDirectoryTemplate = Constants::DEFAULT_BUILD_DIRECTORY_TEMPLATE;
// TODO: Remove in ~4.16
dd->m_buildPropertiesSettings.buildDirectoryTemplate.replace("%{CurrentProject:Name}",
"%{Project:Name}");
dd->m_buildPropertiesSettings.buildDirectoryTemplate.replace("%{CurrentKit:FileSystemName}",
"%{Kit:FileSystemName}");
dd->m_buildPropertiesSettings.buildDirectoryTemplate.replace("%{CurrentBuild:Name}",
"%{BuildConfig:Name}");
const auto loadTriStateValue = [&s](const QString &key) {
return TriState::fromVariant(s->value(key, TriState::Default.toVariant()));
@@ -1745,6 +1741,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
// FIXME: These are mostly "legacy"/"convenience" entries, relying on
// the global entry point ProjectExplorer::currentProject(). They should
// not be used in the Run/Build configuration pages.
// TODO: Remove the CurrentProject versions in ~4.16
Utils::MacroExpander *expander = Utils::globalMacroExpander();
expander->registerFileVariables(Constants::VAR_CURRENTPROJECT_PREFIX,
tr("Current project's main file."),
@@ -1753,115 +1750,39 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
if (Project *project = ProjectTree::currentProject())
projectFilePath = project->projectFilePath();
return projectFilePath.toString();
});
expander->registerVariable("CurrentProject:BuildPath",
tr("Full build path of the current project's active build configuration."),
}, false);
expander->registerFileVariables("CurrentDocument:Project",
tr("Main file of the project the current document belongs to."),
[]() -> QString {
BuildConfiguration *bc = activeBuildConfiguration();
return bc ? bc->buildDirectory().toUserOutput() : QString();
});
Utils::FilePath projectFilePath;
if (Project *project = ProjectTree::currentProject())
projectFilePath = project->projectFilePath();
return projectFilePath.toString();
}, false);
expander->registerVariable(Constants::VAR_CURRENTPROJECT_NAME,
tr("The name of the current project."),
[]() -> QString {
Project *project = ProjectTree::currentProject();
return project ? project->displayName() : QString();
});
expander->registerVariable(Constants::VAR_CURRENTKIT_NAME,
tr("The name of the currently active kit."),
}, false);
expander->registerVariable("CurrentDocument:Project:Name",
tr("The name of the project the current document belongs to."),
[]() -> QString {
Kit *kit = currentKit();
return kit ? kit->displayName() : QString();
});
expander->registerVariable(Constants::VAR_CURRENTKIT_FILESYSTEMNAME,
tr("The name of the currently active kit as a filesystem-friendly version."),
[]() -> QString {
Kit *kit = currentKit();
return kit ? kit->fileSystemFriendlyName() : QString();
});
expander->registerVariable(Constants::VAR_CURRENTKIT_ID,
tr("The ID of the currently active kit."),
[]() -> QString {
Kit *kit = currentKit();
return kit ? kit->id().toString() : QString();
});
expander->registerVariable("CurrentDevice:HostAddress",
tr("The host address of the device in the currently active kit."),
[]() -> QString {
Kit *kit = currentKit();
const IDevice::ConstPtr device = DeviceKitAspect::device(kit);
return device ? device->sshParameters().host() : QString();
});
expander->registerVariable("CurrentDevice:SshPort",
tr("The SSH port of the device in the currently active kit."),
[]() -> QString {
Kit *kit = currentKit();
const IDevice::ConstPtr device = DeviceKitAspect::device(kit);
return device ? QString::number(device->sshParameters().port()) : QString();
});
expander->registerVariable("CurrentDevice:UserName",
tr("The username with which to log into the device in the currently active kit."),
[]() -> QString {
Kit *kit = currentKit();
const IDevice::ConstPtr device = DeviceKitAspect::device(kit);
return device ? device->sshParameters().userName() : QString();
});
expander->registerVariable("CurrentDevice:PrivateKeyFile",
tr("The private key file with which to authenticate when logging into the device "
"in the currently active kit."),
[]() -> QString {
Kit *kit = currentKit();
const IDevice::ConstPtr device = DeviceKitAspect::device(kit);
return device ? device->sshParameters().privateKeyFile : QString();
});
expander->registerVariable(Constants::VAR_CURRENTBUILD_NAME,
tr("The currently active build configuration's name."),
[&]() -> QString {
BuildConfiguration *bc = activeBuildConfiguration();
return bc ? bc->displayName() : QString();
});
expander->registerVariable(Constants::VAR_CURRENTRUN_NAME,
tr("The currently active run configuration's name."),
[]() -> QString {
if (Target *target = activeTarget()) {
if (RunConfiguration *rc = target->activeRunConfiguration())
return rc->displayName();
}
return QString();
});
expander->registerFileVariables("CurrentRun:Executable",
tr("The currently active run configuration's executable (if applicable)."),
[]() -> QString {
if (Target *target = activeTarget()) {
if (RunConfiguration *rc = target->activeRunConfiguration())
return rc->commandLine().executable().toString();
}
return QString();
});
expander->registerVariable(Constants::VAR_CURRENTBUILD_TYPE,
tr("The currently active build configuration's type."),
[&]() -> QString {
BuildConfiguration *bc = activeBuildConfiguration();
const BuildConfiguration::BuildType type
= bc ? bc->buildType() : BuildConfiguration::Unknown;
return BuildConfiguration::buildTypeName(type);
Project *project = ProjectTree::currentProject();
return project ? project->displayName() : QString();
});
expander->registerPrefix(Constants::VAR_CURRENTBUILD_ENV,
BuildConfiguration::tr("Variables in the current build environment"),
[](const QString &var) {
if (BuildConfiguration *bc = activeBuildConfiguration())
return bc->environment().expandedValueForKey(var);
return QString();
}, false);
expander->registerPrefix("CurrentDocument:Project:BuildConfig:Env",
BuildConfiguration::tr("Variables in the active build environment "
"of the project containing the currently open document"),
[](const QString &var) {
if (BuildConfiguration *bc = activeBuildConfiguration())
return bc->environment().expandedValueForKey(var);
@@ -1874,24 +1795,21 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
return bc->environment();
return Utils::Environment::systemEnvironment();
}});
Utils::EnvironmentProvider::addProvider(
{"CurrentRun:Env", tr("Current Run Environment"), []() {
if (RunConfiguration *rc = activeRunConfiguration())
if (auto envAspect = rc->aspect<EnvironmentAspect>())
return envAspect->environment();
{"CurrentDocument:Project:BuildConfig:Env", tr("Current Build Environment"), []() {
if (BuildConfiguration *bc = activeBuildConfiguration())
return bc->environment();
return Utils::Environment::systemEnvironment();
}});
QString fileDescription = tr("File where current session is saved.");
auto fileHandler = [] { return SessionManager::sessionNameToFileName(SessionManager::activeSession()).toString(); };
expander->registerFileVariables("Session", fileDescription, fileHandler);
expander->registerFileVariables("CurrentSession", fileDescription, fileHandler, false);
QString nameDescription = tr("Name of current session.");
auto nameHandler = [] { return SessionManager::activeSession(); };
expander->registerVariable("Session:Name", nameDescription, nameHandler);
expander->registerVariable("CurrentSession:Name", nameDescription, nameHandler, false);
const auto fileHandler = [] {
return SessionManager::sessionNameToFileName(SessionManager::activeSession()).toString();
};
expander->registerFileVariables("Session", tr("File where current session is saved."),
fileHandler);
expander->registerVariable("Session:Name", tr("Name of current session."), [] {
return SessionManager::activeSession();
});
return true;
}

View File

@@ -189,14 +189,8 @@ const char ANDROID_ABI_X86_64[] = "x86_64";
// Variable Names:
const char VAR_CURRENTPROJECT_PREFIX[] = "CurrentProject";
const char VAR_CURRENTPROJECT_NAME[] = "CurrentProject:Name";
const char VAR_CURRENTKIT_NAME[] = "CurrentKit:Name";
const char VAR_CURRENTKIT_FILESYSTEMNAME[] = "CurrentKit:FileSystemName";
const char VAR_CURRENTKIT_ID[] = "CurrentKit:Id";
const char VAR_CURRENTBUILD_NAME[] = "CurrentBuild:Name";
const char VAR_CURRENTBUILD_TYPE[] = "CurrentBuild:Type";
const char VAR_CURRENTBUILD_ENV[] = "CurrentBuild:Env";
const char VAR_CURRENTRUN_NAME[] = "CurrentRun:Name";
const char VAR_CURRENTRUN_WORKINGDIR[] = "CurrentRun:WorkingDir";
// JsonWizard:
const char PAGE_ID_PREFIX[] = "PE.Wizard.Page.";

View File

@@ -33,22 +33,33 @@ ProjectMacroExpander::ProjectMacroExpander(const Utils::FilePath &mainFilePath,
const Kit *kit, const QString &bcName,
BuildConfiguration::BuildType buildType)
{
// TODO: Remove "Current" variants in ~4.16
registerFileVariables(Constants::VAR_CURRENTPROJECT_PREFIX,
QCoreApplication::translate("ProjectExplorer", "Main file of current project"),
[mainFilePath] { return mainFilePath.toString(); }, false);
registerFileVariables("Project",
QCoreApplication::translate("ProjectExplorer", "Main file of the project"),
[mainFilePath] { return mainFilePath.toString(); });
registerVariable(Constants::VAR_CURRENTPROJECT_NAME,
QCoreApplication::translate("ProjectExplorer", "Name of current project"),
[projectName] { return projectName; }, false);
registerVariable("Project:Name",
QCoreApplication::translate("ProjectExplorer", "Name of the project"),
[projectName] { return projectName; });
registerVariable(Constants::VAR_CURRENTBUILD_NAME,
QCoreApplication::translate("ProjectExplorer", "Name of current build"),
[bcName] { return bcName; }, false);
registerVariable("BuildConfig:Name",
QCoreApplication::translate(
"ProjectExplorer", "Name of the project's active build configuration"),
[bcName] { return bcName; });
registerVariable(Constants::VAR_CURRENTBUILD_TYPE,
registerVariable("CurrentBuild:Type",
QCoreApplication::translate("ProjectExplorer", "Type of current build"),
[buildType] { return BuildConfiguration::buildTypeName(buildType); }, false);
registerVariable("BuildConfig:Type",
QCoreApplication::translate(
"ProjectExplorer", "Type of the project's active build configuration"),
[buildType] { return BuildConfiguration::buildTypeName(buildType); });
registerSubProvider([kit] { return kit->macroExpander(); });
}

View File

@@ -177,23 +177,6 @@ RunConfiguration::RunConfiguration(Target *target, Utils::Id id)
BuildConfiguration *bc = target->activeBuildConfiguration();
return bc ? bc->macroExpander() : target->macroExpander();
});
m_expander.registerPrefix("CurrentRun:Env", tr("Variables in the current run environment"),
[this](const QString &var) {
const auto envAspect = aspect<EnvironmentAspect>();
return envAspect ? envAspect->environment().expandedValueForKey(var) : QString();
});
m_expander.registerVariable(Constants::VAR_CURRENTRUN_WORKINGDIR,
tr("The currently active run configuration's working directory"),
[this] {
const auto wdAspect = aspect<WorkingDirectoryAspect>();
return wdAspect ? wdAspect->workingDirectory(&m_expander).toString() : QString();
});
m_expander.registerVariable(Constants::VAR_CURRENTRUN_NAME,
QCoreApplication::translate("ProjectExplorer", "The currently active run configuration's name."),
[this] { return displayName(); }, false);
m_commandLineGetter = [this] {
FilePath executable;
if (const auto executableAspect = aspect<ExecutableAspect>())

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()

View File

@@ -47,14 +47,12 @@
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projecttree.h>
#include <projectexplorer/runcontrol.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
#include <utils/infobar.h>
#include <utils/macroexpander.h>
const char kHostBins[] = "CurrentProject:QT_HOST_BINS";
const char kInstallBins[] = "CurrentProject:QT_INSTALL_BINS";
using namespace Core;
using namespace ProjectExplorer;
@@ -107,15 +105,6 @@ bool QtSupportPlugin::initialize(const QStringList &arguments, QString *errorMes
return true;
}
static BaseQtVersion *qtVersion()
{
ProjectExplorer::Project *project = ProjectExplorer::ProjectTree::currentProject();
if (!project || !project->activeTarget())
return nullptr;
return QtKitAspect::qtVersion(project->activeTarget()->kit());
}
const char kLinkWithQtInstallationSetting[] = "LinkWithQtInstallation";
static void askAboutQtInstallation()
@@ -144,21 +133,55 @@ void QtSupportPlugin::extensionsInitialized()
{
Utils::MacroExpander *expander = Utils::globalMacroExpander();
static const auto currentQtVersion = []() -> const BaseQtVersion * {
ProjectExplorer::Project *project = ProjectExplorer::ProjectTree::currentProject();
if (!project || !project->activeTarget())
return nullptr;
return QtKitAspect::qtVersion(project->activeTarget()->kit());
};
static const char kCurrentHostBins[] = "CurrentDocument:Project:QT_HOST_BINS";
expander->registerVariable(
kHostBins,
tr("Full path to the host bin directory of the current project's Qt version."),
kCurrentHostBins,
tr("Full path to the host bin directory of the Qt version in the active kit "
"of the project containing the current document."),
[]() {
BaseQtVersion *qt = qtVersion();
const BaseQtVersion * const qt = currentQtVersion();
return qt ? qt->hostBinPath().toUserOutput() : QString();
});
expander->registerVariable(
kInstallBins,
tr("Full path to the target bin directory of the current project's Qt version.<br>"
"You probably want %1 instead.")
.arg(QString::fromLatin1(kInstallBins)),
"CurrentDocument:Project:QT_INSTALL_BINS",
tr("Full path to the target bin directory of the Qt version in the active kit "
"of the project containing the current document.<br>You probably want %1 instead.")
.arg(QString::fromLatin1(kCurrentHostBins)),
[]() {
BaseQtVersion *qt = qtVersion();
const BaseQtVersion * const qt = currentQtVersion();
return qt ? qt->binPath().toUserOutput() : QString();
});
static const auto activeQtVersion = []() -> const BaseQtVersion * {
ProjectExplorer::Project *project = SessionManager::startupProject();
if (!project || !project->activeTarget())
return nullptr;
return QtKitAspect::qtVersion(project->activeTarget()->kit());
};
static const char kActiveHostBins[] = "ActiveProject:QT_HOST_BINS";
expander->registerVariable(
kActiveHostBins,
tr("Full path to the host bin directory of the Qt version in the active kit "
"of the active project."),
[]() {
const BaseQtVersion * const qt = activeQtVersion();
return qt ? qt->hostBinPath().toUserOutput() : QString();
});
expander->registerVariable(
"ActiveProject:QT_INSTALL_BINS",
tr("Full path to the target bin directory of the Qt version in the active kit "
"of the active project.<br>You probably want %1 instead.")
.arg(QString::fromLatin1(kActiveHostBins)),
[]() {
const BaseQtVersion * const qt = activeQtVersion();
return qt ? qt->binPath().toUserOutput() : QString();
});

View File

@@ -42,9 +42,9 @@ const char VCS_ID_SUBVERSION[] = "J.Subversion";
const char VCS_ID_PERFORCE[] = "P.Perforce";
const char VCS_ID_CVS[] = "Z.CVS";
const char VAR_VCS_NAME[] = "CurrentProject:VcsName";
const char VAR_VCS_TOPIC[] = "CurrentProject:VcsTopic";
const char VAR_VCS_TOPLEVELPATH[] = "CurrentProject:VcsTopLevelPath";
const char VAR_VCS_NAME[] = "CurrentDocument:Project:VcsName";
const char VAR_VCS_TOPIC[] = "CurrentDocument:Project:VcsTopic";
const char VAR_VCS_TOPLEVELPATH[] = "CurrentDocument:Project:VcsTopLevelPath";
} // namespace Constants
} // namespace VcsBase

View File

@@ -32,10 +32,10 @@
<category>Linguist</category>
<order>2</order>
<executable>
<path>%{CurrentProject:QT_INSTALL_BINS}/lrelease</path>
<path>%{CurrentDocument:Project:QT_INSTALL_BINS}/lrelease</path>
<path>lrelease</path>
<arguments>%{CurrentProject:FilePath}</arguments>
<workingdirectory>%{CurrentProject:Path}</workingdirectory>
<baseEnvironmentId>CurrentBuild:Env</baseEnvironmentId>
<arguments>%{CurrentDocument:Project:FilePath}</arguments>
<workingdirectory>%{CurrentDocument:Project:Path}</workingdirectory>
<baseEnvironmentId>CurrentDocument:Project:BuildConfig:Env</baseEnvironmentId>
</executable>
</externaltool>

View File

@@ -32,10 +32,10 @@
<category>Linguist</category>
<order>1</order>
<executable>
<path>%{CurrentProject:QT_INSTALL_BINS}/lupdate</path>
<path>%{CurrentDocument:Project:QT_INSTALL_BINS}/lupdate</path>
<path>lupdate</path>
<arguments>%{CurrentProject:FilePath}</arguments>
<workingdirectory>%{CurrentProject:Path}</workingdirectory>
<baseEnvironmentId>CurrentBuild:Env</baseEnvironmentId>
<arguments>%{CurrentDocument:Project:FilePath}</arguments>
<workingdirectory>%{CurrentDocument:Project:Path}</workingdirectory>
<baseEnvironmentId>CurrentDocument:Project:BuildConfig:Env</baseEnvironmentId>
</executable>
</externaltool>

View File

@@ -32,7 +32,7 @@
<category>Qt Quick</category>
<order>1</order>
<executable>
<path>%{CurrentProject:QT_INSTALL_BINS}/qmlscene</path>
<path>%{CurrentDocument:Project:QT_INSTALL_BINS}/qmlscene</path>
<path>qmlscene</path>
<arguments>%{CurrentDocument:FilePath}</arguments>
<workingdirectory>%{CurrentDocument:Path}</workingdirectory>

View File

@@ -32,7 +32,7 @@
<category>Qt Quick</category>
<order>1</order>
<executable>
<path>%{CurrentProject:QT_INSTALL_BINS}/qmlviewer</path>
<path>%{CurrentDocument:Project:QT_INSTALL_BINS}/qmlviewer</path>
<path>qmlviewer</path>
<arguments>%{CurrentDocument:FilePath}</arguments>
<workingdirectory>%{CurrentDocument:Path}</workingdirectory>