Commit 1d517641 authored by con's avatar con
Browse files

Variable manager uses "update request" mechanism.

For now that removes the CURRENT_DOCUMENT variable and derivates.
parent 371478ff
......@@ -440,8 +440,6 @@ EditorManager::EditorManager(ICore *core, QWidget *parent) :
advancedMenu->addAction(cmd, Constants::G_EDIT_EDITOR);
connect(m_d->m_openInExternalEditorAction, SIGNAL(triggered()), this, SLOT(openInExternalEditor()));
// Connect to VariableManager for CURRENT_DOCUMENT variable setting
VariableManager::initEditorManagerConnections();
// other setup
m_d->m_splitter = new SplitterOrView(m_d->m_editorModel);
m_d->m_view = m_d->m_splitter->view();
......
......@@ -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);
d->m_map.insert(variable, value);
}
void VariableManager::insertFileInfo(const QString &tag, const QFileInfo &file)
bool VariableManager::remove(const QString &variable)
{
d->insertFileInfo(tag, file);
return d->m_map.remove(variable) > 0;
}
void VariableManager::removeFileInfo(const QString &tag)
QString VariableManager::value(const QString &variable, bool *found)
{
d->removeFileInfo(tag);
emit variableUpdateRequested(variable);
if (found) {
*found = d->m_map.contains(variable);
}
return d->m_map.value(variable);
}
bool VariableManager::remove(const QString &variable)
QString VariableManager::value(const QString &variable, const QString &defaultValue)
{
return d->remove(variable);
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"
......@@ -36,6 +36,7 @@
#include "core_global.h"
#include <QtCore/QObject>
#include <QtCore/QScopedPointer>
#include <QtCore/QString>
......@@ -50,24 +51,25 @@ class AbstractMacroExpander;
namespace Core {
class VariableManagerPrivate;
class CORE_EXPORT VariableManager
class CORE_EXPORT VariableManager : public QObject
{
Q_OBJECT
Q_DISABLE_COPY(VariableManager)
public:
VariableManager();
~VariableManager();
static VariableManager* instance();
static void initEditorManagerConnections();
void insert(const QString &variable, const QString &value);
void insertFileInfo(const QString &tag, const QFileInfo &file);
void removeFileInfo(const QString &tag);
QString value(const QString &variable) const;
QString value(const QString &variable, const QString &defaultValue) const;
bool remove(const QString &variable);
QString value(const QString &variable, bool *found = 0);
QString value(const QString &variable, const QString &defaultValue);
Utils::AbstractMacroExpander *macroExpander();
signals:
void variableUpdateRequested(const QString &variable);
private:
QScopedPointer<VariableManagerPrivate> d;
};
......
......@@ -100,6 +100,7 @@
#include <coreplugin/basefilewizard.h>
#include <coreplugin/vcsmanager.h>
#include <coreplugin/iversioncontrol.h>
#include <coreplugin/variablemanager.h>
#include <welcome/welcomemode.h>
#include <extensionsystem/pluginmanager.h>
#include <find/searchresultwindow.h>
......@@ -898,6 +899,9 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
updateWelcomePage();
connect(Core::VariableManager::instance(), SIGNAL(variableUpdateRequested(QString)),
this, SLOT(updateVariable(QString)));
return true;
}
......@@ -995,6 +999,27 @@ void ProjectExplorerPlugin::loadCustomWizards()
}
}
void ProjectExplorerPlugin::updateVariable(const QString &variable)
{
static const char * const currentProjectPathVar = "CurrentProjectPath";
static const char * const currentProjectFilePathVar = "CurrentProjectFilePath";
if (variable == QLatin1String(currentProjectFilePathVar)) {
if (currentProject() && currentProject()->file()) {
Core::VariableManager::instance()->insert(variable,
currentProject()->file()->fileName());
} else {
Core::VariableManager::instance()->remove(variable);
}
} else if (variable == QLatin1String(currentProjectPathVar)) {
if (currentProject() && currentProject()->file()) {
Core::VariableManager::instance()->insert(variable,
QFileInfo(currentProject()->file()->fileName()).filePath());
} else {
Core::VariableManager::instance()->remove(variable);
}
}
}
ExtensionSystem::IPlugin::ShutdownFlag ProjectExplorerPlugin::aboutToShutdown()
{
d->m_proWindow->aboutToShutdown(); // disconnect from session
......
......@@ -213,6 +213,7 @@ private slots:
void currentModeChanged(Core::IMode *mode, Core::IMode *oldMode);
void updateActions();
void loadCustomWizards();
void updateVariable(const QString &variable);
void publishProject();
......
......@@ -50,6 +50,7 @@
#include <coreplugin/uniqueidmanager.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/variablemanager.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/buildmanager.h>
#include <projectexplorer/session.h>
......@@ -132,6 +133,9 @@ void Qt4Manager::init()
connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
this, SLOT(editorChanged(Core::IEditor*)));
connect(Core::VariableManager::instance(), SIGNAL(variableUpdateRequested(QString)),
this, SLOT(updateVariable(QString)));
}
void Qt4Manager::editorChanged(Core::IEditor *editor)
......@@ -173,6 +177,21 @@ void Qt4Manager::editorAboutToClose(Core::IEditor *editor)
}
}
void Qt4Manager::updateVariable(const QString &variable)
{
static const char * const installBinsVar = "QT_INSTALL_BINS";
if (variable == QLatin1String(installBinsVar)) {
Qt4Project *qt4pro = qobject_cast<Qt4Project *>(projectExplorer()->currentProject());
if (!qt4pro) {
Core::VariableManager::instance()->remove(QLatin1String(installBinsVar));
return;
}
QString value = qt4pro->activeTarget()->activeBuildConfiguration()
->qtVersion()->versionInfo().value(QLatin1String(installBinsVar));
Core::VariableManager::instance()->insert(QLatin1String(installBinsVar), value);
}
}
void Qt4Manager::uiEditorContentsChanged()
{
// cast sender, get filename
......@@ -371,3 +390,4 @@ QString Qt4Manager::fileTypeId(ProjectExplorer::FileType type)
}
return QString();
}
......@@ -107,6 +107,7 @@ private slots:
void editorAboutToClose(Core::IEditor *editor);
void uiEditorContentsChanged();
void editorChanged(Core::IEditor*);
void updateVariable(const QString &variable);
private:
QList<Qt4Project *> m_projects;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment