New File Dialog: Tweak default node on Projct Page

The case from the bug report is:
/
 --> project.pro
 --> src
     --> foo.qrc
     --> folder
         --> file added here

Since the .qrc file is nearer then the .pro file, it was selected as the default node.
This patch makes the priority for the .qrc node -1 if it's a unmatched mime type.
That means a .qrc node will only be the default if it's either a image, a .qml or a .js
file.

Task-number: QTCREATORBUG-12793
Change-Id: I7328fd6359cc2e1959ab0bda831bd77de117baff
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
Daniel Teske
2014-08-05 16:08:45 +02:00
committed by Eike Ziller
parent f6dab5c0e3
commit 1c6394b8cd
2 changed files with 14 additions and 10 deletions

View File

@@ -136,8 +136,10 @@ void BestNodeSelector::inspect(AddNewTree *tree)
const int projectDirectorySize = projectDirectory.size();
if (!m_commonDirectory.startsWith(projectDirectory))
return;
bool betterMatch = projectDirectorySize > m_bestMatchLength
|| (projectDirectorySize == m_bestMatchLength && tree->priority() > m_bestMatchPriority);
bool betterMatch = tree->priority() > 0
&& (projectDirectorySize > m_bestMatchLength
|| (projectDirectorySize == m_bestMatchLength && tree->priority() > m_bestMatchPriority));
if (betterMatch) {
m_bestMatchPriority = tree->priority();
m_bestMatchLength = projectDirectorySize;

View File

@@ -256,10 +256,11 @@ ProjectExplorer::FolderNode::AddNewInformation ResourceTopLevelNode::addNewInfor
.arg(QFileInfo(path()).fileName())
.arg(QLatin1String("/"));
int p = 80;
if (priority(files)) {
if (context == 0 || context == this)
p = 125;
int p = -1;
if (priority(files)) { // images/* and qml/js mimetypes
p = 110;
if (context == this)
p = 120;
else if (projectNode() == context)
p = 150; // steal from our project node
// The ResourceFolderNode '/' defers to us, as otherwise
@@ -267,7 +268,7 @@ ProjectExplorer::FolderNode::AddNewInformation ResourceTopLevelNode::addNewInfor
// Thus also return a high priority for it
if (ResourceFolderNode *rfn = qobject_cast<ResourceFolderNode *>(context))
if (rfn->prefix() == QLatin1String("/") && rfn->parentFolderNode() == this)
p = 150;
p = 120;
}
return AddNewInformation(name, p);
@@ -389,9 +390,10 @@ ProjectExplorer::FolderNode::AddNewInformation ResourceFolderNode::addNewInforma
.arg(QFileInfo(m_topLevelNode->path()).fileName())
.arg(displayName());
int p = 80;
if (priority(files)) {
if (context == 0 || context == this)
int p = -1; // never the default
if (priority(files)) { // image/* and qml/js mimetypes
p = 105; // prefer against .pro and .pri files
if (context == this)
p = 120;
}