forked from qt-creator/qt-creator
Centralize handling of file-kind variables.
Change-Id: I400e28ae7d1d4f0250519dcd3c85746da1ea1e93 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
@@ -86,8 +86,7 @@
|
||||
|
||||
enum { debugEditorManager=0 };
|
||||
|
||||
static const char kCurrentDocumentFilePath[] = "CurrentDocument:FilePath";
|
||||
static const char kCurrentDocumentPath[] = "CurrentDocument:Path";
|
||||
static const char kCurrentDocumentPrefix[] = "CurrentDocument";
|
||||
static const char kCurrentDocumentXPos[] = "CurrentDocument:XPos";
|
||||
static const char kCurrentDocumentYPos[] = "CurrentDocument:YPos";
|
||||
static const char kMakeWritableWarning[] = "Core.EditorManager.MakeWritable";
|
||||
@@ -467,10 +466,7 @@ void EditorManager::init()
|
||||
ExtensionSystem::PluginManager::addObject(d->m_openEditorsFactory);
|
||||
|
||||
VariableManager *vm = VariableManager::instance();
|
||||
vm->registerVariable(kCurrentDocumentFilePath,
|
||||
tr("Full path of the current document including file name."));
|
||||
vm->registerVariable(kCurrentDocumentPath,
|
||||
tr("Full path of the current document excluding file name."));
|
||||
vm->registerFileVariables(kCurrentDocumentPrefix, tr("Current document"));
|
||||
vm->registerVariable(kCurrentDocumentXPos,
|
||||
tr("X-coordinate of the current editor's upper left corner, relative to screen."));
|
||||
vm->registerVariable(kCurrentDocumentYPos,
|
||||
@@ -2291,17 +2287,14 @@ QString EditorManager::windowTitleAddition() const
|
||||
|
||||
void EditorManager::updateVariable(const QByteArray &variable)
|
||||
{
|
||||
if (variable == kCurrentDocumentFilePath || variable == kCurrentDocumentPath) {
|
||||
if (VariableManager::instance()->isFileVariable(variable, kCurrentDocumentPrefix)) {
|
||||
QString value;
|
||||
IEditor *curEditor = currentEditor();
|
||||
if (curEditor) {
|
||||
QString fileName = curEditor->document()->fileName();
|
||||
if (!fileName.isEmpty()) {
|
||||
if (variable == kCurrentDocumentFilePath)
|
||||
value = QFileInfo(fileName).filePath();
|
||||
else if (variable == kCurrentDocumentPath)
|
||||
value = QFileInfo(fileName).path();
|
||||
}
|
||||
if (!fileName.isEmpty())
|
||||
value = VariableManager::instance()->fileVariableValue(variable, kCurrentDocumentPrefix,
|
||||
fileName);
|
||||
}
|
||||
VariableManager::instance()->insert(variable, value);
|
||||
} else if (variable == kCurrentDocumentXPos) {
|
||||
|
||||
@@ -40,6 +40,9 @@
|
||||
#include <QMap>
|
||||
#include <QDebug>
|
||||
|
||||
static const char kFilePathPostfix[] = ":FilePath";
|
||||
static const char kPathPostfix[] = ":Path";
|
||||
|
||||
namespace Core {
|
||||
|
||||
class VMMapExpander : public Utils::AbstractQtcMacroExpander
|
||||
@@ -117,6 +120,34 @@ void VariableManager::registerVariable(const QByteArray &variable, const QString
|
||||
d->m_descriptions.insert(variable, description);
|
||||
}
|
||||
|
||||
void VariableManager::registerFileVariables(const QByteArray &prefix, const QString &heading)
|
||||
{
|
||||
registerVariable(prefix + kFilePathPostfix, tr("%1: Full path including file name.").arg(heading));
|
||||
registerVariable(prefix + kPathPostfix, tr("%1: Full path excluding file name.").arg(heading));
|
||||
}
|
||||
|
||||
bool VariableManager::isFileVariable(const QByteArray &variable, const QByteArray &prefix)
|
||||
{
|
||||
return variable == prefix + kFilePathPostfix
|
||||
|| variable == prefix + kPathPostfix;
|
||||
}
|
||||
|
||||
QString VariableManager::fileVariableValue(const QByteArray &variable, const QByteArray &prefix,
|
||||
const QString &fileName)
|
||||
{
|
||||
return fileVariableValue(variable, prefix, QFileInfo(fileName));
|
||||
}
|
||||
|
||||
QString VariableManager::fileVariableValue(const QByteArray &variable, const QByteArray &prefix,
|
||||
const QFileInfo &fileInfo)
|
||||
{
|
||||
if (variable == prefix + kFilePathPostfix)
|
||||
return fileInfo.filePath();
|
||||
else if (variable == prefix + kPathPostfix)
|
||||
return fileInfo.path();
|
||||
return QString();
|
||||
}
|
||||
|
||||
QList<QByteArray> VariableManager::variables() const
|
||||
{
|
||||
return d->m_descriptions.keys();
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
#include "core_global.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
@@ -60,6 +61,15 @@ public:
|
||||
|
||||
void registerVariable(const QByteArray &variable,
|
||||
const QString &description);
|
||||
|
||||
void registerFileVariables(const QByteArray &prefix,
|
||||
const QString &heading);
|
||||
bool isFileVariable(const QByteArray &variable, const QByteArray &prefix);
|
||||
QString fileVariableValue(const QByteArray &variable, const QByteArray &prefix,
|
||||
const QString &fileName);
|
||||
QString fileVariableValue(const QByteArray &variable, const QByteArray &prefix,
|
||||
const QFileInfo &fileInfo);
|
||||
|
||||
QList<QByteArray> variables() const;
|
||||
QString variableDescription(const QByteArray &variable) const;
|
||||
|
||||
|
||||
@@ -1005,10 +1005,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
||||
updateWelcomePage();
|
||||
|
||||
Core::VariableManager *vm = Core::VariableManager::instance();
|
||||
vm->registerVariable(Constants::VAR_CURRENTPROJECT_FILEPATH,
|
||||
tr("Full path of the current project's main file, including file name."));
|
||||
vm->registerVariable(Constants::VAR_CURRENTPROJECT_PATH,
|
||||
tr("Full path of the current project's main file, excluding file name."));
|
||||
vm->registerFileVariables(Constants::VAR_CURRENTPROJECT_PREFIX, tr("Current project's main file"));
|
||||
vm->registerVariable(Constants::VAR_CURRENTPROJECT_BUILDPATH,
|
||||
tr("Full build path of the current project's active build configuration."));
|
||||
vm->registerVariable(Constants::VAR_CURRENTPROJECT_NAME, tr("The current project's name."));
|
||||
|
||||
@@ -237,8 +237,7 @@ const char DESKTOP_DEVICE_ID[] = "Desktop Device";
|
||||
const char DESKTOP_DEVICE_TYPE[] = "Desktop";
|
||||
|
||||
// Variable Names:
|
||||
const char VAR_CURRENTPROJECT_PATH[] = "CurrentProject:Path";
|
||||
const char VAR_CURRENTPROJECT_FILEPATH[] = "CurrentProject:FilePath";
|
||||
const char VAR_CURRENTPROJECT_PREFIX[] = "CurrentProject";
|
||||
const char VAR_CURRENTPROJECT_BUILDPATH[] = "CurrentProject:BuildPath";
|
||||
const char VAR_CURRENTPROJECT_NAME[] = "CurrentProject:Name";
|
||||
const char VAR_CURRENTKIT_NAME[] = "CurrentKit:Name";
|
||||
|
||||
@@ -49,14 +49,12 @@ bool ProjectExpander::resolveProjectMacro(const QString &name, QString *ret)
|
||||
result = m_projectName;
|
||||
found = true;
|
||||
}
|
||||
} else if (name == QLatin1String(ProjectExplorer::Constants::VAR_CURRENTPROJECT_PATH)) {
|
||||
} else if (Core::VariableManager::instance()->isFileVariable(
|
||||
name.toUtf8(), ProjectExplorer::Constants::VAR_CURRENTPROJECT_PREFIX)) {
|
||||
if (!m_projectFile.filePath().isEmpty()) {
|
||||
result = m_projectFile.absolutePath();
|
||||
found = true;
|
||||
}
|
||||
} else if (name == QLatin1String(ProjectExplorer::Constants::VAR_CURRENTPROJECT_FILEPATH)) {
|
||||
if (!m_projectFile.filePath().isEmpty()) {
|
||||
result = m_projectFile.absoluteFilePath();
|
||||
result = Core::VariableManager::instance()->fileVariableValue(name.toUtf8(),
|
||||
ProjectExplorer::Constants::VAR_CURRENTPROJECT_PREFIX,
|
||||
m_projectFile);
|
||||
found = true;
|
||||
}
|
||||
} else if (m_kit && name == QLatin1String(ProjectExplorer::Constants::VAR_CURRENTKIT_NAME)) {
|
||||
|
||||
Reference in New Issue
Block a user