From a94fcbd1e745687efc19f59c85b0ddba0b90577d Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Thu, 12 Jul 2018 12:12:57 +0200 Subject: [PATCH] ProjectTree: Fall back to startupProject as current more often Fall back to SessionManager::startupProject more often. Creator used to have ProjectTree::currentProject return a nullptr e.g. right after the first project is loaded via the menu (and before the Project tree widget is 'touched'). It also returned nullptr when closing a project via the menu (again till user interaction with the Project tree widget). I think this is wrong, especially in the light of %{CurrentProject:Foo} macro expansion. Change-Id: I1c980382548792181584ec3dfc0d919e939111d8 Reviewed-by: Ulf Hermann --- src/plugins/projectexplorer/projecttree.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/plugins/projectexplorer/projecttree.cpp b/src/plugins/projectexplorer/projecttree.cpp index cf08af7ca25..df02418238c 100644 --- a/src/plugins/projectexplorer/projecttree.cpp +++ b/src/plugins/projectexplorer/projecttree.cpp @@ -158,7 +158,10 @@ void ProjectTree::updateFromProjectTreeWidget(ProjectTreeWidget *widget) Node *currentNode = widget->currentNode(); Project *project = projectForNode(currentNode); - setCurrent(currentNode, project); + if (!project) + updateFromNode(nullptr); // Project was removed! + else + setCurrent(currentNode, project); } void ProjectTree::updateFromDocumentManager() @@ -227,12 +230,14 @@ void ProjectTree::setCurrent(Node *node, Project *project) void ProjectTree::sessionChanged() { - if (m_currentProject) + if (m_currentProject) { Core::DocumentManager::setDefaultLocationForNewFiles(m_currentProject->projectDirectory().toString()); - else if (SessionManager::startupProject()) - Core::DocumentManager::setDefaultLocationForNewFiles(SessionManager::startupProject()->projectDirectory().toString()); - else + } else if (Project *project = SessionManager::startupProject()) { + Core::DocumentManager::setDefaultLocationForNewFiles(project->projectDirectory().toString()); + updateFromNode(nullptr); // Make startup project current if there is no other current + } else { Core::DocumentManager::setDefaultLocationForNewFiles(QString()); + } update(); }