diff options
Diffstat (limited to 'src/plugins/projectexplorer/jsonwizard')
-rw-r--r-- | src/plugins/projectexplorer/jsonwizard/jsonsummarypage.cpp | 36 | ||||
-rw-r--r-- | src/plugins/projectexplorer/jsonwizard/jsonsummarypage.h | 2 |
2 files changed, 34 insertions, 4 deletions
diff --git a/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.cpp b/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.cpp index 5f02bc7779d..27b4b682ab5 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.cpp @@ -31,6 +31,8 @@ #include "../projectnodes.h" #include "../session.h" +#include "../projecttree.h" + #include <coreplugin/coreconstants.h> #include <coreplugin/iversioncontrol.h> @@ -125,10 +127,19 @@ void JsonSummaryPage::initializePage() }); } - Node *contextNode = m_wizard->value(QLatin1String(Constants::PREFERRED_PROJECT_NODE)) - .value<Node *>(); - initializeProjectTree(contextNode, files, kind, - isProject ? AddSubProject : AddNewFile); + // 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<Node *>(m_wizard->value(Constants::PREFERRED_PROJECT_NODE).value<void *>())); + const ProjectAction currentAction = isProject ? AddSubProject : AddNewFile; + + 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); + }); + bool hideProjectUi = JsonWizard::boolFromVariant(m_hideProjectUiValue, m_wizard->expander()); setProjectUiVisible(!hideProjectUi); @@ -207,6 +218,23 @@ void JsonSummaryPage::summarySettingsHaveChanged() updateProjectData(currentNode()); } +Node *JsonSummaryPage::findWizardContextNode(Node *contextNode) const +{ + if (contextNode && !ProjectTree::hasNode(contextNode)) { + contextNode = nullptr; + + // Static cast from void * to avoid qobject_cast (which needs a valid object) in value(). + auto project = static_cast<Project *>(m_wizard->value(Constants::PROJECT_POINTER).value<void *>()); + if (SessionManager::projects().contains(project) && project->rootProjectNode()) { + const QString path = m_wizard->value(Constants::PREFERRED_PROJECT_NODE_PATH).toString(); + contextNode = project->rootProjectNode()->findNode([path](const Node *n) { + return path == n->filePath().toString(); + }); + } + } + return contextNode; +} + void JsonSummaryPage::updateFileList() { m_fileList = m_wizard->generateFileList(); diff --git a/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.h b/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.h index 1e0bd1800f1..2fa134a38f7 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.h +++ b/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.h @@ -33,6 +33,7 @@ namespace ProjectExplorer { class FolderNode; +class Node; // Documentation inside. class JsonSummaryPage : public Internal::ProjectWizardPage @@ -52,6 +53,7 @@ public: void summarySettingsHaveChanged(); private: + Node *findWizardContextNode(Node *contextNode) const; void updateFileList(); void updateProjectData(FolderNode *node); |