Commit cdbbf377 authored by Daniel Teske's avatar Daniel Teske

Qt4Project: Do not trigger updateCodeModels on folderChanged

This reverts commit 2fdb70bd.
Be smarter about what to do on folder changes. Trigger at most
one codemodel update per folder change signal. (Thus still fixing
the original problem 2fdb70bd fixed.) And only trigger one if the
actual file list changes. This could be further optimized to only
tell the code model about the new files, but that's for another
patch.

Task-number: QTCREATORBUG-9697
Change-Id: I78d134663f1455254caf812c27c048d4f0828242
Reviewed-by: default avatarFawzi Mohamed <fawzi.mohamed@digia.com>
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent dea96728
......@@ -557,7 +557,7 @@ QStringList Qt4PriFileNode::fullVPaths(const QStringList &baseVPaths, QtSupport:
return vPaths;
}
static QSet<Utils::FileName> recursiveEnumerate(const QString &folder)
QSet<Utils::FileName> Qt4PriFileNode::recursiveEnumerate(const QString &folder)
{
QSet<Utils::FileName> result;
QFileInfo fi(folder);
......@@ -718,10 +718,66 @@ void Qt4PriFileNode::watchFolders(const QSet<QString> &folders)
m_watchedFolders = folders;
}
void Qt4PriFileNode::folderChanged(const QString &changedFolder)
bool Qt4PriFileNode::folderChanged(const QString &changedFolder, const QSet<Utils::FileName> &newFiles)
{
Q_UNUSED(changedFolder);
scheduleUpdate();
//qDebug()<<"########## Qt4PriFileNode::folderChanged";
// So, we need to figure out which files changed.
QSet<Utils::FileName> addedFiles = newFiles;
addedFiles.subtract(m_recursiveEnumerateFiles);
QSet<Utils::FileName> removedFiles = m_recursiveEnumerateFiles;
removedFiles.subtract(newFiles);
foreach (const Utils::FileName &file, removedFiles) {
if (!file.isChildOf(Utils::FileName::fromString(changedFolder)))
removedFiles.remove(file);
}
if (addedFiles.isEmpty() && removedFiles.isEmpty())
return false;
m_recursiveEnumerateFiles = newFiles;
// Apply the differences
// per file type
const QVector<Qt4NodeStaticData::FileTypeData> &fileTypes = qt4NodeStaticData()->fileTypeData;
for (int i = 0; i < fileTypes.size(); ++i) {
FileType type = fileTypes.at(i).type;
QSet<Utils::FileName> add = filterFilesRecursiveEnumerata(type, addedFiles);
QSet<Utils::FileName> remove = filterFilesRecursiveEnumerata(type, removedFiles);
if (!add.isEmpty() || !remove.isEmpty()) {
// Scream :)
// qDebug()<<"For type"<<fileTypes.at(i).typeName<<"\n"
// <<"added files"<<add<<"\n"
// <<"removed files"<<remove;
m_files[type].unite(add);
m_files[type].subtract(remove);
}
}
// Now apply stuff
InternalNode contents;
for (int i = 0; i < fileTypes.size(); ++i) {
FileType type = fileTypes.at(i).type;
if (!m_files[type].isEmpty()) {
InternalNode *subfolder = new InternalNode;
subfolder->type = type;
subfolder->icon = fileTypes.at(i).icon;
subfolder->fullPath = m_projectDir;
subfolder->typeName = fileTypes.at(i).typeName;
subfolder->priority = -i;
subfolder->displayName = fileTypes.at(i).typeName;
contents.virtualfolders.append(subfolder);
// create the hierarchy with subdirectories
subfolder->create(m_projectDir, m_files[type], type);
}
}
contents.updateSubFolders(this, this);
return true;
}
bool Qt4PriFileNode::deploysFolder(const QString &folder) const
......
......@@ -162,7 +162,7 @@ public:
bool renameFile(const FileType fileType,
const QString &filePath, const QString &newFilePath);
void folderChanged(const QString &changedFolder);
bool folderChanged(const QString &changedFolder, const QSet<Utils::FileName> &newFiles);
bool deploysFolder(const QString &folder) const;
QList<ProjectExplorer::RunConfiguration *> runConfigurationsFor(Node *node);
......@@ -172,6 +172,7 @@ public:
// Set by parent
bool includedInExactParse() const;
static QSet<Utils::FileName> recursiveEnumerate(const QString &folder);
protected:
void setIncludedInExactParse(bool b);
static QStringList varNames(FileType type);
......
......@@ -146,7 +146,7 @@ class CentralizedFolderWatcher : public QObject
{
Q_OBJECT
public:
CentralizedFolderWatcher(QObject *parent);
CentralizedFolderWatcher(Qt4Project *parent);
~CentralizedFolderWatcher();
void watchFolders(const QList<QString> &folders, Qt4ProjectManager::Qt4PriFileNode *node);
void unwatchFolders(const QList<QString> &folders, Qt4ProjectManager::Qt4PriFileNode *node);
......@@ -157,6 +157,7 @@ private slots:
void delayedFolderChanged(const QString &folder);
private:
Qt4Project *m_project;
QSet<QString> recursiveDirs(const QString &folder);
QFileSystemWatcher m_watcher;
QMultiMap<QString, Qt4ProjectManager::Qt4PriFileNode *> m_map;
......@@ -1215,7 +1216,8 @@ namespace {
bool debugCFW = false;
}
CentralizedFolderWatcher::CentralizedFolderWatcher(QObject *parent) : QObject(parent)
CentralizedFolderWatcher::CentralizedFolderWatcher(Qt4Project *parent)
: QObject(parent), m_project(parent)
{
m_compressTimer.setSingleShot(true);
m_compressTimer.setInterval(200);
......@@ -1337,12 +1339,19 @@ void CentralizedFolderWatcher::delayedFolderChanged(const QString &folder)
QString dir = folder;
const QChar slash = QLatin1Char('/');
bool newOrRemovedFiles = false;
while (true) {
if (!dir.endsWith(slash))
dir.append(slash);
QList<Qt4ProjectManager::Qt4PriFileNode *> nodes = m_map.values(dir);
foreach (Qt4ProjectManager::Qt4PriFileNode *node, nodes) {
node->folderChanged(folder);
if (!nodes.isEmpty()) {
// Collect all the files
QSet<Utils::FileName> newFiles;
newFiles += Qt4PriFileNode::recursiveEnumerate(folder);
foreach (Qt4ProjectManager::Qt4PriFileNode *node, nodes) {
newOrRemovedFiles = newOrRemovedFiles
|| node->folderChanged(folder, newFiles);
}
}
// Chop off last part, and break if there's nothing to chop off
......@@ -1357,7 +1366,6 @@ void CentralizedFolderWatcher::delayedFolderChanged(const QString &folder)
dir.truncate(index + 1);
}
QString folderWithSlash = folder;
if (!folder.endsWith(slash))
folderWithSlash.append(slash);
......@@ -1374,6 +1382,11 @@ void CentralizedFolderWatcher::delayedFolderChanged(const QString &folder)
m_watcher.addPaths(tmp.toList());
m_recursiveWatchedFolders += tmp;
}
if (newOrRemovedFiles) {
m_project->updateFileList();
m_project->updateCodeModels();
}
}
bool Qt4Project::needsConfiguration() const
......
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