forked from qt-creator/qt-creator
Update project tree if .qmlproject file / included directories change
This commit is contained in:
@@ -7,6 +7,8 @@ FileFilterBaseItem::FileFilterBaseItem(QObject *parent) :
|
||||
QmlProjectContentItem(parent),
|
||||
m_recursive(false)
|
||||
{
|
||||
connect(&m_fsWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(updateFileList()));
|
||||
connect(&m_fsWatcher, SIGNAL(fileChanged(QString)), this, SLOT(updateFileList()));
|
||||
}
|
||||
|
||||
QString FileFilterBaseItem::directory() const
|
||||
@@ -82,24 +84,48 @@ QString FileFilterBaseItem::absoluteDir() const
|
||||
|
||||
void FileFilterBaseItem::updateFileList()
|
||||
{
|
||||
const QString dir = absoluteDir();
|
||||
if (dir.isEmpty())
|
||||
const QString projectDir = absoluteDir();
|
||||
if (projectDir.isEmpty())
|
||||
return;
|
||||
|
||||
const QSet<QString> newFiles = filesInSubTree(QDir(m_defaultDir), QDir(dir));
|
||||
QSet<QString> dirsToBeWatched;
|
||||
const QSet<QString> newFiles = filesInSubTree(QDir(m_defaultDir), QDir(projectDir), &dirsToBeWatched);
|
||||
|
||||
if (newFiles != m_files) {
|
||||
// update watched files
|
||||
foreach (const QString &file, m_files - newFiles) {
|
||||
m_fsWatcher.removePath(QDir(projectDir).absoluteFilePath(file));
|
||||
}
|
||||
foreach (const QString &file, newFiles - m_files) {
|
||||
m_fsWatcher.addPath(QDir(projectDir).absoluteFilePath(file));
|
||||
}
|
||||
|
||||
m_files = newFiles;
|
||||
|
||||
emit filesChanged();
|
||||
}
|
||||
|
||||
// update watched directories
|
||||
QSet<QString> watchedDirectories = m_fsWatcher.directories().toSet();
|
||||
foreach (const QString &dir, watchedDirectories - dirsToBeWatched) {
|
||||
m_fsWatcher.removePath(QDir(projectDir).absoluteFilePath(dir));
|
||||
}
|
||||
foreach (const QString &dir, dirsToBeWatched - watchedDirectories) {
|
||||
m_fsWatcher.addPath(QDir(projectDir).absoluteFilePath(dir));
|
||||
}
|
||||
}
|
||||
|
||||
QSet<QString> FileFilterBaseItem::filesInSubTree(const QDir &rootDir, const QDir &dir)
|
||||
QSet<QString> FileFilterBaseItem::filesInSubTree(const QDir &rootDir, const QDir &dir, QSet<QString> *parsedDirs)
|
||||
{
|
||||
QSet<QString> fileSet;
|
||||
|
||||
if (parsedDirs)
|
||||
parsedDirs->insert(dir.absolutePath());
|
||||
|
||||
foreach (const QFileInfo &file, dir.entryInfoList(QDir::Files)) {
|
||||
if (m_regex.exactMatch(file.fileName()))
|
||||
if (m_regex.exactMatch(file.fileName())) {
|
||||
fileSet.insert(rootDir.relativeFilePath(file.absoluteFilePath()));
|
||||
}
|
||||
}
|
||||
|
||||
if (m_recursive) {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <QObject>
|
||||
#include <QSet>
|
||||
#include <qml.h>
|
||||
#include <QFileSystemWatcher>
|
||||
|
||||
#include "qmlprojectitem.h"
|
||||
|
||||
@@ -40,11 +41,13 @@ signals:
|
||||
void filterChanged();
|
||||
void filesChanged();
|
||||
|
||||
private slots:
|
||||
void updateFileList();
|
||||
|
||||
private:
|
||||
QString absoluteDir() const;
|
||||
|
||||
void updateFileList();
|
||||
QSet<QString> filesInSubTree(const QDir &rootDir, const QDir &dir);
|
||||
QSet<QString> filesInSubTree(const QDir &rootDir, const QDir &dir, QSet<QString> *parsedDirs = 0);
|
||||
|
||||
QString m_rootDir;
|
||||
QString m_defaultDir;
|
||||
@@ -53,6 +56,8 @@ private:
|
||||
QRegExp m_regex;
|
||||
bool m_recursive;
|
||||
|
||||
QFileSystemWatcher m_fsWatcher;
|
||||
|
||||
QSet<QString> m_files;
|
||||
|
||||
friend class ProjectItem;
|
||||
|
||||
@@ -56,6 +56,7 @@ QString QmlProjectItem::sourceDirectory() const
|
||||
return d->sourceDirectory;
|
||||
}
|
||||
|
||||
// kind of initialization
|
||||
void QmlProjectItem::setSourceDirectory(const QString &directoryPath)
|
||||
{
|
||||
Q_D(QmlProjectItem);
|
||||
@@ -68,8 +69,10 @@ void QmlProjectItem::setSourceDirectory(const QString &directoryPath)
|
||||
for (int i = 0; i < d->content.size(); ++i) {
|
||||
QmlProjectContentItem *contentElement = d->content.at(i);
|
||||
FileFilterBaseItem *fileFilter = qobject_cast<FileFilterBaseItem*>(contentElement);
|
||||
if (fileFilter)
|
||||
if (fileFilter) {
|
||||
fileFilter->setDefaultDirectory(directoryPath);
|
||||
connect(fileFilter, SIGNAL(filesChanged()), this, SIGNAL(qmlFilesChanged()));
|
||||
}
|
||||
}
|
||||
|
||||
emit sourceDirectoryChanged();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef PROJECTITEM_H
|
||||
#define PROJECTITEM_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QtCore/QObject>
|
||||
#include <qml.h>
|
||||
|
||||
namespace QmlProjectManager {
|
||||
@@ -38,11 +38,11 @@ public:
|
||||
QStringList qmlFiles() const;
|
||||
|
||||
signals:
|
||||
void qmlFilesChanged();
|
||||
void sourceDirectoryChanged();
|
||||
|
||||
protected:
|
||||
QmlProjectItemPrivate *d_ptr;
|
||||
|
||||
};
|
||||
|
||||
} // namespace QmlProjectManager
|
||||
|
||||
Reference in New Issue
Block a user