Variable manager uses "update request" mechanism.

For now that removes the CURRENT_DOCUMENT variable and derivates.
This commit is contained in:
con
2010-12-08 12:03:33 +01:00
parent 371478ffb9
commit 1d51764103
7 changed files with 76 additions and 104 deletions

View File

@@ -50,22 +50,15 @@ class VMMapExpander : public Utils::AbstractQtcMacroExpander {
public:
virtual bool resolveMacro(const QString &name, QString *ret)
{
*ret = Core::VariableManager::instance()->value(name);
return !ret->isEmpty();
bool found;
*ret = Core::VariableManager::instance()->value(name, &found);
return found;
}
};
class VariableManagerPrivate : public QObject
{
Q_OBJECT
public:
void insert(const QString &variable, const QString &value);
bool remove(const QString &variable);
void insertFileInfo(const QString &tag, const QFileInfo &file);
void removeFileInfo(const QString &tag);
public slots:
void updateCurrentDocument(Core::IEditor *editor);
public:
QHash<QString, QString> m_map;
@@ -75,62 +68,6 @@ public:
VariableManager *VariableManagerPrivate::m_instance = 0;
void VariableManagerPrivate::updateCurrentDocument(Core::IEditor *editor)
{
const QString currentDocumentTag = QLatin1String("CURRENT_DOCUMENT");
removeFileInfo(currentDocumentTag);
if (editor) {
if (const Core::IFile *file = editor->file()) {
const QString fileName = file->fileName();
if (!fileName.isEmpty())
insertFileInfo(currentDocumentTag, fileName);
}
}
}
void VariableManagerPrivate::insert(const QString &variable, const QString &value)
{
m_map.insert(variable, value);
}
bool VariableManagerPrivate::remove(const QString &variable)
{
return m_map.remove(variable) > 0;
}
void VariableManagerPrivate::insertFileInfo(const QString &tag, const QFileInfo &file)
{
insert(tag, file.filePath());
insert(tag + QLatin1String(":absoluteFilePath"), file.absoluteFilePath());
insert(tag + QLatin1String(":absolutePath"), file.absolutePath());
insert(tag + QLatin1String(":baseName"), file.baseName());
insert(tag + QLatin1String(":canonicalPath"), file.canonicalPath());
insert(tag + QLatin1String(":canonicalFilePath"), file.canonicalFilePath());
insert(tag + QLatin1String(":completeBaseName"), file.completeBaseName());
insert(tag + QLatin1String(":completeSuffix"), file.completeSuffix());
insert(tag + QLatin1String(":fileName"), file.fileName());
insert(tag + QLatin1String(":filePath"), file.filePath());
insert(tag + QLatin1String(":path"), file.path());
insert(tag + QLatin1String(":suffix"), file.suffix());
}
void VariableManagerPrivate::removeFileInfo(const QString &tag)
{
if (remove(tag)) {
remove(tag + QLatin1String(":absoluteFilePath"));
remove(tag + QLatin1String(":absolutePath"));
remove(tag + QLatin1String(":baseName"));
remove(tag + QLatin1String(":canonicalPath"));
remove(tag + QLatin1String(":canonicalFilePath"));
remove(tag + QLatin1String(":completeBaseName"));
remove(tag + QLatin1String(":completeSuffix"));
remove(tag + QLatin1String(":fileName"));
remove(tag + QLatin1String(":filePath"));
remove(tag + QLatin1String(":path"));
remove(tag + QLatin1String(":suffix"));
}
}
VariableManager::VariableManager() : d(new VariableManagerPrivate)
{
VariableManagerPrivate::m_instance = this;
@@ -141,42 +78,29 @@ VariableManager::~VariableManager()
VariableManagerPrivate::m_instance = 0;
}
void VariableManager::initEditorManagerConnections()
{
QTC_ASSERT(VariableManagerPrivate::m_instance && Core::EditorManager::instance(), return; )
QObject::connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
VariableManagerPrivate::m_instance->d.data(), SLOT(updateCurrentDocument(Core::IEditor*)));
}
QString VariableManager::value(const QString &variable) const
{
return d->m_map.value(variable);
}
QString VariableManager::value(const QString &variable, const QString &defaultValue) const
{
return d->m_map.value(variable, defaultValue);
}
void VariableManager::insert(const QString &variable, const QString &value)
{
d->insert(variable, value);
}
void VariableManager::insertFileInfo(const QString &tag, const QFileInfo &file)
{
d->insertFileInfo(tag, file);
}
void VariableManager::removeFileInfo(const QString &tag)
{
d->removeFileInfo(tag);
d->m_map.insert(variable, value);
}
bool VariableManager::remove(const QString &variable)
{
return d->remove(variable);
return d->m_map.remove(variable) > 0;
}
QString VariableManager::value(const QString &variable, bool *found)
{
emit variableUpdateRequested(variable);
if (found) {
*found = d->m_map.contains(variable);
}
return d->m_map.value(variable);
}
QString VariableManager::value(const QString &variable, const QString &defaultValue)
{
emit variableUpdateRequested(variable);
return d->m_map.value(variable, defaultValue);
}
Utils::AbstractMacroExpander *VariableManager::macroExpander()
@@ -188,6 +112,7 @@ VariableManager* VariableManager::instance()
{
return VariableManagerPrivate::m_instance;
}
} // namespace Core
#include "variablemanager.moc"