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 @@ ...@@ -34,6 +34,7 @@
#include "project.h" #include "project.h"
#include "projectnodes.h" #include "projectnodes.h"
#include "projectexplorerconstants.h" #include "projectexplorerconstants.h"
#include "nodesvisitor.h"
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
...@@ -187,11 +188,16 @@ void ProjectTree::updateFromDocumentManager(bool invalidCurrentNode) ...@@ -187,11 +188,16 @@ void ProjectTree::updateFromDocumentManager(bool invalidCurrentNode)
else else
currentNode = ProjectTreeWidget::nodeForFile(fileName); 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) foreach (ProjectTreeWidget *widget, m_projectTreeWidgets)
widget->sync(currentNode); widget->sync(node);
} }
void ProjectTree::update(Node *node, Project *project) void ProjectTree::update(Node *node, Project *project)
...@@ -289,6 +295,8 @@ void ProjectTree::emitFoldersAboutToBeAdded(FolderNode *parentFolder, const QLis ...@@ -289,6 +295,8 @@ void ProjectTree::emitFoldersAboutToBeAdded(FolderNode *parentFolder, const QLis
if (!isInNodeHierarchy(parentFolder)) if (!isInNodeHierarchy(parentFolder))
return; return;
m_foldersAdded = newFolders;
emit foldersAboutToBeAdded(parentFolder, newFolders); emit foldersAboutToBeAdded(parentFolder, newFolders);
} }
...@@ -302,7 +310,22 @@ void ProjectTree::emitFoldersAdded(FolderNode *folder) ...@@ -302,7 +310,22 @@ void ProjectTree::emitFoldersAdded(FolderNode *folder)
if (Utils::anyOf(m_projectTreeWidgets, &ProjectTreeWidget::hasFocus)) if (Utils::anyOf(m_projectTreeWidgets, &ProjectTreeWidget::hasFocus))
return; 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) void ProjectTree::emitFoldersAboutToBeRemoved(FolderNode *parentFolder, const QList<FolderNode *> &staleFolders)
...@@ -344,6 +367,7 @@ void ProjectTree::emitFilesAboutToBeAdded(FolderNode *folder, const QList<FileNo ...@@ -344,6 +367,7 @@ void ProjectTree::emitFilesAboutToBeAdded(FolderNode *folder, const QList<FileNo
{ {
if (!isInNodeHierarchy(folder)) if (!isInNodeHierarchy(folder))
return; return;
m_filesAdded = newFiles;
emit filesAboutToBeAdded(folder, newFiles); emit filesAboutToBeAdded(folder, newFiles);
} }
...@@ -357,7 +381,20 @@ void ProjectTree::emitFilesAdded(FolderNode *folder) ...@@ -357,7 +381,20 @@ void ProjectTree::emitFilesAdded(FolderNode *folder)
if (Utils::anyOf(m_projectTreeWidgets, &ProjectTreeWidget::hasFocus)) if (Utils::anyOf(m_projectTreeWidgets, &ProjectTreeWidget::hasFocus))
return; 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) void ProjectTree::emitFilesAboutToBeRemoved(FolderNode *folder, const QList<FileNode *> &staleFiles)
......
...@@ -135,6 +135,7 @@ private: ...@@ -135,6 +135,7 @@ private:
void updateFromProjectTreeWidget(Internal::ProjectTreeWidget *widget); void updateFromProjectTreeWidget(Internal::ProjectTreeWidget *widget);
void documentManagerCurrentFileChanged(); void documentManagerCurrentFileChanged();
void updateFromDocumentManager(bool invalidCurrentNode = false); void updateFromDocumentManager(bool invalidCurrentNode = false);
void updateFromNode(Node *node);
void update(Node *node, Project *project); void update(Node *node, Project *project);
void updateContext(); void updateContext();
...@@ -150,6 +151,8 @@ private: ...@@ -150,6 +151,8 @@ private:
QList<Internal::ProjectTreeWidget *> m_projectTreeWidgets; QList<Internal::ProjectTreeWidget *> m_projectTreeWidgets;
Node *m_currentNode; Node *m_currentNode;
Project *m_currentProject; Project *m_currentProject;
QList<FileNode *> m_filesAdded;
QList<FolderNode *> m_foldersAdded;
bool m_resetCurrentNodeFolder; bool m_resetCurrentNodeFolder;
bool m_resetCurrentNodeFile; bool m_resetCurrentNodeFile;
bool m_resetCurrentNodeProject; bool m_resetCurrentNodeProject;
......
...@@ -237,11 +237,16 @@ void ProjectTreeWidget::rowsInserted(const QModelIndex &parent, int start, int e ...@@ -237,11 +237,16 @@ void ProjectTreeWidget::rowsInserted(const QModelIndex &parent, int start, int e
} }
Node *ProjectTreeWidget::nodeForFile(const Utils::FileName &fileName) Node *ProjectTreeWidget::nodeForFile(const Utils::FileName &fileName)
{
return mostExpandedNode(SessionManager::nodesForFile(fileName));
}
Node *ProjectTreeWidget::mostExpandedNode(const QList<Node *> &nodes)
{ {
Node *bestNode = 0; Node *bestNode = 0;
int bestNodeExpandCount = INT_MAX; int bestNodeExpandCount = INT_MAX;
foreach (Node *node, SessionManager::nodesForFile(fileName)) { foreach (Node *node, nodes) {
if (!bestNode) { if (!bestNode) {
bestNode = node; bestNode = node;
bestNodeExpandCount = ProjectTreeWidget::expandedCount(node); bestNodeExpandCount = ProjectTreeWidget::expandedCount(node);
...@@ -256,7 +261,6 @@ Node *ProjectTreeWidget::nodeForFile(const Utils::FileName &fileName) ...@@ -256,7 +261,6 @@ Node *ProjectTreeWidget::nodeForFile(const Utils::FileName &fileName)
} }
} }
} }
return bestNode; return bestNode;
} }
......
...@@ -68,6 +68,7 @@ public: ...@@ -68,6 +68,7 @@ public:
void sync(ProjectExplorer::Node *node); void sync(ProjectExplorer::Node *node);
static Node *nodeForFile(const Utils::FileName &fileName); static Node *nodeForFile(const Utils::FileName &fileName);
static Node *mostExpandedNode(const QList<Node*> &nodes);
public slots: public slots:
void toggleAutoSynchronization(); 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