summaryrefslogtreecommitdiff
path: root/src/plugins/projectexplorer
diff options
context:
space:
mode:
authorhjk <hjk121@nokiamail.com>2014-06-23 16:57:56 +0200
committerhjk <hjk121@nokiamail.com>2014-06-24 15:25:56 +0200
commit2982a763ac69043400e624c2c199344be2b2ba6f (patch)
tree883241797f1fdf78a946835139d9552026d3d17c /src/plugins/projectexplorer
parent000fbe63bcfee71605c485645ca4b337f71737be (diff)
downloadqt-creator-2982a763ac69043400e624c2c199344be2b2ba6f.tar.gz
Variables: Use lambdas as callbacks to resolve variables
Instead of broadcasting for each resolution we ask the code that knows about a specific variable directly. Change-Id: I2f0f4f2acceba85a236995d236980594a3166bd8 Reviewed-by: Eike Ziller <eike.ziller@digia.com> Reviewed-by: Daniel Teske <daniel.teske@digia.com>
Diffstat (limited to 'src/plugins/projectexplorer')
-rw-r--r--src/plugins/projectexplorer/projectexplorer.cpp176
-rw-r--r--src/plugins/projectexplorer/projectexplorer.h1
-rw-r--r--src/plugins/projectexplorer/projectmacroexpander.cpp9
-rw-r--r--src/plugins/projectexplorer/projectmacroexpander.h3
4 files changed, 101 insertions, 88 deletions
diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp
index 9c166eb152..73f586b9b2 100644
--- a/src/plugins/projectexplorer/projectexplorer.cpp
+++ b/src/plugins/projectexplorer/projectexplorer.cpp
@@ -164,6 +164,18 @@ using namespace Core;
namespace ProjectExplorer {
+static Target *activeTarget()
+{
+ Project *project = ProjectExplorerPlugin::currentProject();
+ return project ? project->activeTarget() : 0;
+}
+
+static BuildConfiguration *activeBuildConfiguration()
+{
+ Target *target = activeTarget();
+ return target ? target->activeBuildConfiguration() : 0;
+}
+
struct ProjectExplorerPluginPrivate {
ProjectExplorerPluginPrivate();
@@ -323,6 +335,25 @@ bool ProjectExplorerPlugin::parseArguments(const QStringList &arguments, QString
return true;
}
+static QString variableValue(const char *variable)
+{
+ QString projectName;
+ QString projectFilePath;
+ Kit *kit = 0;
+ QString buildConfigurationName;
+ if (Project *project = ProjectExplorerPlugin::currentProject()) {
+ projectName = project->displayName();
+ if (IDocument *doc = project->document())
+ projectFilePath = doc->filePath();
+ if (BuildConfiguration *buildConfiguration = activeBuildConfiguration())
+ buildConfigurationName = buildConfiguration->displayName();
+ }
+ ProjectMacroExpander expander(projectFilePath, projectName, kit, buildConfigurationName);
+ QString result;
+ expander.resolveProjectMacro(QString::fromUtf8(variable), &result);
+ return result;
+}
+
bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *error)
{
qRegisterMetaType<ProjectExplorer::RunControl *>();
@@ -1016,30 +1047,80 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
updateWelcomePage();
- VariableManager::registerFileVariables(Constants::VAR_CURRENTPROJECT_PREFIX, tr("Current project's main file"));
+ VariableManager::registerFileVariables(Constants::VAR_CURRENTPROJECT_PREFIX,
+ tr("Current project's main file"),
+ []() {
+ QString projectFilePath;
+ if (Project *project = ProjectExplorerPlugin::currentProject())
+ if (IDocument *doc = project->document())
+ projectFilePath = doc->filePath();
+ return projectFilePath;
+ });
+
VariableManager::registerVariable(Constants::VAR_CURRENTPROJECT_BUILDPATH,
- tr("Full build path of the current project's active build configuration."));
- VariableManager::registerVariable(Constants::VAR_CURRENTPROJECT_NAME, tr("The current project's name."));
- VariableManager::registerVariable(Constants::VAR_CURRENTKIT_NAME, tr("The currently active kit's name."));
+ tr("Full build path of the current project's active build configuration."),
+ []() -> QString {
+ BuildConfiguration *bc = activeBuildConfiguration();
+ return bc ? bc->buildDirectory().toUserOutput() : QString();
+ });
+
+ VariableManager::registerVariable(Constants::VAR_CURRENTPROJECT_NAME,
+ tr("The current project's name."),
+ []() -> QString { return variableValue(Constants::VAR_CURRENTPROJECT_NAME); });
+
+ VariableManager::registerVariable(Constants::VAR_CURRENTKIT_NAME,
+ tr("The currently active kit's name."),
+ []() -> QString { return variableValue(Constants::VAR_CURRENTKIT_NAME); });
+
VariableManager::registerVariable(Constants::VAR_CURRENTKIT_FILESYSTEMNAME,
- tr("The currently active kit's name in a filesystem friendly version."));
- VariableManager::registerVariable(Constants::VAR_CURRENTKIT_ID, tr("The currently active kit's id."));
+ tr("The currently active kit's name in a filesystem friendly version."),
+ []() -> QString { return variableValue(Constants::VAR_CURRENTKIT_FILESYSTEMNAME); });
+
+ VariableManager::registerVariable(Constants::VAR_CURRENTKIT_ID,
+ tr("The currently active kit's id."),
+ []() -> QString { return variableValue(Constants::VAR_CURRENTKIT_ID); });
+
VariableManager::registerVariable(Constants::VAR_CURRENTDEVICE_HOSTADDRESS,
- tr("The host address of the device in the currently active kit."));
+ tr("The host address of the device in the currently active kit."),
+ []() -> QString { return variableValue(Constants::VAR_CURRENTDEVICE_HOSTADDRESS); });
+
VariableManager::registerVariable(Constants::VAR_CURRENTDEVICE_SSHPORT,
- tr("The SSH port of the device in the currently active kit."));
+ tr("The SSH port of the device in the currently active kit."),
+ []() -> QString { return variableValue(Constants::VAR_CURRENTDEVICE_SSHPORT); });
+
VariableManager::registerVariable(Constants::VAR_CURRENTDEVICE_USERNAME,
- tr("The user name with which to log into the device in the currently active kit."));
+ tr("The user name with which to log into the device in the currently active kit."),
+ []() -> QString { return variableValue(Constants::VAR_CURRENTDEVICE_USERNAME); });
+
VariableManager::registerVariable(Constants::VAR_CURRENTDEVICE_PRIVATEKEYFILE,
- tr("The private key file with which to authenticate when logging into the device "
- "in the currently active kit."));
- VariableManager::registerVariable(Constants::VAR_CURRENTBUILD_NAME, tr("The currently active build configuration's name."));
- VariableManager::registerVariable(Constants::VAR_CURRENTBUILD_TYPE, tr("The currently active build configuration's type."));
- VariableManager::registerFileVariables(Constants::VAR_CURRENTSESSION_PREFIX, tr("File where current session is saved."));
- VariableManager::registerVariable(Constants::VAR_CURRENTSESSION_NAME, tr("Name of current session."));
+ tr("The private key file with which to authenticate when logging into the device "
+ "in the currently active kit."),
+ []() -> QString { return variableValue(Constants::VAR_CURRENTDEVICE_PRIVATEKEYFILE); });
+
+ VariableManager::registerVariable(Constants::VAR_CURRENTBUILD_NAME,
+ tr("The currently active build configuration's name."),
+ []() -> QString { return variableValue(Constants::VAR_CURRENTBUILD_NAME); });
+
+ VariableManager::registerVariable(Constants::VAR_CURRENTBUILD_TYPE,
+ tr("The currently active build configuration's type."),
+ []() -> QString {
+ if (BuildConfiguration *bc = activeBuildConfiguration()) {
+ BuildConfiguration::BuildType type = bc->buildType();
+ if (type == BuildConfiguration::Debug)
+ return tr("debug");
+ if (type == BuildConfiguration::Release)
+ return tr("release");
+ }
+ return tr("unknown");
+ });
- connect(VariableManager::instance(), SIGNAL(variableUpdateRequested(QByteArray)),
- this, SLOT(updateVariable(QByteArray)));
+ VariableManager::registerFileVariables(Constants::VAR_CURRENTSESSION_PREFIX,
+ tr("File where current session is saved."),
+ []() -> QString { return SessionManager::sessionNameToFileName(SessionManager::activeSession()).toString(); });
+
+ VariableManager::registerVariable(Constants::VAR_CURRENTSESSION_NAME,
+ tr("Name of current session."),
+ []() -> QString { return SessionManager::activeSession(); });
return true;
}
@@ -1154,67 +1235,6 @@ void ProjectExplorerPlugin::loadCustomWizards()
}
}
-void ProjectExplorerPlugin::updateVariable(const QByteArray &variable)
-{
- if (variable == Constants::VAR_CURRENTPROJECT_BUILDPATH) {
- if (currentProject() && currentProject()->activeTarget() && currentProject()->activeTarget()->activeBuildConfiguration()) {
- VariableManager::insert(variable,
- currentProject()->activeTarget()->activeBuildConfiguration()->buildDirectory().toUserOutput());
- } else {
- VariableManager::remove(variable);
- }
- } else if (variable == Constants::VAR_CURRENTBUILD_TYPE) {
- if (currentProject() && currentProject()->activeTarget() && currentProject()->activeTarget()->activeBuildConfiguration()) {
- BuildConfiguration::BuildType type = currentProject()->activeTarget()->activeBuildConfiguration()->buildType();
- QString typeString;
- if (type == BuildConfiguration::Debug)
- typeString = tr("debug");
- else if (type == BuildConfiguration::Release)
- typeString = tr("release");
- else
- typeString = tr("unknown");
- VariableManager::insert(variable, typeString);
- } else {
- VariableManager::remove(variable);
- }
- } else if (variable == Constants::VAR_CURRENTSESSION_NAME) {
- if (!SessionManager::activeSession().isEmpty())
- VariableManager::insert(variable, SessionManager::activeSession());
- else
- VariableManager::remove(variable);
- } else if (Core::VariableManager::isFileVariable(
- variable, ProjectExplorer::Constants::VAR_CURRENTSESSION_PREFIX)) {
- if (!SessionManager::activeSession().isEmpty()) {
- VariableManager::insert(variable, Core::VariableManager::fileVariableValue(variable,
- ProjectExplorer::Constants::VAR_CURRENTSESSION_PREFIX,
- SessionManager::sessionNameToFileName(SessionManager::activeSession()).toFileInfo()));
- } else {
- VariableManager::remove(variable);
- }
- } else {
- QString projectName;
- QString projectFilePath;
- Kit *kit = 0;
- QString buildConfigurationName;
- if (Project *project = currentProject()) {
- projectName = project->displayName();
- if (IDocument *doc = project->document())
- projectFilePath = doc->filePath();
- if (Target *target = project->activeTarget()) {
- kit = target->kit();
- if (BuildConfiguration *buildConfiguration = target->activeBuildConfiguration())
- buildConfigurationName = buildConfiguration->displayName();
- }
- }
- ProjectMacroExpander expander(projectFilePath, projectName, kit, buildConfigurationName);
- QString result;
- if (expander.resolveProjectMacro(QString::fromUtf8(variable), &result))
- VariableManager::insert(variable, result);
- else
- VariableManager::remove(variable);
- }
-}
-
void ProjectExplorerPlugin::updateRunWithoutDeployMenu()
{
d->m_runWithoutDeployAction->setVisible(d->m_projectExplorerSettings.deployBeforeRun);
diff --git a/src/plugins/projectexplorer/projectexplorer.h b/src/plugins/projectexplorer/projectexplorer.h
index 73e0a8a57a..731a1723eb 100644
--- a/src/plugins/projectexplorer/projectexplorer.h
+++ b/src/plugins/projectexplorer/projectexplorer.h
@@ -226,7 +226,6 @@ private slots:
void currentModeChanged(Core::IMode *mode, Core::IMode *oldMode);
void updateActions();
void loadCustomWizards();
- void updateVariable(const QByteArray &variable);
void updateRunWithoutDeployMenu();
void updateWelcomePage();
diff --git a/src/plugins/projectexplorer/projectmacroexpander.cpp b/src/plugins/projectexplorer/projectmacroexpander.cpp
index 4ce2f4086f..04c87e7431 100644
--- a/src/plugins/projectexplorer/projectmacroexpander.cpp
+++ b/src/plugins/projectexplorer/projectmacroexpander.cpp
@@ -51,14 +51,6 @@ bool ProjectMacroExpander::resolveProjectMacro(const QString &name, QString *ret
result = m_projectName;
found = true;
}
- } else if (Core::VariableManager::isFileVariable(
- name.toUtf8(), ProjectExplorer::Constants::VAR_CURRENTPROJECT_PREFIX)) {
- if (!m_projectFile.filePath().isEmpty()) {
- result = Core::VariableManager::fileVariableValue(name.toUtf8(),
- ProjectExplorer::Constants::VAR_CURRENTPROJECT_PREFIX,
- m_projectFile);
- found = true;
- }
} else if (m_kit && name == QLatin1String(ProjectExplorer::Constants::VAR_CURRENTKIT_NAME)) {
result = m_kit->displayName();
found = true;
@@ -101,6 +93,7 @@ bool ProjectMacroExpander::resolveProjectMacro(const QString &name, QString *ret
return found;
}
+// Try to resolve using local information, otherwise fall back to global variables.
bool ProjectMacroExpander::resolveMacro(const QString &name, QString *ret)
{
bool found = resolveProjectMacro(name, ret);
diff --git a/src/plugins/projectexplorer/projectmacroexpander.h b/src/plugins/projectexplorer/projectmacroexpander.h
index 6f8eda93ea..f54f920189 100644
--- a/src/plugins/projectexplorer/projectmacroexpander.h
+++ b/src/plugins/projectexplorer/projectmacroexpander.h
@@ -50,6 +50,7 @@ private:
const Kit *m_kit;
QString m_bcName;
};
-} // namespace
+
+} // namespace ProjectExplorer
#endif // PROJECTMACROEXPANDER_H