forked from qt-creator/qt-creator
Fix that file from project is selected in file system node
The new file system node in CMake projects leads to funny selections in
the project tree when "Synchronize with Editor" is turned on.
Since the file system items are less deep in the tree than the files in
the "regular" CMake project tree, they were selected instead of the
regular project nodes.
Reduce the selection priority for the nodes in the file system sub-tree.
For this remove the hard-coded priorities when selecting nodes for
"Synchronize with Editor" and use the existing node priorities.
Amends 53115259ba
Fixes: QTCREATORBUG-25208
Change-Id: I69c08c4f0e7afa305141a0c475af515d9db1363b
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -215,6 +215,7 @@ void addFileSystemNodes(ProjectNode *root, const QList<const FileNode *> &allFil
|
|||||||
static QIcon fileSystemNodeIcon = Core::FileIconProvider::directoryIcon(
|
static QIcon fileSystemNodeIcon = Core::FileIconProvider::directoryIcon(
|
||||||
ProjectExplorer::Constants::FILEOVERLAY_UNKNOWN);
|
ProjectExplorer::Constants::FILEOVERLAY_UNKNOWN);
|
||||||
auto fileSystemNode = std::make_unique<VirtualFolderNode>(root->filePath());
|
auto fileSystemNode = std::make_unique<VirtualFolderNode>(root->filePath());
|
||||||
|
// just before special nodes like "CMake Modules"
|
||||||
fileSystemNode->setPriority(Node::DefaultPriority - 6);
|
fileSystemNode->setPriority(Node::DefaultPriority - 6);
|
||||||
fileSystemNode->setDisplayName(
|
fileSystemNode->setDisplayName(
|
||||||
QCoreApplication::translate("CMakeProjectManager::Internal::ProjectTreeHelper",
|
QCoreApplication::translate("CMakeProjectManager::Internal::ProjectTreeHelper",
|
||||||
@@ -230,8 +231,11 @@ void addFileSystemNodes(ProjectNode *root, const QList<const FileNode *> &allFil
|
|||||||
fileSystemNode->addNestedNode(std::move(node));
|
fileSystemNode->addNestedNode(std::move(node));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fileSystemNode->isEmpty())
|
if (!fileSystemNode->isEmpty()) {
|
||||||
|
// make file system nodes less probable to be selected when syncing with the current document
|
||||||
|
fileSystemNode->forEachGenericNode([](Node *n) { n->setPriority(n->priority() + 10); });
|
||||||
root->addNode(std::move(fileSystemNode));
|
root->addNode(std::move(fileSystemNode));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -358,29 +358,15 @@ Node *ProjectTreeWidget::nodeForFile(const FilePath &fileName)
|
|||||||
Node *bestNode = nullptr;
|
Node *bestNode = nullptr;
|
||||||
int bestNodeExpandCount = INT_MAX;
|
int bestNodeExpandCount = INT_MAX;
|
||||||
|
|
||||||
// FIXME: Check that the values used make sense in the context.
|
|
||||||
auto priority = [](Node *node) {
|
|
||||||
if (node->asFileNode())
|
|
||||||
return 1;
|
|
||||||
if (node->isFolderNodeType())
|
|
||||||
return 2;
|
|
||||||
if (node->isVirtualFolderType())
|
|
||||||
return 3;
|
|
||||||
if (node->isProjectNodeType())
|
|
||||||
return 4;
|
|
||||||
QTC_CHECK(false);
|
|
||||||
return 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
// FIXME: Looks like this could be done with less cycles.
|
// FIXME: Looks like this could be done with less cycles.
|
||||||
for (Project *project : SessionManager::projects()) {
|
for (Project *project : SessionManager::projects()) {
|
||||||
if (ProjectNode *projectNode = project->rootProjectNode()) {
|
if (ProjectNode *projectNode = project->rootProjectNode()) {
|
||||||
projectNode->forEachGenericNode([&](Node *node) {
|
projectNode->forEachGenericNode([&](Node *node) {
|
||||||
if (node->filePath() == fileName) {
|
if (node->filePath() == fileName) {
|
||||||
if (!bestNode || priority(node) < priority(bestNode)) {
|
if (!bestNode || node->priority() < bestNode->priority()) {
|
||||||
bestNode = node;
|
bestNode = node;
|
||||||
bestNodeExpandCount = ProjectTreeWidget::expandedCount(node);
|
bestNodeExpandCount = ProjectTreeWidget::expandedCount(node);
|
||||||
} else if (priority(node) == priority(bestNode)) {
|
} else if (node->priority() == bestNode->priority()) {
|
||||||
int nodeExpandCount = ProjectTreeWidget::expandedCount(node);
|
int nodeExpandCount = ProjectTreeWidget::expandedCount(node);
|
||||||
if (nodeExpandCount < bestNodeExpandCount) {
|
if (nodeExpandCount < bestNodeExpandCount) {
|
||||||
bestNode = node;
|
bestNode = node;
|
||||||
|
|||||||
Reference in New Issue
Block a user