forked from qt-creator/qt-creator
JsonWizard: Allow the summary page to change to the file list
Change the JsonWizard interface: * generateFileList now does no longer change the state of the JsonWizard * commitToFileList added which is used to commit the wizard to a final list of files. * Trigger generateFileList when version control is changed in the SummaryPage * Commit to the file list once the SummaryPage is done Change-Id: Ieb7b7abbf428d96596526c01946ecf0852f65744 Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
#include "../session.h"
|
||||
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/iversioncontrol.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
@@ -81,48 +82,58 @@ static IWizardFactory::WizardKind wizardKind(JsonWizard *wiz)
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
JsonSummaryPage::JsonSummaryPage(QWidget *parent) :
|
||||
Internal::ProjectWizardPage(parent)
|
||||
Internal::ProjectWizardPage(parent),
|
||||
m_wizard(0)
|
||||
{
|
||||
connect(this, &Internal::ProjectWizardPage::projectNodeChanged,
|
||||
this, &JsonSummaryPage::projectNodeHasChanged);
|
||||
connect(this, &Internal::ProjectWizardPage::versionControlChanged,
|
||||
this, &JsonSummaryPage::versionControlHasChanged);
|
||||
}
|
||||
|
||||
void JsonSummaryPage::initializePage()
|
||||
{
|
||||
m_wizard = qobject_cast<JsonWizard *>(wizard());
|
||||
|
||||
m_wizard->setProperty("SelectedProject", QVariant());
|
||||
m_wizard->setProperty("SelectedFolderNode", QVariant());
|
||||
m_wizard->setProperty("IsSubproject", QString());
|
||||
m_wizard->setProperty("VersionControl", QString());
|
||||
|
||||
connect(m_wizard, &JsonWizard::filesReady, this, &JsonSummaryPage::triggerCommit);
|
||||
connect(m_wizard, &JsonWizard::filesReady, this, &JsonSummaryPage::addToProject);
|
||||
|
||||
JsonWizard::GeneratorFiles files = m_wizard->fileList();
|
||||
QStringList filePaths = Utils::transform(files, [](const JsonWizard::GeneratorFile &f)
|
||||
{ return f.file.path(); });
|
||||
updateFileList();
|
||||
|
||||
IWizardFactory::WizardKind kind = wizardKind(m_wizard);
|
||||
bool isProject = (kind == IWizardFactory::ProjectWizard);
|
||||
|
||||
setFiles(filePaths);
|
||||
|
||||
QStringList projectFiles;
|
||||
if (isProject) {
|
||||
filePaths.clear();
|
||||
JsonWizard::GeneratorFile f
|
||||
= Utils::findOrDefault(files, [](const JsonWizard::GeneratorFile &f) {
|
||||
= Utils::findOrDefault(m_fileList, [](const JsonWizard::GeneratorFile &f) {
|
||||
return f.file.attributes() & GeneratedFile::OpenProjectAttribute;
|
||||
});
|
||||
filePaths << f.file.path();
|
||||
projectFiles << f.file.path();
|
||||
}
|
||||
|
||||
Node *contextNode = m_wizard->value(QLatin1String(Constants::PREFERRED_PROJECT_NODE))
|
||||
.value<Node *>();
|
||||
initializeProjectTree(contextNode, filePaths, kind,
|
||||
initializeProjectTree(contextNode, projectFiles, kind,
|
||||
isProject ? AddSubProject : AddNewFile);
|
||||
|
||||
initializeVersionControls();
|
||||
}
|
||||
|
||||
bool JsonSummaryPage::validatePage()
|
||||
{
|
||||
m_wizard->commitToFileList(m_fileList);
|
||||
m_fileList.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
void JsonSummaryPage::cleanupPage()
|
||||
{
|
||||
m_wizard->resetFileList();
|
||||
|
||||
disconnect(m_wizard, &JsonWizard::filesReady, this, 0);
|
||||
}
|
||||
|
||||
@@ -142,6 +153,7 @@ void JsonSummaryPage::triggerCommit(const JsonWizard::GeneratorFiles &files)
|
||||
|
||||
void JsonSummaryPage::addToProject(const JsonWizard::GeneratorFiles &files)
|
||||
{
|
||||
QTC_CHECK(m_fileList.isEmpty()); // Happens after this page is done
|
||||
QString generatedProject = generatedProjectFilePath(files);
|
||||
IWizardFactory::WizardKind kind = wizardKind(m_wizard);
|
||||
|
||||
@@ -178,12 +190,31 @@ void JsonSummaryPage::projectNodeHasChanged()
|
||||
updateProjectData(currentNode());
|
||||
}
|
||||
|
||||
void JsonSummaryPage::versionControlHasChanged()
|
||||
{
|
||||
IVersionControl *vc = currentVersionControl();
|
||||
m_wizard->setProperty("VersionControl", vc ? vc->id().toString() : QString());
|
||||
|
||||
updateFileList();
|
||||
}
|
||||
|
||||
void JsonSummaryPage::updateFileList()
|
||||
{
|
||||
m_fileList = m_wizard->generateFileList();
|
||||
QStringList filePaths
|
||||
= Utils::transform(m_fileList, [](const JsonWizard::GeneratorFile &f) { return f.file.path(); });
|
||||
setFiles(filePaths);
|
||||
}
|
||||
|
||||
void JsonSummaryPage::updateProjectData(FolderNode *node)
|
||||
{
|
||||
Project *project = SessionManager::projectForNode(node);
|
||||
|
||||
wizard()->setProperty("SelectedProject", QVariant::fromValue(project));
|
||||
wizard()->setProperty("SelectedFolderNode", QVariant::fromValue(node));
|
||||
m_wizard->setProperty("SelectedProject", QVariant::fromValue(project));
|
||||
m_wizard->setProperty("SelectedFolderNode", QVariant::fromValue(node));
|
||||
m_wizard->setProperty("IsSubproject", node ? QLatin1String("yes") : QString());
|
||||
|
||||
updateFileList();
|
||||
}
|
||||
|
||||
} // namespace ProjectExplorer
|
||||
|
||||
@@ -49,17 +49,21 @@ public:
|
||||
JsonSummaryPage(QWidget *parent = 0);
|
||||
|
||||
void initializePage();
|
||||
bool validatePage();
|
||||
void cleanupPage();
|
||||
|
||||
public slots:
|
||||
void triggerCommit(const JsonWizard::GeneratorFiles &files);
|
||||
void addToProject(const JsonWizard::GeneratorFiles &files);
|
||||
void projectNodeHasChanged();
|
||||
void versionControlHasChanged();
|
||||
|
||||
private:
|
||||
void updateFileList();
|
||||
void updateProjectData(FolderNode *node);
|
||||
|
||||
JsonWizard *m_wizard;
|
||||
JsonWizard::GeneratorFiles m_fileList;
|
||||
};
|
||||
|
||||
} // namespace ProjectExplorer
|
||||
|
||||
@@ -82,23 +82,16 @@ Utils::MacroExpander *JsonWizard::expander()
|
||||
return &m_expander;
|
||||
}
|
||||
|
||||
void JsonWizard::resetFileList()
|
||||
{
|
||||
m_files.clear();
|
||||
}
|
||||
|
||||
JsonWizard::GeneratorFiles JsonWizard::fileList()
|
||||
JsonWizard::GeneratorFiles JsonWizard::generateFileList()
|
||||
{
|
||||
QString errorMessage;
|
||||
GeneratorFiles list;
|
||||
|
||||
QString targetPath = value(QLatin1String("TargetPath")).toString();
|
||||
if (targetPath.isEmpty()) {
|
||||
if (targetPath.isEmpty())
|
||||
errorMessage = tr("Could not determine target path. \"TargetPath\" was not set on any page.");
|
||||
return list;
|
||||
}
|
||||
|
||||
if (m_files.isEmpty()) {
|
||||
if (m_files.isEmpty() && errorMessage.isEmpty()) {
|
||||
emit preGenerateFiles();
|
||||
foreach (JsonWizardGenerator *gen, m_generators) {
|
||||
Core::GeneratedFiles tmp = gen->fileList(&m_expander, value(QStringLiteral("WizardDir")).toString(),
|
||||
@@ -108,10 +101,6 @@ JsonWizard::GeneratorFiles JsonWizard::fileList()
|
||||
list.append(Utils::transform(tmp, [&gen](const Core::GeneratedFile &f)
|
||||
{ return JsonWizard::GeneratorFile(f, gen); }));
|
||||
}
|
||||
|
||||
if (errorMessage.isEmpty())
|
||||
m_files = list;
|
||||
emit postGenerateFiles(m_files);
|
||||
}
|
||||
|
||||
if (!errorMessage.isEmpty()) {
|
||||
@@ -122,7 +111,13 @@ JsonWizard::GeneratorFiles JsonWizard::fileList()
|
||||
return GeneratorFiles();
|
||||
}
|
||||
|
||||
return m_files;
|
||||
return list;
|
||||
}
|
||||
|
||||
void JsonWizard::commitToFileList(const JsonWizard::GeneratorFiles &list)
|
||||
{
|
||||
m_files = list;
|
||||
emit postGenerateFiles(m_files);
|
||||
}
|
||||
|
||||
QVariant JsonWizard::value(const QString &n) const
|
||||
@@ -162,8 +157,11 @@ void JsonWizard::accept()
|
||||
Utils::Wizard::accept();
|
||||
|
||||
QString errorMessage;
|
||||
if (fileList().isEmpty())
|
||||
return;
|
||||
if (m_files.isEmpty()) {
|
||||
commitToFileList(generateFileList()); // The Summary page does this for us, but a wizard
|
||||
// does not need to have one.
|
||||
}
|
||||
QTC_ASSERT(!m_files.isEmpty(), return);
|
||||
|
||||
emit prePromptForOverwrite(m_files);
|
||||
JsonWizardGenerator::OverwriteResult overwrite =
|
||||
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
JsonWizardGenerator *generator;
|
||||
};
|
||||
typedef QList<GeneratorFile> GeneratorFiles;
|
||||
Q_PROPERTY(GeneratorFiles fileList READ fileList)
|
||||
Q_PROPERTY(GeneratorFiles generateFileList READ generateFileList)
|
||||
|
||||
explicit JsonWizard(QWidget *parent = 0);
|
||||
~JsonWizard();
|
||||
@@ -70,8 +70,8 @@ public:
|
||||
|
||||
Utils::MacroExpander *expander();
|
||||
|
||||
void resetFileList();
|
||||
GeneratorFiles fileList();
|
||||
GeneratorFiles generateFileList();
|
||||
void commitToFileList(const GeneratorFiles &list);
|
||||
|
||||
QVariant value(const QString &n) const;
|
||||
void setValue(const QString &key, const QVariant &value);
|
||||
@@ -81,8 +81,8 @@ public:
|
||||
void removeAttributeFromAllFiles(Core::GeneratedFile::Attribute a);
|
||||
|
||||
signals:
|
||||
void preGenerateFiles(); // emitted before files are generated.
|
||||
void postGenerateFiles(const JsonWizard::GeneratorFiles &files); // emitted after files are generated.
|
||||
void preGenerateFiles(); // emitted before files are generated (can happen several times!)
|
||||
void postGenerateFiles(const JsonWizard::GeneratorFiles &files); // emitted after commitToFileList was called.
|
||||
void prePromptForOverwrite(const JsonWizard::GeneratorFiles &files); // emitted before overwriting checks are done.
|
||||
void preFormatFiles(const JsonWizard::GeneratorFiles &files); // emitted before files are formatted.
|
||||
void preWriteFiles(const JsonWizard::GeneratorFiles &files); // emitted before files are written to disk.
|
||||
|
||||
Reference in New Issue
Block a user