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