Eike Ziller, Monday 22 June 2009: > I'm thinking of any kind of e.g. build or run configuration, command > line arguments for starting a program, working directory settings, > running external tools ... (a variable for the current editor might > not be the most important one for these, but once the infrastructure > is there, it could be used for a bunch of variables)
Ok, I have implemented it in the VariableManager now in a way such that it can be used from anywhere with an arbitrary QFileInfo as input. Given that, I also thought it would make sense to use the QFileInfo method names as replacement tags, e.g. ${absolutePath}. That should make it easy to document the functionality and very natural for every Qt programmer to actually use it. > > Also, to implement this in a proper way, I'd have to make sure that I > > identify the file name components in a more platform-independent > > way, i.e. > > not by looking for the last forward-slash. > > QFileInfo(filePath).fileName() > that's what Qt is for ;-) Thanks, I was sure there must be something like that, and actually had figured it out from the Qt docs half an hour ago. They are very good, and I am very new to Qt as you have noticed (it's not even what I am using QtCreator for ;)). > Hoping that I'm not too aggressive :), Not at all, thanks for your help. I have a proper implementation of my wanted feature now, and am attaching it as a patch for the moment, until I find out how to do the fancy requesting with gitorious (and have a better connection than the one in a train ;)). Comments very welcome. Cheers, Frank
diff --git a/src/plugins/coreplugin/variablemanager.cpp b/src/plugins/coreplugin/variablemanager.cpp index b2d395f..542632b 100644 --- a/src/plugins/coreplugin/variablemanager.cpp +++ b/src/plugins/coreplugin/variablemanager.cpp @@ -48,6 +48,21 @@ void VariableManager::insert(const QString &variable, const QString &value) m_map.insert(variable, value); } +void VariableManager::insertCurrentFileInfo(const QFileInfo& file) +{ + insert("absoluteFilePath", file.absoluteFilePath()); + insert("absolutePath", file.absolutePath()); + insert("baseName", file.baseName()); + insert("canonicalPath", file.canonicalPath()); + insert("canonicalFilePath", file.canonicalFilePath()); + insert("completeBaseName", file.completeBaseName()); + insert("completeSuffix", file.completeSuffix()); + insert("fileName", file.fileName()); + insert("filePath", file.filePath()); + insert("path", file.path()); + insert("suffix", file.suffix()); +} + QString VariableManager::value(const QString &variable) { return m_map.value(variable); diff --git a/src/plugins/coreplugin/variablemanager.h b/src/plugins/coreplugin/variablemanager.h index 76a0592..578c80c 100644 --- a/src/plugins/coreplugin/variablemanager.h +++ b/src/plugins/coreplugin/variablemanager.h @@ -35,6 +35,7 @@ #include <QtCore/QObject> #include <QtCore/QMap> #include <QtCore/QString> +#include <QtCore/QFileInfo> namespace Core { @@ -49,6 +50,7 @@ public: static VariableManager* instance() { return m_instance; } void insert(const QString &variable, const QString &value); + void insertCurrentFileInfo(const QFileInfo& file); QString value(const QString &variable); QString value(const QString &variable, const QString &defaultValue); void remove(const QString &variable); diff --git a/src/plugins/genericprojectmanager/genericmakestep.cpp b/src/plugins/genericprojectmanager/genericmakestep.cpp index c4d4f2d..bd11748 100644 --- a/src/plugins/genericprojectmanager/genericmakestep.cpp +++ b/src/plugins/genericprojectmanager/genericmakestep.cpp @@ -35,6 +35,8 @@ #include <extensionsystem/pluginmanager.h> #include <projectexplorer/toolchain.h> #include <utils/qtcassert.h> +#include <coreplugin/editormanager/editormanager.h> +#include <coreplugin/variablemanager.h> #include <QtGui/QFormLayout> #include <QtGui/QGroupBox> @@ -61,7 +63,11 @@ bool GenericMakeStep::init(const QString &buildConfiguration) qDebug() << "*** build parser:" << buildParser; setEnabled(buildConfiguration, true); - setWorkingDirectory(buildConfiguration, m_pro->buildDirectory(buildConfiguration)); + const QFileInfo file(Core::EditorManager::instance()->currentEditor()->file()->fileName()); + Core::VariableManager::instance()->insertCurrentFileInfo(file); + const QString rawBuildDir = m_pro->buildDirectory(buildConfiguration); + const QString buildDir = Core::VariableManager::instance()->resolve(rawBuildDir); + setWorkingDirectory(buildConfiguration, buildDir); QString command = value(buildConfiguration, "makeCommand").toString(); if (command.isEmpty()) {
_______________________________________________ Qt-creator mailing list Qt-creator@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-creator