forked from qt-creator/qt-creator
PE: Fix adding first project for subdirs project
Change-Id: Iab2d463d7b138e9a6d4c9bf10e94556ea9a10d77 Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -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 <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/iversioncontrol.h>
|
||||
@@ -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<Node *>(variant.value<void *>());
|
||||
} 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<JsonWizard *>(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<Node *>(m_wizard->value(Constants::PREFERRED_PROJECT_NODE).value<void *>()));
|
||||
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());
|
||||
|
@@ -38,6 +38,7 @@ private:
|
||||
JsonWizard *m_wizard;
|
||||
JsonWizard::GeneratorFiles m_fileList;
|
||||
QVariant m_hideProjectUiValue;
|
||||
QMetaObject::Connection m_bsConnection;
|
||||
};
|
||||
|
||||
} // namespace ProjectExplorer
|
||||
|
@@ -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<QStringList>(wizard->selectedKits(), &Utils::Id::toString));
|
||||
IWizardFactory::requestNewItemDialog(Tr::tr("New Subproject", "Title of dialog"),
|
||||
|
Reference in New Issue
Block a user