ProjectExplorer: Move code to set up default project structure

Move the code used to set up the default project structure from the
Project into the sessionmanager. Now that the models are no longer
connected to the project this is the safer way as less change to the
projects logic is required.

Change-Id: Ib6b897f990a24d2dcce96a9821f090551fe45f13
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Tobias Hunger
2017-03-16 15:03:45 +01:00
parent fdb40645a4
commit 2ff0d30829
3 changed files with 14 additions and 10 deletions

View File

@@ -417,13 +417,6 @@ void Project::setDocument(Core::IDocument *doc)
QTC_ASSERT(doc, return);
QTC_ASSERT(!d->m_document, return);
d->m_document = doc;
if (!d->m_rootProjectNode) {
auto newRoot = new ProjectNode(projectDirectory());
newRoot->setDisplayName(displayName());
newRoot->addNode(new FileNode(projectFilePath(), FileType::Project, false));
setRootProjectNode(newRoot);
}
}
void Project::setRootProjectNode(ProjectNode *root)

View File

@@ -40,7 +40,7 @@ namespace Utils { class MimeType; }
namespace ProjectExplorer {
class RunConfiguration;
class Project;
class SessionManager;
enum class NodeType : quint16 {
File = 1,
@@ -302,7 +302,7 @@ protected:
// will add the persistent stuff
explicit ProjectNode(const Utils::FileName &projectFilePath);
friend class Project;
friend class SessionManager;
};
// Documentation inside.

View File

@@ -205,7 +205,14 @@ void SessionManager::updateProjectTree(Project *pro)
return; // Project was already de-registered and is shutting down
ProjectNode *const oldNode = currentPair->second;
ProjectNode *const newNode = pro->rootProjectNode();
ProjectNode *newNode = pro->rootProjectNode();
if (!newNode) {
// Set up generic project structure if the project does not provide any!
newNode = new ProjectNode(pro->projectDirectory());
newNode->setDisplayName(pro->displayName());
newNode->addNode(new FileNode(pro->projectFilePath(), FileType::Project, false));
}
d->m_sessionNode.replaceSubtree(oldNode, newNode);
currentPair->second = newNode;
@@ -766,6 +773,10 @@ void SessionManager::removeProjects(QList<Project *> remove)
pro->saveSettings();
pro->setRootProjectNode(nullptr); // Deregister project with sessionnode!
// Remove the project node:
Node *projectNode = nodeForProject(pro);
d->m_sessionNode.removeNode(projectNode);
d->m_projects
= Utils::filtered(d->m_projects, [pro](const QPair<Project *, ProjectNode *> &pair)
{