forked from qt-creator/qt-creator
ProjectTree::currentProject: Introduce a fall back to startupProject
If no node is selected, e.g. no document is open, the ProjectTree currently claims that there is no current project. This adds a fallback to startup project in that case. This especially fixes the case where only one project is open and as such it is clear from context which project the user expects to be current. Revert a few places where I implemented this fallback manually. I do not like this. If multiple projects are open, this fallback can be surprising and not what the user wants. Everything works fine in the simple case with one project open but breaks with multiple projects open, this actively hides bugs. Change-Id: I6259834ca2220dd83bdffb16c3a0eac8f98e504b Task-number: QTCREATORBUG-14394 Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
@@ -81,11 +81,11 @@ ProjectTree::ProjectTree(QObject *parent)
|
||||
this, &ProjectTree::focusChanged);
|
||||
|
||||
connect(SessionManager::instance(), &SessionManager::projectAdded,
|
||||
this, &ProjectTree::updateDefaultLocationForNewFiles);
|
||||
this, &ProjectTree::sessionChanged);
|
||||
connect(SessionManager::instance(), &SessionManager::projectRemoved,
|
||||
this, &ProjectTree::updateDefaultLocationForNewFiles);
|
||||
this, &ProjectTree::sessionChanged);
|
||||
connect(SessionManager::instance(), &SessionManager::startupProjectChanged,
|
||||
this, &ProjectTree::updateDefaultLocationForNewFiles);
|
||||
this, &ProjectTree::sessionChanged);
|
||||
}
|
||||
|
||||
void ProjectTree::aboutToShutDown()
|
||||
@@ -193,7 +193,11 @@ void ProjectTree::updateFromDocumentManager(bool invalidCurrentNode)
|
||||
|
||||
void ProjectTree::updateFromNode(Node *node)
|
||||
{
|
||||
Project *project = projectForNode(node);
|
||||
Project *project;
|
||||
if (node)
|
||||
project = projectForNode(node);
|
||||
else
|
||||
project = SessionManager::startupProject();
|
||||
|
||||
update(node, project);
|
||||
foreach (ProjectTreeWidget *widget, m_projectTreeWidgets)
|
||||
@@ -236,12 +240,12 @@ void ProjectTree::update(Node *node, Project *project)
|
||||
|
||||
if (changedProject) {
|
||||
emit currentProjectChanged(m_currentProject);
|
||||
updateDefaultLocationForNewFiles();
|
||||
sessionChanged();
|
||||
updateContext();
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectTree::updateDefaultLocationForNewFiles()
|
||||
void ProjectTree::sessionChanged()
|
||||
{
|
||||
if (m_currentProject)
|
||||
Core::DocumentManager::setDefaultLocationForNewFiles(m_currentProject->projectDirectory().toString());
|
||||
@@ -249,6 +253,7 @@ void ProjectTree::updateDefaultLocationForNewFiles()
|
||||
Core::DocumentManager::setDefaultLocationForNewFiles(SessionManager::startupProject()->projectDirectory().toString());
|
||||
else
|
||||
Core::DocumentManager::setDefaultLocationForNewFiles(QString());
|
||||
updateFromFocus();
|
||||
}
|
||||
|
||||
void ProjectTree::updateContext()
|
||||
|
||||
Reference in New Issue
Block a user