diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index ff3244c4620..6aa5d51b40a 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -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); } } diff --git a/src/plugins/projectexplorer/projectmacroexpander.cpp b/src/plugins/projectexplorer/projectmacroexpander.cpp index b1c4a7fcf0a..978b7678111 100644 --- a/src/plugins/projectexplorer/projectmacroexpander.cpp +++ b/src/plugins/projectexplorer/projectmacroexpander.cpp @@ -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; +} diff --git a/src/plugins/projectexplorer/projectmacroexpander.h b/src/plugins/projectexplorer/projectmacroexpander.h index eb5d51f3e36..46181c228d7 100644 --- a/src/plugins/projectexplorer/projectmacroexpander.h +++ b/src/plugins/projectexplorer/projectmacroexpander.h @@ -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: