From cccad7432d99064fa7cf61943a0630e7adf54d51 Mon Sep 17 00:00:00 2001 From: Kai Koehne <kai.koehne@nokia.com> Date: Thu, 15 Sep 2011 13:05:36 +0200 Subject: [PATCH] QmlProjectManager: Make sure project tree updates after in project file change Use FileManager instead of our own FileSystemWatcher, since this one only signals the first file change (cause Qt Creator apparently removes the file and creates a new one on each change). Change-Id: Idacd545e41cd3ee29bfbc122526b9097039c65d0 Reviewed-on: http://codereview.qt-project.org/4975 Reviewed-by: Daniel Teske <daniel.teske@nokia.com> Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> --- src/plugins/qmlprojectmanager/qmlproject.cpp | 11 +++++------ src/plugins/qmlprojectmanager/qmlproject.h | 4 ++-- src/plugins/qmlprojectmanager/qmlprojectfile.cpp | 14 +++++++++++--- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/plugins/qmlprojectmanager/qmlproject.cpp b/src/plugins/qmlprojectmanager/qmlproject.cpp index 508ed62d7a1..9da413a81a8 100644 --- a/src/plugins/qmlprojectmanager/qmlproject.cpp +++ b/src/plugins/qmlprojectmanager/qmlproject.cpp @@ -42,6 +42,7 @@ #include <coreplugin/icore.h> #include <coreplugin/messagemanager.h> +#include <coreplugin/filemanager.h> #include <extensionsystem/pluginmanager.h> #include <qtsupport/qmldumptool.h> #include <qtsupport/baseqtversion.h> @@ -60,10 +61,8 @@ namespace QmlProjectManager { QmlProject::QmlProject(Internal::Manager *manager, const QString &fileName) : m_manager(manager), m_fileName(fileName), - m_modelManager(ExtensionSystem::PluginManager::instance()->getObject<QmlJS::ModelManagerInterface>()), - m_fileWatcher(new Utils::FileSystemWatcher(this)) + m_modelManager(ExtensionSystem::PluginManager::instance()->getObject<QmlJS::ModelManagerInterface>()) { - m_fileWatcher->setObjectName(QLatin1String("QmlProjectWatcher")); setProjectContext(Core::Context(QmlProjectManager::Constants::PROJECTCONTEXT)); setProjectLanguage(Core::Context(QmlProjectManager::Constants::LANG_QML)); @@ -73,9 +72,7 @@ QmlProject::QmlProject(Internal::Manager *manager, const QString &fileName) m_file = new Internal::QmlProjectFile(this, fileName); m_rootNode = new Internal::QmlProjectNode(this, m_file); - m_fileWatcher->addFile(fileName, Utils::FileSystemWatcher::WatchModifiedDate); - connect(m_fileWatcher, SIGNAL(fileChanged(QString)), - this, SLOT(refreshProjectFile())); + Core::FileManager::instance()->addFile(m_file, true); m_manager->registerProject(this); } @@ -84,6 +81,8 @@ QmlProject::~QmlProject() { m_manager->unregisterProject(this); + Core::FileManager::instance()->removeFile(m_file); + delete m_projectItem.data(); delete m_rootNode; } diff --git a/src/plugins/qmlprojectmanager/qmlproject.h b/src/plugins/qmlprojectmanager/qmlproject.h index f163a9d2089..caa4a751b82 100644 --- a/src/plugins/qmlprojectmanager/qmlproject.h +++ b/src/plugins/qmlprojectmanager/qmlproject.h @@ -100,8 +100,9 @@ public: bool addFiles(const QStringList &filePaths); -private slots: void refreshProjectFile(); + +private slots: void refreshFiles(const QSet<QString> &added, const QSet<QString> &removed); protected: @@ -124,7 +125,6 @@ private: // qml based, new format QDeclarativeEngine m_engine; QWeakPointer<QmlProjectItem> m_projectItem; - Utils::FileSystemWatcher *m_fileWatcher; Internal::QmlProjectNode *m_rootNode; }; diff --git a/src/plugins/qmlprojectmanager/qmlprojectfile.cpp b/src/plugins/qmlprojectmanager/qmlprojectfile.cpp index 44189f12f36..4fd10bba868 100644 --- a/src/plugins/qmlprojectmanager/qmlprojectfile.cpp +++ b/src/plugins/qmlprojectmanager/qmlprojectfile.cpp @@ -33,6 +33,7 @@ #include "qmlprojectfile.h" #include "qmlproject.h" #include "qmlprojectconstants.h" +#include <utils/qtcassert.h> namespace QmlProjectManager { namespace Internal { @@ -41,10 +42,14 @@ QmlProjectFile::QmlProjectFile(QmlProject *parent, QString fileName) : Core::IFile(parent), m_project(parent), m_fileName(fileName) -{ } +{ + QTC_CHECK(m_project); + QTC_CHECK(!fileName.isEmpty()); +} QmlProjectFile::~QmlProjectFile() -{ } +{ +} bool QmlProjectFile::save(QString *, const QString &, bool) { @@ -104,7 +109,10 @@ bool QmlProjectFile::reload(QString *errorString, ReloadFlag flag, ChangeType ty { Q_UNUSED(errorString) Q_UNUSED(flag) - Q_UNUSED(type) + + if (type == TypeContents) + m_project->refreshProjectFile(); + return true; } -- GitLab