Commit facc89fa authored by Daniel Teske's avatar Daniel Teske

Optimize ProjectTree for adding folders/files

Instead of searching the whole tree for the current node,
only check the newly added files/folders.

Change-Id: I015a955815223767367c4cad476d0620f69abd71
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
parent 159f4e4f
......@@ -34,6 +34,7 @@
#include "project.h"
#include "projectnodes.h"
#include "projectexplorerconstants.h"
#include "nodesvisitor.h"
#include <utils/algorithm.h>
#include <coreplugin/icore.h>
......@@ -187,11 +188,16 @@ void ProjectTree::updateFromDocumentManager(bool invalidCurrentNode)
else
currentNode = ProjectTreeWidget::nodeForFile(fileName);
Project *project = projectForNode(currentNode);
updateFromNode(currentNode);
}
update(currentNode, project);
void ProjectTree::updateFromNode(Node *node)
{
Project *project = projectForNode(node);
update(node, project);
foreach (ProjectTreeWidget *widget, m_projectTreeWidgets)
widget->sync(currentNode);
widget->sync(node);
}
void ProjectTree::update(Node *node, Project *project)
......@@ -289,6 +295,8 @@ void ProjectTree::emitFoldersAboutToBeAdded(FolderNode *parentFolder, const QLis
if (!isInNodeHierarchy(parentFolder))
return;
m_foldersAdded = newFolders;
emit foldersAboutToBeAdded(parentFolder, newFolders);
}
......@@ -302,7 +310,22 @@ void ProjectTree::emitFoldersAdded(FolderNode *folder)
if (Utils::anyOf(m_projectTreeWidgets, &ProjectTreeWidget::hasFocus))
return;
updateFromDocumentManager();
if (!m_currentNode) {
Core::IDocument *document = Core::EditorManager::currentDocument();
const FileName fileName = document ? document->filePath() : FileName();
FindNodesForFileVisitor findNodes(fileName);
foreach (FolderNode *fn, m_foldersAdded)
fn->accept(&findNodes);
Node *bestNode = ProjectTreeWidget::mostExpandedNode(findNodes.nodes());
if (!bestNode)
return;
updateFromNode(bestNode);
}
m_foldersAdded.clear();
}
void ProjectTree::emitFoldersAboutToBeRemoved(FolderNode *parentFolder, const QList<FolderNode *> &staleFolders)
......@@ -344,6 +367,7 @@ void ProjectTree::emitFilesAboutToBeAdded(FolderNode *folder, const QList<FileNo
{
if (!isInNodeHierarchy(folder))
return;
m_filesAdded = newFiles;
emit filesAboutToBeAdded(folder, newFiles);
}
......@@ -357,7 +381,20 @@ void ProjectTree::emitFilesAdded(FolderNode *folder)
if (Utils::anyOf(m_projectTreeWidgets, &ProjectTreeWidget::hasFocus))
return;
updateFromDocumentManager();
if (!m_currentNode) {
Core::IDocument *document = Core::EditorManager::currentDocument();
const FileName fileName = document ? document->filePath() : FileName();
int index = Utils::indexOf(m_filesAdded, [&fileName](FileNode *node) {
return node->path() == fileName;
});
if (index == -1)
return;
updateFromNode(m_filesAdded.at(index));
}
m_filesAdded.clear();
}
void ProjectTree::emitFilesAboutToBeRemoved(FolderNode *folder, const QList<FileNode *> &staleFiles)
......
......@@ -135,6 +135,7 @@ private:
void updateFromProjectTreeWidget(Internal::ProjectTreeWidget *widget);
void documentManagerCurrentFileChanged();
void updateFromDocumentManager(bool invalidCurrentNode = false);
void updateFromNode(Node *node);
void update(Node *node, Project *project);
void updateContext();
......@@ -150,6 +151,8 @@ private:
QList<Internal::ProjectTreeWidget *> m_projectTreeWidgets;
Node *m_currentNode;
Project *m_currentProject;
QList<FileNode *> m_filesAdded;
QList<FolderNode *> m_foldersAdded;
bool m_resetCurrentNodeFolder;
bool m_resetCurrentNodeFile;
bool m_resetCurrentNodeProject;
......
......@@ -237,11 +237,16 @@ void ProjectTreeWidget::rowsInserted(const QModelIndex &parent, int start, int e
}
Node *ProjectTreeWidget::nodeForFile(const Utils::FileName &fileName)
{
return mostExpandedNode(SessionManager::nodesForFile(fileName));
}
Node *ProjectTreeWidget::mostExpandedNode(const QList<Node *> &nodes)
{
Node *bestNode = 0;
int bestNodeExpandCount = INT_MAX;
foreach (Node *node, SessionManager::nodesForFile(fileName)) {
foreach (Node *node, nodes) {
if (!bestNode) {
bestNode = node;
bestNodeExpandCount = ProjectTreeWidget::expandedCount(node);
......@@ -256,7 +261,6 @@ Node *ProjectTreeWidget::nodeForFile(const Utils::FileName &fileName)
}
}
}
return bestNode;
}
......
......@@ -68,6 +68,7 @@ public:
void sync(ProjectExplorer::Node *node);
static Node *nodeForFile(const Utils::FileName &fileName);
static Node *mostExpandedNode(const QList<Node*> &nodes);
public slots:
void toggleAutoSynchronization();
......
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