forked from qt-creator/qt-creator
ProjectNodes: Handle supported actions one-by-one
Getting the full list for a node can get quite expensive e.g. in cases of recursive calls of QMakeProjectManager::findPriFile. However, the FlatModel needs to decide quickly on whether an item is editable to potentially allow renaming. So split up QList<Actions> supportedActions() into individual bool supportsAction(action) calls and make sure Rename is not on the critical path. Task-number: QTCREATORBUG-17953 Change-Id: I31841847f8aa7d7b94c63d76ce71efb1c930fa69 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -45,6 +45,8 @@
|
||||
#include <QIcon>
|
||||
#include <QStyle>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Helpers:
|
||||
// ----------------------------------------------------------------------
|
||||
@@ -223,26 +225,23 @@ public:
|
||||
};
|
||||
|
||||
|
||||
static QList<ProjectExplorer::ProjectAction> supportedNodeActions(ProjectExplorer::Node *node,
|
||||
bool managesFiles)
|
||||
static bool supportsNodeAction(ProjectAction action, Node *node)
|
||||
{
|
||||
QList<ProjectExplorer::ProjectAction> actions;
|
||||
const QbsProject * const project = parentQbsProjectNode(node)->project();
|
||||
if (!project->isProjectEditable())
|
||||
return actions;
|
||||
if (managesFiles)
|
||||
actions << ProjectExplorer::AddNewFile << ProjectExplorer::AddExistingFile;
|
||||
return false;
|
||||
|
||||
auto equalsNodeFilePath = [node](const QString &str)
|
||||
{
|
||||
return str == node->filePath().toString();
|
||||
};
|
||||
|
||||
if (node->nodeType() == ProjectExplorer::NodeType::File
|
||||
&& !Utils::contains(project->qbsProject().buildSystemFiles(), equalsNodeFilePath)) {
|
||||
actions << ProjectExplorer::RemoveFile << ProjectExplorer::Rename;
|
||||
if (action == RemoveFile || action == Rename) {
|
||||
if (node->nodeType() == ProjectExplorer::NodeType::File)
|
||||
return !Utils::contains(project->qbsProject().buildSystemFiles(), equalsNodeFilePath);
|
||||
}
|
||||
return actions;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
@@ -271,9 +270,9 @@ QbsFolderNode::QbsFolderNode(const Utils::FileName &folderPath, ProjectExplorer:
|
||||
{
|
||||
}
|
||||
|
||||
QList<ProjectExplorer::ProjectAction> QbsFolderNode::supportedActions(ProjectExplorer::Node *node) const
|
||||
bool QbsFolderNode::supportsAction(ProjectAction action, Node *node) const
|
||||
{
|
||||
return supportedNodeActions(node, false);
|
||||
return supportsNodeAction(action, node);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -289,12 +288,6 @@ bool QbsBaseProjectNode::showInSimpleTree() const
|
||||
return false;
|
||||
}
|
||||
|
||||
QList<ProjectExplorer::ProjectAction> QbsBaseProjectNode::supportedActions(ProjectExplorer::Node *node) const
|
||||
{
|
||||
Q_UNUSED(node);
|
||||
return QList<ProjectExplorer::ProjectAction>();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// QbsGroupNode:
|
||||
// --------------------------------------------------------------------
|
||||
@@ -309,9 +302,12 @@ QbsGroupNode::QbsGroupNode(const qbs::GroupData &grp, const QString &productPath
|
||||
m_qbsGroupData = grp;
|
||||
}
|
||||
|
||||
QList<ProjectExplorer::ProjectAction> QbsGroupNode::supportedActions(ProjectExplorer::Node *node) const
|
||||
bool QbsGroupNode::supportsAction(ProjectAction action, Node *node) const
|
||||
{
|
||||
return supportedNodeActions(node, true);
|
||||
if (action == AddNewFile || action == AddExistingFile)
|
||||
return true;
|
||||
|
||||
return supportsNodeAction(action, node);
|
||||
}
|
||||
|
||||
bool QbsGroupNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
|
||||
@@ -388,9 +384,12 @@ bool QbsProductNode::showInSimpleTree() const
|
||||
return true;
|
||||
}
|
||||
|
||||
QList<ProjectExplorer::ProjectAction> QbsProductNode::supportedActions(ProjectExplorer::Node *node) const
|
||||
bool QbsProductNode::supportsAction(ProjectAction action, Node *node) const
|
||||
{
|
||||
return supportedNodeActions(node, true);
|
||||
if (action == AddNewFile || action == AddExistingFile)
|
||||
return true;
|
||||
|
||||
return supportsNodeAction(action, node);
|
||||
}
|
||||
|
||||
bool QbsProductNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
|
||||
|
||||
Reference in New Issue
Block a user