aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/projectexplorer/jsonwizard/jsonsummarypage.cpp')
-rw-r--r--src/plugins/projectexplorer/jsonwizard/jsonsummarypage.cpp36
1 files changed, 32 insertions, 4 deletions
diff --git a/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.cpp b/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.cpp
index 5f02bc7779..27b4b682ab 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();