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:
@@ -57,15 +57,17 @@ bool QmlProjectNode::showInSimpleTree() const
|
||||
return true;
|
||||
}
|
||||
|
||||
QList<ProjectAction> QmlProjectNode::supportedActions(Node *node) const
|
||||
bool QmlProjectNode::supportsAction(ProjectAction action, Node *node) const
|
||||
{
|
||||
QList<ProjectAction> actions = {AddNewFile, EraseFile};
|
||||
if (node->nodeType() == NodeType::File) {
|
||||
if (action == AddNewFile || action == EraseFile)
|
||||
return true;
|
||||
|
||||
if (action == Rename && node->nodeType() == NodeType::File) {
|
||||
FileNode *fileNode = static_cast<FileNode *>(node);
|
||||
if (fileNode->fileType() != FileType::Project)
|
||||
actions.append(Rename);
|
||||
return fileNode->fileType() != FileType::Project;
|
||||
}
|
||||
return actions;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QmlProjectNode::addFiles(const QStringList &filePaths, QStringList * /*notAdded*/)
|
||||
|
||||
@@ -38,13 +38,11 @@ class QmlProjectNode : public ProjectExplorer::ProjectNode
|
||||
public:
|
||||
QmlProjectNode(QmlProject *project);
|
||||
|
||||
virtual bool showInSimpleTree() const override;
|
||||
|
||||
virtual QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const override;
|
||||
|
||||
virtual bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0) override;
|
||||
virtual bool deleteFiles(const QStringList &filePaths) override;
|
||||
virtual bool renameFile(const QString &filePath, const QString &newFilePath) override;
|
||||
bool showInSimpleTree() const override;
|
||||
bool supportsAction(ProjectExplorer::ProjectAction action, Node *node) const override;
|
||||
bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0) override;
|
||||
bool deleteFiles(const QStringList &filePaths) override;
|
||||
bool renameFile(const QString &filePath, const QString &newFilePath) override;
|
||||
|
||||
private:
|
||||
QmlProject *m_project;
|
||||
|
||||
Reference in New Issue
Block a user