diff --git a/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.cpp b/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.cpp index 8db6d46cac9..07d71f62a2a 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.cpp @@ -4,12 +4,14 @@ #include "jsonsummarypage.h" #include "jsonwizard.h" +#include "../buildsystem.h" #include "../project.h" #include "../projectexplorerconstants.h" #include "../projectexplorertr.h" #include "../projectnodes.h" #include "../projectmanager.h" #include "../projecttree.h" +#include "../target.h" #include #include @@ -76,6 +78,24 @@ void JsonSummaryPage::setHideProjectUiValue(const QVariant &hideProjectUiValue) m_hideProjectUiValue = hideProjectUiValue; } +static Node *extractPreferredNode(const JsonWizard *wizard) +{ + // Use static cast from void * to avoid qobject_cast (which needs a valid object) in value() + // in the following code: + Node *preferred = nullptr; + QVariant variant = wizard->value(Constants::PREFERRED_PROJECT_NODE); + if (variant.isValid()) { + preferred = static_cast(variant.value()); + } else { + variant = wizard->value(Constants::PREFERRED_PROJECT_NODE_PATH); + if (variant.isValid()) { + const FilePath fp = FilePath::fromVariant(variant); + preferred = ProjectTree::instance()->nodeForFile(fp); + } + } + return preferred; +} + void JsonSummaryPage::initializePage() { m_wizard = qobject_cast(wizard()); @@ -109,18 +129,39 @@ void JsonSummaryPage::initializePage() }); } - // Use static cast from void * to avoid qobject_cast (which needs a valid object) in value() - // in the following code: - auto contextNode = findWizardContextNode(static_cast(m_wizard->value(Constants::PREFERRED_PROJECT_NODE).value())); + Node *preferredNode = extractPreferredNode(m_wizard); + const FilePath preferredNodePath = preferredNode ? preferredNode->filePath() : FilePath{}; + auto contextNode = findWizardContextNode(preferredNode); const ProjectAction currentAction = isProject ? AddSubProject : AddNewFile; + auto updateProjectTree = [this, files, kind, currentAction, preferredNodePath]() { + Node *node = currentNode(); + if (!node) { + if (auto p = ProjectManager::projectWithProjectFilePath(preferredNodePath)) + node = p->rootProjectNode(); + } + initializeProjectTree(findWizardContextNode(node), files, kind, currentAction); + if (m_bsConnection && sender() != ProjectTree::instance()) + disconnect(m_bsConnection); + }; + + if (contextNode) { + if (auto p = contextNode->getProject()) { + if (auto targets = p->targets(); !targets.isEmpty()) { + if (auto bs = targets.first()->buildSystem()) { + if (bs->isParsing()) { + m_bsConnection = connect(bs, &BuildSystem::parsingFinished, + this, updateProjectTree); + } + } + } + } + } initializeProjectTree(contextNode, files, kind, currentAction); // Refresh combobox on project tree changes: connect(ProjectTree::instance(), &ProjectTree::treeChanged, - this, [this, files, kind, currentAction]() { - initializeProjectTree(findWizardContextNode(currentNode()), files, kind, currentAction); - }); + this, updateProjectTree); bool hideProjectUi = JsonWizard::boolFromVariant(m_hideProjectUiValue, m_wizard->expander()); diff --git a/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.h b/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.h index c1b4578799e..c5eec013788 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.h +++ b/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.h @@ -38,6 +38,7 @@ private: JsonWizard *m_wizard; JsonWizard::GeneratorFiles m_fileList; QVariant m_hideProjectUiValue; + QMetaObject::Connection m_bsConnection; }; } // namespace ProjectExplorer diff --git a/src/plugins/qmakeprojectmanager/wizards/subdirsprojectwizard.cpp b/src/plugins/qmakeprojectmanager/wizards/subdirsprojectwizard.cpp index 724ff9329cd..9093b70a864 100644 --- a/src/plugins/qmakeprojectmanager/wizards/subdirsprojectwizard.cpp +++ b/src/plugins/qmakeprojectmanager/wizards/subdirsprojectwizard.cpp @@ -69,7 +69,8 @@ bool SubdirsProjectWizard::postGenerateFiles(const QWizard *w, const Core::Gener const FilePath projectPath = params.projectPath(); const FilePath profileName = Core::BaseFileWizardFactory::buildFileName(projectPath, params.fileName, profileSuffix()); QVariantMap map; - map.insert(QLatin1String(ProjectExplorer::Constants::PREFERRED_PROJECT_NODE), profileName.toVariant()); + map.insert(QLatin1String(ProjectExplorer::Constants::PREFERRED_PROJECT_NODE), QVariant()); + map.insert(QLatin1String(ProjectExplorer::Constants::PREFERRED_PROJECT_NODE_PATH), profileName.toVariant()); map.insert(QLatin1String(ProjectExplorer::Constants::PROJECT_KIT_IDS), Utils::transform(wizard->selectedKits(), &Utils::Id::toString)); IWizardFactory::requestNewItemDialog(Tr::tr("New Subproject", "Title of dialog"),