Commit 2978f08b authored by Daniel Teske's avatar Daniel Teske
Browse files

New File Wizard: Fine tune selection of best node



If the user right clicked on a node and invoked the new dialog that way,
always consider that node even if it is deeper in the file system tree
than the new files.

Task-number: QTCREATORBUG-13215
Change-Id: Ic87033cb9a5e480eee8fb56eacad506d2fd39653
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 9477250b
...@@ -73,7 +73,7 @@ class BestNodeSelector ...@@ -73,7 +73,7 @@ class BestNodeSelector
{ {
public: public:
BestNodeSelector(const QString &commonDirectory, const QStringList &files); BestNodeSelector(const QString &commonDirectory, const QStringList &files);
void inspect(AddNewTree *tree); void inspect(AddNewTree *tree, bool isContextNode);
AddNewTree *bestChoice() const; AddNewTree *bestChoice() const;
bool deploys(); bool deploys();
QString deployingProjects() const; QString deployingProjects() const;
...@@ -102,7 +102,7 @@ BestNodeSelector::BestNodeSelector(const QString &commonDirectory, const QString ...@@ -102,7 +102,7 @@ BestNodeSelector::BestNodeSelector(const QString &commonDirectory, const QString
// Otherwise consider their common path. Either a direct match on the directory // Otherwise consider their common path. Either a direct match on the directory
// or the directory with the longest matching path (list containing"/project/subproject1" // or the directory with the longest matching path (list containing"/project/subproject1"
// matching common path "/project/subproject1/newuserpath"). // matching common path "/project/subproject1/newuserpath").
void BestNodeSelector::inspect(AddNewTree *tree) void BestNodeSelector::inspect(AddNewTree *tree, bool isContextNode)
{ {
FolderNode *node = tree->node(); FolderNode *node = tree->node();
if (node->nodeType() == ProjectNodeType) { if (node->nodeType() == ProjectNodeType) {
...@@ -115,7 +115,7 @@ void BestNodeSelector::inspect(AddNewTree *tree) ...@@ -115,7 +115,7 @@ void BestNodeSelector::inspect(AddNewTree *tree)
return; return;
const QString projectDirectory = ProjectExplorerPlugin::directoryFor(node); const QString projectDirectory = ProjectExplorerPlugin::directoryFor(node);
const int projectDirectorySize = projectDirectory.size(); const int projectDirectorySize = projectDirectory.size();
if (!m_commonDirectory.startsWith(projectDirectory)) if (!m_commonDirectory.startsWith(projectDirectory) && !isContextNode)
return; return;
bool betterMatch = tree->priority() > 0 bool betterMatch = tree->priority() > 0
&& (projectDirectorySize > m_bestMatchLength && (projectDirectorySize > m_bestMatchLength
...@@ -173,7 +173,7 @@ static inline AddNewTree *buildAddProjectTree(ProjectNode *root, const QString & ...@@ -173,7 +173,7 @@ static inline AddNewTree *buildAddProjectTree(ProjectNode *root, const QString &
if (projectPath.isEmpty() || root->canAddSubProject(projectPath)) { if (projectPath.isEmpty() || root->canAddSubProject(projectPath)) {
FolderNode::AddNewInformation info = root->addNewInformation(QStringList() << projectPath, contextNode); FolderNode::AddNewInformation info = root->addNewInformation(QStringList() << projectPath, contextNode);
AddNewTree *item = new AddNewTree(root, children, info); AddNewTree *item = new AddNewTree(root, children, info);
selector->inspect(item); selector->inspect(item, root == contextNode);
return item; return item;
} }
} }
...@@ -208,7 +208,7 @@ static inline AddNewTree *buildAddFilesTree(FolderNode *root, const QStringList ...@@ -208,7 +208,7 @@ static inline AddNewTree *buildAddFilesTree(FolderNode *root, const QStringList
if (list.contains(AddNewFile) && !list.contains(InheritedFromParent)) { if (list.contains(AddNewFile) && !list.contains(InheritedFromParent)) {
FolderNode::AddNewInformation info = root->addNewInformation(files, contextNode); FolderNode::AddNewInformation info = root->addNewInformation(files, contextNode);
AddNewTree *item = new AddNewTree(root, children, info); AddNewTree *item = new AddNewTree(root, children, info);
selector->inspect(item); selector->inspect(item, root == contextNode);
return item; return item;
} }
if (children.isEmpty()) if (children.isEmpty())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment