Commit ec4a1014 authored by Eike Ziller's avatar Eike Ziller
Browse files

Avoid duplication of projectexplorer's variable handling.



Change-Id: I5a5c41448d521af5aa60b92b804c8fd965b90906
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 61bcb380
......@@ -35,6 +35,7 @@
#include "gcctoolchainfactories.h"
#include "project.h"
#include "projectexplorersettings.h"
#include "projectmacroexpander.h"
#include "removetaskhandler.h"
#include "kitmanager.h"
#include "kitoptionspage.h"
......@@ -1144,52 +1145,13 @@ void ProjectExplorerPlugin::loadCustomWizards()
void ProjectExplorerPlugin::updateVariable(const QByteArray &variable)
{
if (variable == Constants::VAR_CURRENTPROJECT_FILEPATH) {
if (currentProject() && currentProject()->document()) {
Core::VariableManager::instance()->insert(variable,
currentProject()->document()->fileName());
} else {
Core::VariableManager::instance()->remove(variable);
}
} else if (variable == Constants::VAR_CURRENTPROJECT_PATH) {
if (currentProject() && currentProject()->document()) {
Core::VariableManager::instance()->insert(variable,
QFileInfo(currentProject()->document()->fileName()).path());
} else {
Core::VariableManager::instance()->remove(variable);
}
} else if (variable == Constants::VAR_CURRENTPROJECT_BUILDPATH) {
if (variable == Constants::VAR_CURRENTPROJECT_BUILDPATH) {
if (currentProject() && currentProject()->activeTarget() && currentProject()->activeTarget()->activeBuildConfiguration()) {
Core::VariableManager::instance()->insert(variable,
currentProject()->activeTarget()->activeBuildConfiguration()->buildDirectory());
} else {
Core::VariableManager::instance()->remove(variable);
}
} else if (variable == Constants::VAR_CURRENTPROJECT_NAME) {
if (currentProject())
Core::VariableManager::instance()->insert(variable, currentProject()->displayName());
else
Core::VariableManager::instance()->remove(variable);
} else if (variable == Constants::VAR_CURRENTKIT_NAME) {
if (currentProject() && currentProject()->activeTarget() && currentProject()->activeTarget()->kit())
Core::VariableManager::instance()->insert(variable, currentProject()->activeTarget()->kit()->displayName());
else
Core::VariableManager::instance()->remove(variable);
} else if (variable == Constants::VAR_CURRENTKIT_FILESYSTEMNAME) {
if (currentProject() && currentProject()->activeTarget() && currentProject()->activeTarget()->kit())
Core::VariableManager::instance()->insert(variable, currentProject()->activeTarget()->kit()->fileSystemFriendlyName());
else
Core::VariableManager::instance()->remove(variable);
} else if (variable == Constants::VAR_CURRENTKIT_ID) {
if (currentProject() && currentProject()->activeTarget() && currentProject()->activeTarget()->kit())
Core::VariableManager::instance()->insert(variable, currentProject()->activeTarget()->kit()->id().toString());
else
Core::VariableManager::instance()->remove(variable);
} else if (variable == Constants::VAR_CURRENTBUILD_NAME) {
if (currentProject() && currentProject()->activeTarget() && currentProject()->activeTarget()->activeBuildConfiguration())
Core::VariableManager::instance()->insert(variable, currentProject()->activeTarget()->activeBuildConfiguration()->displayName());
else
Core::VariableManager::instance()->remove(variable);
} else if (variable == Constants::VAR_CURRENTBUILD_TYPE) {
if (currentProject() && currentProject()->activeTarget() && currentProject()->activeTarget()->activeBuildConfiguration()) {
BuildConfiguration::BuildType type = currentProject()->activeTarget()->activeBuildConfiguration()->buildType();
......@@ -1204,6 +1166,28 @@ void ProjectExplorerPlugin::updateVariable(const QByteArray &variable)
} else {
Core::VariableManager::instance()->remove(variable);
}
} else {
QString projectName;
QString projectFilePath;
Kit *kit = 0;
QString buildConfigurationName;
if (Project *project = currentProject()) {
projectName = project->displayName();
if (Core::IDocument *doc = project->document())
projectFilePath = doc->fileName();
if (Target *target = project->activeTarget()) {
kit = target->kit();
if (BuildConfiguration *buildConfiguration = target->activeBuildConfiguration()) {
buildConfigurationName = buildConfiguration->displayName();
}
}
}
ProjectExpander expander(projectFilePath, projectName, kit, buildConfigurationName);
QString result;
if (expander.resolveProjectMacro(QString::fromUtf8(variable), &result))
Core::VariableManager::instance()->insert(variable, result);
else
Core::VariableManager::instance()->remove(variable);
}
}
......
......@@ -40,19 +40,25 @@ ProjectExpander::ProjectExpander(const QString &projectFilePath, const QString &
: m_projectFile(projectFilePath), m_projectName(projectName), m_kit(k), m_bcName(bcName)
{ }
bool ProjectExpander::resolveMacro(const QString &name, QString *ret)
bool ProjectExpander::resolveProjectMacro(const QString &name, QString *ret)
{
QString result;
bool found = false;
if (name == QLatin1String(ProjectExplorer::Constants::VAR_CURRENTPROJECT_NAME)) {
result = m_projectName;
found = true;
if (!m_projectName.isEmpty()) {
result = m_projectName;
found = true;
}
} else if (name == QLatin1String(ProjectExplorer::Constants::VAR_CURRENTPROJECT_PATH)) {
result = m_projectFile.absolutePath();
found = true;
if (!m_projectFile.filePath().isEmpty()) {
result = m_projectFile.absolutePath();
found = true;
}
} else if (name == QLatin1String(ProjectExplorer::Constants::VAR_CURRENTPROJECT_FILEPATH)) {
result = m_projectFile.absoluteFilePath();
found = true;
if (!m_projectFile.filePath().isEmpty()) {
result = m_projectFile.absoluteFilePath();
found = true;
}
} else if (m_kit && name == QLatin1String(ProjectExplorer::Constants::VAR_CURRENTKIT_NAME)) {
result = m_kit->displayName();
found = true;
......@@ -65,10 +71,19 @@ bool ProjectExpander::resolveMacro(const QString &name, QString *ret)
} else if (name == QLatin1String(ProjectExplorer::Constants::VAR_CURRENTBUILD_NAME)) {
result = m_bcName;
found = true;
} else {
result = Core::VariableManager::instance()->value(name.toUtf8(), &found);
}
if (ret)
*ret = result;
return found;
}
bool ProjectExpander::resolveMacro(const QString &name, QString *ret)
{
bool found = resolveProjectMacro(name, ret);
if (!found) {
QString result = Core::VariableManager::instance()->value(name.toUtf8(), &found);
if (ret)
*ret = result;
}
return found;
}
......@@ -41,6 +41,7 @@ class PROJECTEXPLORER_EXPORT ProjectExpander : public Utils::AbstractQtcMacroExp
{
public:
ProjectExpander(const QString &projectFilePath, const QString &projectName, const Kit *k, const QString &bcName);
bool resolveProjectMacro(const QString &name, QString *ret);
bool resolveMacro(const QString &name, QString *ret);
private:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment