Commit d9425c5c authored by Daniel Teske's avatar Daniel Teske

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: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 68a00c12
......@@ -31,7 +31,6 @@
#include "currentprojectfilter.h"
#include "projecttree.h"
#include "project.h"
#include "session.h"
#include <utils/algorithm.h>
......@@ -52,8 +51,6 @@ CurrentProjectFilter::CurrentProjectFilter()
connect(ProjectTree::instance(), &ProjectTree::currentProjectChanged,
this, &CurrentProjectFilter::currentProjectChanged);
connect(SessionManager::instance(), &SessionManager::startupProjectChanged,
this, &CurrentProjectFilter::currentProjectChanged);
}
void CurrentProjectFilter::markFilesAsOutOfDate()
......@@ -78,9 +75,6 @@ void CurrentProjectFilter::prepareSearch(const QString &entry)
void CurrentProjectFilter::currentProjectChanged()
{
Project *project = ProjectTree::currentProject();
if (!project)
project = SessionManager::startupProject();
if (project == m_project)
return;
if (m_project)
......
......@@ -44,24 +44,10 @@ using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;
using namespace TextEditor;
static Project *currentProject()
{
Project *p = ProjectTree::currentProject();
if (p)
return p;
return SessionManager::startupProject();
}
CurrentProjectFind::CurrentProjectFind()
{
connect(ProjectTree::instance(), &ProjectTree::currentProjectChanged,
this, &CurrentProjectFind::handleProjectChanged);
connect(SessionManager::instance(), &SessionManager::startupProjectChanged,
this, &CurrentProjectFind::handleProjectChanged);
connect(SessionManager::instance(), SIGNAL(projectRemoved(ProjectExplorer::Project*)),
this, SLOT(handleProjectChanged()));
connect(SessionManager::instance(), SIGNAL(projectAdded(ProjectExplorer::Project*)),
this, SLOT(handleProjectChanged()));
}
QString CurrentProjectFind::id() const
......@@ -76,12 +62,12 @@ QString CurrentProjectFind::displayName() const
bool CurrentProjectFind::isEnabled() const
{
return currentProject() != 0 && BaseFileFind::isEnabled();
return ProjectTree::currentProject() != 0 && BaseFileFind::isEnabled();
}
QVariant CurrentProjectFind::additionalParameters() const
{
Project *project = currentProject();
Project *project = ProjectTree::currentProject();
if (project && project->document())
return qVariantFromValue(project->projectFilePath().toString());
return QVariant();
......@@ -102,7 +88,7 @@ Utils::FileIterator *CurrentProjectFind::files(const QStringList &nameFilters,
QString CurrentProjectFind::label() const
{
Project *p = currentProject();
Project *p = ProjectTree::currentProject();
QTC_ASSERT(p, return QString());
return tr("Project \"%1\":").arg(p->displayName());
}
......
......@@ -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()
......
......@@ -130,7 +130,7 @@ public: // for nodes to emit signals, do not call unless you are a node
void collapseAll();
private:
void updateDefaultLocationForNewFiles();
void sessionChanged();
void focusChanged();
void updateFromProjectTreeWidget(Internal::ProjectTreeWidget *widget);
void documentManagerCurrentFileChanged();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment