diff options
author | hjk <hjk@qt.io> | 2017-03-15 15:46:48 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2017-04-05 12:47:03 +0000 |
commit | bd5e2faa756f1c852a0d7ae019561413e5278cc3 (patch) | |
tree | e1d0680c4e5e5fa9aeb6db14ecbc48c6d67ceae8 /src/plugins/resourceeditor | |
parent | 8410c0bbad626c8ca38a161968c71a09ffb47df7 (diff) |
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>
Diffstat (limited to 'src/plugins/resourceeditor')
-rw-r--r-- | src/plugins/resourceeditor/resourceeditorplugin.cpp | 4 | ||||
-rw-r--r-- | src/plugins/resourceeditor/resourcenode.cpp | 67 | ||||
-rw-r--r-- | src/plugins/resourceeditor/resourcenode.h | 6 |
3 files changed, 38 insertions, 39 deletions
diff --git a/src/plugins/resourceeditor/resourceeditorplugin.cpp b/src/plugins/resourceeditor/resourceeditorplugin.cpp index 474092d350..1ae83161ca 100644 --- a/src/plugins/resourceeditor/resourceeditorplugin.cpp +++ b/src/plugins/resourceeditor/resourceeditorplugin.cpp @@ -338,8 +338,8 @@ void ResourceEditorPlugin::updateContextActions() if (isResourceNode) { FolderNode *parent = node ? node->parentFolderNode() : 0; - enableRename = parent && parent->supportedActions(node).contains(Rename); - enableRemove = parent && parent->supportedActions(node).contains(RemoveFile); + enableRename = parent && parent->supportsAction(Rename, node); + enableRemove = parent && parent->supportsAction(RemoveFile, node); } m_renameResourceFile->setEnabled(isResourceNode && enableRename); diff --git a/src/plugins/resourceeditor/resourcenode.cpp b/src/plugins/resourceeditor/resourcenode.cpp index 49c640840a..ffe74eeb42 100644 --- a/src/plugins/resourceeditor/resourcenode.cpp +++ b/src/plugins/resourceeditor/resourcenode.cpp @@ -160,7 +160,7 @@ public: ResourceTopLevelNode *topLevel, ResourceFolderNode *prefixNode); QString displayName() const final; - QList<ProjectAction> supportedActions(Node *node) const final; + bool supportsAction(ProjectAction, Node *node) const final; bool addFiles(const QStringList &filePaths, QStringList *notAdded) final; bool removeFiles(const QStringList &filePaths, QStringList *notRemoved) final; bool renameFile(const QString &filePath, const QString &newFilePath) final; @@ -199,17 +199,15 @@ SimpleResourceFolderNode::SimpleResourceFolderNode(const QString &afolderName, c } -QList<ProjectAction> SimpleResourceFolderNode::supportedActions(Node *) const +bool SimpleResourceFolderNode::supportsAction(ProjectAction action, Node *) const { - return { - AddNewFile, - AddExistingFile, - AddExistingDirectory, - RemoveFile, - DuplicateFile, - Rename, // Note: only works for the filename, works akwardly for relative file paths - InheritedFromParent // Do not add to list of projects when adding new file - }; + return action == AddNewFile + || action == AddExistingFile + || action == AddExistingDirectory + || action == RemoveFile + || action == DuplicateFile + || action == Rename // Note: only works for the filename, works akwardly for relative file paths + || action == InheritedFromParent; // Do not add to list of projects when adding new file } bool SimpleResourceFolderNode::addFiles(const QStringList &filePaths, QStringList *notAdded) @@ -387,11 +385,15 @@ QString ResourceTopLevelNode::addFileFilter() const return QLatin1String("*.png; *.jpg; *.gif; *.svg; *.ico; *.qml; *.qml.ui"); } -QList<ProjectAction> ResourceTopLevelNode::supportedActions(Node *node) const +bool ResourceTopLevelNode::supportsAction(ProjectAction action, Node *node) const { if (node != this) - return {}; - return {AddNewFile, AddExistingFile, AddExistingDirectory, HidePathActions, Rename}; + return false; + return action == AddNewFile + || action == AddExistingFile + || action == AddExistingDirectory + || action == HidePathActions + || action == Rename; } bool ResourceTopLevelNode::addFiles(const QStringList &filePaths, QStringList *notAdded) @@ -504,25 +506,23 @@ ResourceFolderNode::~ResourceFolderNode() } -QList<ProjectAction> ResourceFolderNode::supportedActions(Node *node) const +bool ResourceFolderNode::supportsAction(ProjectAction action, Node *node) const { Q_UNUSED(node) - QList<ProjectAction> actions = { - AddNewFile, - AddExistingFile, - AddExistingDirectory, - RemoveFile, - DuplicateFile, - Rename, // Note: only works for the filename, works akwardly for relative file paths - HidePathActions, // hides open terminal etc. - }; - // if the prefix is '/' (without lang) hide this node in add new dialog, - // as the ResouceTopLevelNode is always shown for the '/' prefix - if (m_prefix == QLatin1String("/") && m_lang.isEmpty()) - actions << InheritedFromParent; + if (action == InheritedFromParent) { + // if the prefix is '/' (without lang) hide this node in add new dialog, + // as the ResouceTopLevelNode is always shown for the '/' prefix + return m_prefix == QLatin1String("/") && m_lang.isEmpty(); + } - return actions; + return action == AddNewFile + || action == AddExistingFile + || action == AddExistingDirectory + || action == RemoveFile + || action == DuplicateFile + || action == Rename // Note: only works for the filename, works akwardly for relative file paths + || action == HidePathActions; // hides open terminal etc. } bool ResourceFolderNode::addFiles(const QStringList &filePaths, QStringList *notAdded) @@ -674,12 +674,11 @@ QString ResourceFileNode::qrcPath() const return m_qrcPath; } -QList<ProjectAction> ResourceFileNode::supportedActions(Node *node) const +bool ResourceFileNode::supportsAction(ProjectAction action, Node *node) const { - QList<ProjectAction> actions = parentFolderNode()->supportedActions(node); - actions.removeOne(HidePathActions); - return actions; + if (action == HidePathActions) + return false; + return parentFolderNode()->supportsAction(action, node); } - } // ResourceEditor diff --git a/src/plugins/resourceeditor/resourcenode.h b/src/plugins/resourceeditor/resourcenode.h index aa7ff02580..0d6b7a1b64 100644 --- a/src/plugins/resourceeditor/resourcenode.h +++ b/src/plugins/resourceeditor/resourcenode.h @@ -41,7 +41,7 @@ public: QString addFileFilter() const override; - QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const override; + bool supportsAction(ProjectExplorer::ProjectAction action, Node *node) const override; bool addFiles(const QStringList &filePaths, QStringList *notAdded) override; bool removeFiles(const QStringList &filePaths, QStringList *notRemoved) override; @@ -67,7 +67,7 @@ public: ResourceFolderNode(const QString &prefix, const QString &lang, ResourceTopLevelNode *parent); ~ResourceFolderNode() override; - QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const override; + bool supportsAction(ProjectExplorer::ProjectAction action, Node *node) const override; QString displayName() const override; @@ -97,7 +97,7 @@ public: QString displayName() const override; QString qrcPath() const; - QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const override; + bool supportsAction(ProjectExplorer::ProjectAction action, Node *node) const override; private: QString m_qrcPath; |