From 4e1ff9ed8f2751a63ee7f4d677be6a0abe9d3071 Mon Sep 17 00:00:00 2001 From: Joni Poikelin Date: Wed, 24 May 2023 14:05:13 +0300 Subject: [PATCH] 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 --- src/plugins/projectexplorer/projectmodels.cpp | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/plugins/projectexplorer/projectmodels.cpp b/src/plugins/projectexplorer/projectmodels.cpp index 9805e654b74..64fabcb30ab 100644 --- a/src/plugins/projectexplorer/projectmodels.cpp +++ b/src/plugins/projectexplorer/projectmodels.cpp @@ -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);