Fix issues with project tree node expansion

In CMake projects, initially the project name is the directory name
that is later changed to the name defined in the project file. If
the user had expanded the project when it was still in its original
name, it would be left in the expand data as is, causing the project
to be expanded every time it is re-opened.

Fixed by checking if the name had changed and then re-inserting
possible expanded data with the new name.

Fixes: QTCREATORBUG-28681
Change-Id: I3b914fd0ae916205c86a6bd79cab5d57499d4d33
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Joni Poikelin
2023-05-24 14:05:13 +03:00
parent 9925bae16b
commit 4e1ff9ed8f

View File

@@ -436,6 +436,8 @@ void FlatModel::handleProjectAdded(Project *project)
{
QTC_ASSERT(project, return);
auto oldName = project->displayName();
project->setProperty("_q_oldProjectName", oldName);
connect(project, &Project::anyParsingStarted,
this, [this, project]() {
if (nodeForProject(project))
@@ -443,8 +445,28 @@ void FlatModel::handleProjectAdded(Project *project)
});
connect(project, &Project::anyParsingFinished,
this, [this, project]() {
if (nodeForProject(project))
auto wrapper = nodeForProject(project);
if (wrapper) {
// In case the project was renamed, change the name in expand data as well
// FIXME: Redesign node expansion so that it does not rely on display name of a node
auto oldName = project->property("_q_oldProjectName").toString();
auto currentName = project->displayName();
if (oldName != currentName) {
project->setProperty("_q_oldProjectName", currentName);
auto node = wrapper->m_node;
ExpandData oldData(node->filePath().toString(), oldName);
ExpandData newData(oldData.path, currentName);
auto it = m_toExpand.find(oldData);
if (it != m_toExpand.end()) {
m_toExpand.erase(it);
m_toExpand.insert(newData);
emit requestExpansion(wrapper->index());
} else if (m_toExpand.contains(newData)) {
emit requestExpansion(wrapper->index());
}
}
parsingStateChanged(project);
}
emit ProjectTree::instance()->nodeActionsChanged();
});
addOrRebuildProjectModel(project);