forked from qt-creator/qt-creator
Fixes: Updating the completion for ui files
Details: That is we update all generated headers (which are new or modfied) in the C++ Engine. Big if, this only works if we find the correct path for the ui header files. Which is known to sometimes not work, I'll fix that next.
This commit is contained in:
@@ -44,165 +44,6 @@ enum { debugWatcher = 0 };
|
||||
namespace Qt4ProjectManager {
|
||||
namespace Internal {
|
||||
|
||||
int DirectoryWatcher::m_objectCount = 0;
|
||||
QHash<QString,int> DirectoryWatcher::m_directoryCount;
|
||||
QFileSystemWatcher *DirectoryWatcher::m_watcher = 0;
|
||||
|
||||
/*
|
||||
\class DirectoryWatcher
|
||||
|
||||
A wrapper for QFileSystemWatcher that collects
|
||||
consecutive changes to a registered directory and emits directoryChanged() and fileChanged().
|
||||
|
||||
Note that files added are only monitored if the parent directory is added, too.
|
||||
|
||||
All instances of DirectoryWatcher share one QFileSystemWatcher object.
|
||||
That's because every QFileSystemWatcher object consumes a file descriptor,
|
||||
even if no files are watched.
|
||||
*/
|
||||
DirectoryWatcher::DirectoryWatcher(QObject *parent) :
|
||||
QObject(parent),
|
||||
m_timer(0)
|
||||
{
|
||||
if (!m_watcher)
|
||||
m_watcher = new QFileSystemWatcher();
|
||||
++m_objectCount;
|
||||
connect(m_watcher, SIGNAL(directoryChanged(QString)),
|
||||
this, SLOT(slotDirectoryChanged(QString)));
|
||||
}
|
||||
|
||||
DirectoryWatcher::~DirectoryWatcher()
|
||||
{
|
||||
foreach (const QString &dir, m_directories)
|
||||
removeDirectory(dir);
|
||||
if (--m_objectCount == 0) {
|
||||
delete m_watcher;
|
||||
m_watcher = 0;
|
||||
}
|
||||
}
|
||||
|
||||
QStringList DirectoryWatcher::directories() const
|
||||
{
|
||||
if (debugWatcher)
|
||||
qDebug() << Q_FUNC_INFO << m_directories;
|
||||
return m_directories;
|
||||
}
|
||||
|
||||
void DirectoryWatcher::addDirectory(const QString &dir)
|
||||
{
|
||||
if (debugWatcher)
|
||||
qDebug() << Q_FUNC_INFO << dir;
|
||||
if (m_directories.contains(dir))
|
||||
return;
|
||||
m_directories += dir;
|
||||
if (m_directoryCount[dir] == 0)
|
||||
m_watcher->addPath(dir);
|
||||
m_directoryCount[dir] += 1;
|
||||
}
|
||||
|
||||
void DirectoryWatcher::removeDirectory(const QString &dir)
|
||||
{
|
||||
if (debugWatcher)
|
||||
qDebug() << Q_FUNC_INFO << dir;
|
||||
m_directories.removeOne(dir);
|
||||
m_directoryCount[dir] -= 1;
|
||||
if (m_directoryCount[dir] == 0)
|
||||
m_watcher->removePath(dir);
|
||||
}
|
||||
|
||||
QStringList DirectoryWatcher::files() const
|
||||
{
|
||||
if (debugWatcher)
|
||||
qDebug() << Q_FUNC_INFO << m_files.keys();
|
||||
return m_files.keys();
|
||||
}
|
||||
|
||||
void DirectoryWatcher::addFile(const QString &filePath)
|
||||
{
|
||||
addFiles(QStringList() << filePath);
|
||||
}
|
||||
|
||||
void DirectoryWatcher::addFiles(const QStringList &filePaths)
|
||||
{
|
||||
foreach (const QString filePath, filePaths) {
|
||||
QFileInfo file(filePath);
|
||||
m_files.insert(file.absoluteFilePath(),file.lastModified());
|
||||
}
|
||||
}
|
||||
|
||||
void DirectoryWatcher::removeFile(const QString &filePath)
|
||||
{
|
||||
m_files.remove(filePath);
|
||||
}
|
||||
|
||||
void DirectoryWatcher::slotDirectoryChanged(const QString &path)
|
||||
{
|
||||
if (debugWatcher)
|
||||
qDebug() << Q_FUNC_INFO << path;
|
||||
if (!m_directories.contains(path)
|
||||
|| m_pendingDirectories.contains(path))
|
||||
return;
|
||||
|
||||
if (!m_timer) {
|
||||
m_timer = new QTimer(this);
|
||||
m_timer->setSingleShot(true);
|
||||
m_timer->setInterval(500); // delay for 0.5 sec
|
||||
connect(m_timer, SIGNAL(timeout()), this, SLOT(slotDelayedDirectoriesChanged()));
|
||||
}
|
||||
if (!m_timer->isActive())
|
||||
m_timer->start();
|
||||
m_pendingDirectories.push_back(path);
|
||||
}
|
||||
|
||||
void DirectoryWatcher::slotDelayedDirectoriesChanged()
|
||||
{
|
||||
if (debugWatcher)
|
||||
qDebug() << Q_FUNC_INFO << " emitting " << m_pendingDirectories;
|
||||
const QStringList::const_iterator cend = m_pendingDirectories.constEnd();
|
||||
for (QStringList::const_iterator it = m_pendingDirectories.constBegin(); it != cend; ++it) {
|
||||
const QString dir = *it;
|
||||
if (!QFileInfo(dir).exists())
|
||||
removeDirectory(*it);
|
||||
emit directoryChanged(*it);
|
||||
updateFileList(*it);
|
||||
}
|
||||
m_pendingDirectories.clear();
|
||||
}
|
||||
|
||||
void DirectoryWatcher::updateFileList(const QString &dir)
|
||||
{
|
||||
const QStringList monitoredFiles = m_files.keys();
|
||||
QStringList removedFiles = monitoredFiles;
|
||||
if (QFileInfo(dir).exists()) {
|
||||
// Compare directory contents and emit signals
|
||||
QFileInfoList entryInfoList
|
||||
= QDir(dir).entryInfoList(QDir::Files|QDir::CaseSensitive);
|
||||
// Loop over directory creating the new map of file->time, removing
|
||||
// the existing entries from the old map
|
||||
const QFileInfoList::const_iterator cend = entryInfoList.constEnd();
|
||||
for (QFileInfoList::const_iterator filIt = entryInfoList.constBegin();
|
||||
filIt != cend; ++filIt) {
|
||||
const QString path = filIt->absoluteFilePath();
|
||||
FileModificationTimeMap::iterator mapIt = m_files.find(path);
|
||||
if (mapIt != m_files.end()) {
|
||||
const QDateTime lastModified = filIt->lastModified();
|
||||
if (lastModified > mapIt.value()) {
|
||||
if (debugWatcher)
|
||||
qDebug() << Q_FUNC_INFO << "emitting file changed" << path;
|
||||
emit fileChanged(path);
|
||||
m_files[path] = lastModified;
|
||||
}
|
||||
removedFiles.removeOne(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!removedFiles.isEmpty()) {
|
||||
foreach (const QString &file, removedFiles)
|
||||
removeFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
int FileWatcher::m_objectCount = 0;
|
||||
QHash<QString,int> FileWatcher::m_fileCount;
|
||||
QFileSystemWatcher *FileWatcher::m_watcher = 0;
|
||||
@@ -256,7 +97,5 @@ void FileWatcher::removeFile(const QString &file)
|
||||
m_watcher->removePath(file);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Qt4ProjectManager
|
||||
|
||||
Reference in New Issue
Block a user