From 5ad66f6442ae6ea7ac89672139671e590ac6f289 Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 12 Dec 2018 16:10:34 +0100 Subject: [PATCH] ProjectExplorer: Fix initial top level expansion of projects For freshly created projects using the json wizard, this expands the outermost level of that project's entry in the project tree. This intentionally does not trigger when reloading from existing sessions do honor a user's choice after collapsing that item manually. Fixes: QTCREATORBUG-17800 Change-Id: I101efaea84e68a4e769c803918652a1447805b2b Reviewed-by: Christian Kandeler --- src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp | 1 + src/plugins/projectexplorer/project.cpp | 11 +++++++++++ src/plugins/projectexplorer/project.h | 3 +++ src/plugins/projectexplorer/projectmodels.cpp | 4 ++++ 4 files changed, 19 insertions(+) diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp index fb0de4a3293..a3bad8656f0 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp @@ -354,6 +354,7 @@ void JsonWizard::openFiles(const JsonWizard::GeneratorFiles &files) } break; } + result.project()->setNeedsInitialExpansion(true); openedSomething = true; } if (file.attributes() & Core::GeneratedFile::OpenEditorAttribute) { diff --git a/src/plugins/projectexplorer/project.cpp b/src/plugins/projectexplorer/project.cpp index 4bb5ec1b64c..89550892758 100644 --- a/src/plugins/projectexplorer/project.cpp +++ b/src/plugins/projectexplorer/project.cpp @@ -160,6 +160,7 @@ public: Core::Id m_id; bool m_isParsing = false; bool m_hasParsingData = false; + bool m_needsInitialExpansion = false; std::unique_ptr m_document; std::unique_ptr m_rootProjectNode; std::unique_ptr m_containerNode; @@ -306,6 +307,16 @@ void Project::setActiveTarget(Target *target) } } +bool Project::needsInitialExpansion() const +{ + return d->m_needsInitialExpansion; +} + +void Project::setNeedsInitialExpansion(bool needsExpansion) +{ + d->m_needsInitialExpansion = needsExpansion; +} + Target *Project::target(Core::Id id) const { return Utils::findOrDefault(d->m_targets, Utils::equal(&Target::id, id)); diff --git a/src/plugins/projectexplorer/project.h b/src/plugins/projectexplorer/project.h index 3864599982b..6e62aa14b46 100644 --- a/src/plugins/projectexplorer/project.h +++ b/src/plugins/projectexplorer/project.h @@ -189,6 +189,9 @@ public: }, recv, this); } + bool needsInitialExpansion() const; + void setNeedsInitialExpansion(bool needsInitialExpansion); + signals: void displayNameChanged(); void fileListChanged(); diff --git a/src/plugins/projectexplorer/projectmodels.cpp b/src/plugins/projectexplorer/projectmodels.cpp index c009925c97e..ab09068e3b9 100644 --- a/src/plugins/projectexplorer/projectmodels.cpp +++ b/src/plugins/projectexplorer/projectmodels.cpp @@ -239,6 +239,10 @@ void FlatModel::addOrRebuildProjectModel(Project *project) if (m_trimEmptyDirectories) trimEmptyDirectories(container); } + + if (project->needsInitialExpansion()) + m_toExpand.insert(expandDataForNode(container->m_node)); + if (container->childCount() == 0) { auto projectFileNode = std::make_unique(project->projectFilePath(), FileType::Project, false);