aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/resourceeditor/resourcenode.cpp
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2019-12-09 13:47:42 +0100
committerChristian Kandeler <christian.kandeler@qt.io>2019-12-09 13:48:41 +0000
commitb82add7813384c19879044b44796db1f8f067ad3 (patch)
treebbb141f30564553af45e530d225740aab35fb3c3 /src/plugins/resourceeditor/resourcenode.cpp
parent8f682573a819b6665c6b878d3921dc124af842e8 (diff)
ResourceEditor: Fix priority for qrc sub-nodes
When adding a new file to a qrc file via the context menu, the wrong project tree node was pre-selected in the wizard unless the user had run the context menu either from the ".qrc" node or a qrc prefix node that was *not* the one for the "/" prefix. Now this works correctly for all nodes at or below the ".qrc" node. Fixes: QTCREATORBUG-23210 Change-Id: Ia5e234e9861a480f973b76f8e3026ebc9c73ec35 Reviewed-by: hjk <hjk@qt.io>
Diffstat (limited to 'src/plugins/resourceeditor/resourcenode.cpp')
-rw-r--r--src/plugins/resourceeditor/resourcenode.cpp31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/plugins/resourceeditor/resourcenode.cpp b/src/plugins/resourceeditor/resourcenode.cpp
index 13d23eee23..5a9e2aef6a 100644
--- a/src/plugins/resourceeditor/resourcenode.cpp
+++ b/src/plugins/resourceeditor/resourcenode.cpp
@@ -41,6 +41,8 @@
#include <QDir>
#include <QDebug>
+#include <limits>
+
using namespace Core;
using namespace ProjectExplorer;
using namespace Utils;
@@ -106,6 +108,18 @@ private:
QString m_lang;
};
+static int getPriorityFromContextNode(const ProjectExplorer::Node *resourceNode,
+ const ProjectExplorer::Node *contextNode)
+{
+ if (contextNode == resourceNode)
+ return std::numeric_limits<int>::max();
+ for (const ProjectExplorer::Node *n = contextNode; n; n = n->parentFolderNode()) {
+ if (n == resourceNode)
+ return std::numeric_limits<int>::max() - 1;
+ }
+ return -1;
+}
+
static bool hasPriority(const QStringList &files)
{
if (files.isEmpty())
@@ -438,22 +452,13 @@ FolderNode::AddNewInformation ResourceTopLevelNode::addNewInformation(const QStr
.arg(filePath().fileName())
.arg(QLatin1Char('/'));
- int p = -1;
- if (hasPriority(files)) { // images/* and qml/js mimetypes
+ int p = getPriorityFromContextNode(this, context);
+ if (p == -1 && hasPriority(files)) { // images/* and qml/js mimetypes
p = 110;
if (context == this)
p = 120;
else if (parentProjectNode() == context)
p = 150; // steal from our project node
- // The ResourceFolderNode '/' defers to us, as otherwise
- // two nodes would be responsible for '/'
- // Thus also return a high priority for it
- if (auto rfn = dynamic_cast<ResourceFolderNode *>(context))
- if (rfn->prefix() == QLatin1String("/") && rfn->parentFolderNode() == this)
- p = 120;
- if (auto rfn = dynamic_cast<SimpleResourceFolderNode *>(context))
- if (rfn->prefix() == QLatin1String("/") && rfn->resourceNode() == this)
- p = 120;
}
return AddNewInformation(name, p);
@@ -588,8 +593,8 @@ FolderNode::AddNewInformation ResourceFolderNode::addNewInformation(const QStrin
.arg(m_topLevelNode->filePath().fileName())
.arg(displayName());
- int p = -1; // never the default
- if (hasPriority(files)) { // image/* and qml/js mimetypes
+ int p = getPriorityFromContextNode(this, context);
+ if (p == -1 && hasPriority(files)) { // image/* and qml/js mimetypes
p = 105; // prefer against .pro and .pri files
if (context == this)
p = 120;