Commit 9d0c3976 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Wizards: Allow for async wizards



Change-Id: Id150ede2549150be8e720c5a0e31b05309cb3fb9
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent e2dab768
...@@ -180,9 +180,11 @@ void WizardEventLoop::rejected() ...@@ -180,9 +180,11 @@ void WizardEventLoop::rejected()
\sa Core::Internal::WizardEventLoop \sa Core::Internal::WizardEventLoop
*/ */
void BaseFileWizardFactory::runWizardImpl(const QString &path, QWidget *parent, const QString &platform, const QVariantMap &extraValues) Utils::Wizard *BaseFileWizardFactory::runWizardImpl(const QString &path, QWidget *parent,
const QString &platform,
const QVariantMap &extraValues)
{ {
QTC_ASSERT(!path.isEmpty(), return); QTC_ASSERT(!path.isEmpty(), return 0);
QString errorMessage; QString errorMessage;
// Compile extension pages, purge out unused ones // Compile extension pages, purge out unused ones
...@@ -220,7 +222,7 @@ void BaseFileWizardFactory::runWizardImpl(const QString &path, QWidget *parent, ...@@ -220,7 +222,7 @@ void BaseFileWizardFactory::runWizardImpl(const QString &path, QWidget *parent,
requiredFeatures(), requiredFeatures(),
dialogParameterFlags, dialogParameterFlags,
extraValues))); extraValues)));
QTC_ASSERT(!wizard.isNull(), return); QTC_ASSERT(!wizard.isNull(), return 0);
ICore::registerWindow(wizard.data(), Context("Core.NewWizard")); ICore::registerWindow(wizard.data(), Context("Core.NewWizard"));
GeneratedFiles files; GeneratedFiles files;
...@@ -251,14 +253,14 @@ void BaseFileWizardFactory::runWizardImpl(const QString &path, QWidget *parent, ...@@ -251,14 +253,14 @@ void BaseFileWizardFactory::runWizardImpl(const QString &path, QWidget *parent,
break; break;
} }
if (files.empty()) if (files.empty())
return; return 0;
// Compile result list and prompt for overwrite // Compile result list and prompt for overwrite
switch (promptOverwrite(&files, &errorMessage)) { switch (promptOverwrite(&files, &errorMessage)) {
case OverwriteCanceled: case OverwriteCanceled:
return; return 0;
case OverwriteError: case OverwriteError:
QMessageBox::critical(0, tr("Existing files"), errorMessage); QMessageBox::critical(0, tr("Existing files"), errorMessage);
return; return 0;
case OverwriteOk: case OverwriteOk:
break; break;
} }
...@@ -272,7 +274,7 @@ void BaseFileWizardFactory::runWizardImpl(const QString &path, QWidget *parent, ...@@ -272,7 +274,7 @@ void BaseFileWizardFactory::runWizardImpl(const QString &path, QWidget *parent,
// Write // Write
if (!writeFiles(files, &errorMessage)) { if (!writeFiles(files, &errorMessage)) {
QMessageBox::critical(parent, tr("File Generation Failure"), errorMessage); QMessageBox::critical(parent, tr("File Generation Failure"), errorMessage);
return; return 0;
} }
bool removeOpenProjectAttribute = false; bool removeOpenProjectAttribute = false;
...@@ -282,7 +284,7 @@ void BaseFileWizardFactory::runWizardImpl(const QString &path, QWidget *parent, ...@@ -282,7 +284,7 @@ void BaseFileWizardFactory::runWizardImpl(const QString &path, QWidget *parent,
if (!ex->processFiles(files, &remove, &errorMessage)) { if (!ex->processFiles(files, &remove, &errorMessage)) {
if (!errorMessage.isEmpty()) if (!errorMessage.isEmpty())
QMessageBox::critical(parent, tr("File Generation Failure"), errorMessage); QMessageBox::critical(parent, tr("File Generation Failure"), errorMessage);
return; return 0;
} }
removeOpenProjectAttribute |= remove; removeOpenProjectAttribute |= remove;
} }
...@@ -298,6 +300,8 @@ void BaseFileWizardFactory::runWizardImpl(const QString &path, QWidget *parent, ...@@ -298,6 +300,8 @@ void BaseFileWizardFactory::runWizardImpl(const QString &path, QWidget *parent,
if (!postGenerateFiles(wizard.data(), files, &errorMessage)) if (!postGenerateFiles(wizard.data(), files, &errorMessage))
if (!errorMessage.isEmpty()) if (!errorMessage.isEmpty())
QMessageBox::critical(0, tr("File Generation Failure"), errorMessage); QMessageBox::critical(0, tr("File Generation Failure"), errorMessage);
return 0;
} }
/*! /*!
......
...@@ -129,7 +129,8 @@ protected: ...@@ -129,7 +129,8 @@ protected:
private: private:
// IWizard // IWizard
void runWizardImpl(const QString &path, QWidget *parent, const QString &platform, const QVariantMap &extraValues); Utils::Wizard *runWizardImpl(const QString &path, QWidget *parent, const QString &platform,
const QVariantMap &extraValues) override;
}; };
} // namespace Core } // namespace Core
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/wizard.h>
#include <QAction> #include <QAction>
...@@ -243,15 +244,25 @@ QString IWizardFactory::runPath(const QString &defaultPath) ...@@ -243,15 +244,25 @@ QString IWizardFactory::runPath(const QString &defaultPath)
return path; return path;
} }
void IWizardFactory::runWizard(const QString &path, QWidget *parent, const QString &platform, const QVariantMap &variables) Utils::Wizard *IWizardFactory::runWizard(const QString &path, QWidget *parent, const QString &platform, const QVariantMap &variables)
{ {
s_isWizardRunning = true; s_isWizardRunning = true;
ICore::validateNewDialogIsRunning(); ICore::validateNewDialogIsRunning();
runWizardImpl(path, parent, platform, variables); Utils::Wizard *wizard = runWizardImpl(path, parent, platform, variables);
s_isWizardRunning = false; if (wizard) {
ICore::validateNewDialogIsRunning(); connect(wizard, &Utils::Wizard::finished, [wizard]() {
s_isWizardRunning = false;
ICore::validateNewDialogIsRunning();
wizard->deleteLater();
});
Core::ICore::registerWindow(wizard, Core::Context("Core.NewWizard"));
} else {
s_isWizardRunning = false;
ICore::validateNewDialogIsRunning();
}
return wizard;
} }
bool IWizardFactory::isAvailable(const QString &platformName) const bool IWizardFactory::isAvailable(const QString &platformName) const
......
...@@ -42,6 +42,8 @@ ...@@ -42,6 +42,8 @@
QT_FORWARD_DECLARE_CLASS(QAction) QT_FORWARD_DECLARE_CLASS(QAction)
namespace Utils { class Wizard; }
namespace Core { namespace Core {
namespace Internal { class CorePlugin; } namespace Internal { class CorePlugin; }
...@@ -89,8 +91,8 @@ public: ...@@ -89,8 +91,8 @@ public:
QString runPath(const QString &defaultPath); QString runPath(const QString &defaultPath);
// Does bookkeeping and the calls runWizardImpl. Please implement that. // Does bookkeeping and the calls runWizardImpl. Please implement that.
virtual void runWizard(const QString &path, QWidget *parent, const QString &platform, virtual Utils::Wizard *runWizard(const QString &path, QWidget *parent, const QString &platform,
const QVariantMap &variables); const QVariantMap &variables);
virtual bool isAvailable(const QString &platformName) const; virtual bool isAvailable(const QString &platformName) const;
QStringList supportedPlatforms() const; QStringList supportedPlatforms() const;
...@@ -113,8 +115,8 @@ protected: ...@@ -113,8 +115,8 @@ protected:
FeatureSet pluginFeatures() const; FeatureSet pluginFeatures() const;
FeatureSet availableFeatures(const QString &platformName) const; FeatureSet availableFeatures(const QString &platformName) const;
virtual void runWizardImpl(const QString &path, QWidget *parent, const QString &platform, virtual Utils::Wizard *runWizardImpl(const QString &path, QWidget *parent, const QString &platform,
const QVariantMap &variables) = 0; const QVariantMap &variables) = 0;
private: private:
static void initialize(); static void initialize();
......
...@@ -356,52 +356,53 @@ void JsonWizardFactory::registerGeneratorFactory(JsonWizardGeneratorFactory *fac ...@@ -356,52 +356,53 @@ void JsonWizardFactory::registerGeneratorFactory(JsonWizardGeneratorFactory *fac
JsonWizardFactory::~JsonWizardFactory() JsonWizardFactory::~JsonWizardFactory()
{ } { }
void JsonWizardFactory::runWizardImpl(const QString &path, QWidget *parent, const QString &platform, Utils::Wizard *JsonWizardFactory::runWizardImpl(const QString &path, QWidget *parent,
const QVariantMap &variables) const QString &platform,
const QVariantMap &variables)
{ {
JsonWizard wizard(parent); auto wizard = new JsonWizard(parent);
wizard.setWindowIcon(icon()); wizard->setWindowIcon(icon());
wizard.setWindowTitle(displayName()); wizard->setWindowTitle(displayName());
wizard.setValue(QStringLiteral("WizardDir"), m_wizardDir); wizard->setValue(QStringLiteral("WizardDir"), m_wizardDir);
Core::FeatureSet tmp = requiredFeatures(); Core::FeatureSet tmp = requiredFeatures();
tmp.remove(pluginFeatures()); tmp.remove(pluginFeatures());
wizard.setValue(QStringLiteral("RequiredFeatures"), tmp.toStringList()); wizard->setValue(QStringLiteral("RequiredFeatures"), tmp.toStringList());
tmp = m_preferredFeatures; tmp = m_preferredFeatures;
tmp.remove(pluginFeatures()); tmp.remove(pluginFeatures());
wizard.setValue(QStringLiteral("PreferredFeatures"), tmp.toStringList()); wizard->setValue(QStringLiteral("PreferredFeatures"), tmp.toStringList());
wizard.setValue(QStringLiteral("Features"), availableFeatures(platform).toStringList()); wizard->setValue(QStringLiteral("Features"), availableFeatures(platform).toStringList());
wizard.setValue(QStringLiteral("Plugins"), pluginFeatures().toStringList()); wizard->setValue(QStringLiteral("Plugins"), pluginFeatures().toStringList());
// Add data to wizard: // Add data to wizard:
for (auto i = variables.constBegin(); i != variables.constEnd(); ++i) for (auto i = variables.constBegin(); i != variables.constEnd(); ++i)
wizard.setProperty(i.key().toUtf8(), i.value()); wizard->setValue(i.key(), i.value());
wizard.setValue(QStringLiteral("InitialPath"), path); wizard->setValue(QStringLiteral("InitialPath"), path);
wizard.setValue(QStringLiteral("Platform"), platform); wizard->setValue(QStringLiteral("Platform"), platform);
QString kindStr = QLatin1String(Core::Constants::WIZARD_KIND_UNKNOWN); QString kindStr = QLatin1String(Core::Constants::WIZARD_KIND_UNKNOWN);
if (kind() == IWizardFactory::FileWizard) if (kind() == IWizardFactory::FileWizard)
kindStr = QLatin1String(Core::Constants::WIZARD_KIND_FILE); kindStr = QLatin1String(Core::Constants::WIZARD_KIND_FILE);
else if (kind() == IWizardFactory::ProjectWizard) else if (kind() == IWizardFactory::ProjectWizard)
kindStr = QLatin1String(Core::Constants::WIZARD_KIND_PROJECT); kindStr = QLatin1String(Core::Constants::WIZARD_KIND_PROJECT);
wizard.setValue(QStringLiteral("kind"), kindStr); wizard->setValue(QStringLiteral("kind"), kindStr);
wizard.setValue(QStringLiteral("trDescription"), description()); wizard->setValue(QStringLiteral("trDescription"), description());
wizard.setValue(QStringLiteral("trDisplayName"), displayName()); wizard->setValue(QStringLiteral("trDisplayName"), displayName());
wizard.setValue(QStringLiteral("trCategory"), displayCategory()); wizard->setValue(QStringLiteral("trCategory"), displayCategory());
wizard.setValue(QStringLiteral("category"), category()); wizard->setValue(QStringLiteral("category"), category());
wizard.setValue(QStringLiteral("id"), id().toString()); wizard->setValue(QStringLiteral("id"), id().toString());
for (auto i = m_options.constBegin(); i != m_options.constEnd(); ++i) for (auto i = m_options.constBegin(); i != m_options.constEnd(); ++i)
wizard.setValue(i.key(), i.value()); wizard->setValue(i.key(), i.value());
bool havePage = false; bool havePage = false;
foreach (const Page &data, m_pages) { foreach (const Page &data, m_pages) {
QTC_ASSERT(data.isValid(), continue); QTC_ASSERT(data.isValid(), continue);
if (!JsonWizard::boolFromVariant(data.enabled, wizard.expander())) if (!JsonWizard::boolFromVariant(data.enabled, wizard->expander()))
continue; continue;
havePage = true; havePage = true;
...@@ -410,7 +411,7 @@ void JsonWizardFactory::runWizardImpl(const QString &path, QWidget *parent, cons ...@@ -410,7 +411,7 @@ void JsonWizardFactory::runWizardImpl(const QString &path, QWidget *parent, cons
return f->canCreate(data.typeId); return f->canCreate(data.typeId);
}); });
QTC_ASSERT(factory, continue); QTC_ASSERT(factory, continue);
Utils::WizardPage *page = factory->create(&wizard, data.typeId, data.data); Utils::WizardPage *page = factory->create(wizard, data.typeId, data.data);
QTC_ASSERT(page, continue); QTC_ASSERT(page, continue);
page->setTitle(data.title); page->setTitle(data.title);
...@@ -418,11 +419,11 @@ void JsonWizardFactory::runWizardImpl(const QString &path, QWidget *parent, cons ...@@ -418,11 +419,11 @@ void JsonWizardFactory::runWizardImpl(const QString &path, QWidget *parent, cons
page->setProperty(Utils::SHORT_TITLE_PROPERTY, data.shortTitle); page->setProperty(Utils::SHORT_TITLE_PROPERTY, data.shortTitle);
if (data.index >= 0) { if (data.index >= 0) {
wizard.setPage(data.index, page); wizard->setPage(data.index, page);
if (wizard.page(data.index) != page) // Failed to set page! if (wizard->page(data.index) != page) // Failed to set page!
delete page; delete page;
} else { } else {
wizard.addPage(page); wizard->addPage(page);
} }
} }
...@@ -436,15 +437,17 @@ void JsonWizardFactory::runWizardImpl(const QString &path, QWidget *parent, cons ...@@ -436,15 +437,17 @@ void JsonWizardFactory::runWizardImpl(const QString &path, QWidget *parent, cons
JsonWizardGenerator *gen = factory->create(data.typeId, data.data, path, platform, variables); JsonWizardGenerator *gen = factory->create(data.typeId, data.data, path, platform, variables);
QTC_ASSERT(gen, continue); QTC_ASSERT(gen, continue);
wizard.addGenerator(gen); wizard->addGenerator(gen);
} }
if (havePage) { if (!havePage) {
Core::ICore::registerWindow(&wizard, Core::Context("Core.NewJSONWizard")); wizard->accept();
wizard.exec(); wizard->deleteLater();
} else { return 0;
wizard.accept();
} }
wizard->show();
return wizard;
} }
QList<QVariant> JsonWizardFactory::objectOrList(const QVariant &data, QString *errorMessage) QList<QVariant> JsonWizardFactory::objectOrList(const QVariant &data, QString *errorMessage)
......
...@@ -93,8 +93,8 @@ public: ...@@ -93,8 +93,8 @@ public:
bool isAvailable(const QString &platformName) const override; bool isAvailable(const QString &platformName) const override;
private: private:
void runWizardImpl(const QString &path, QWidget *parent, const QString &platform, Utils::Wizard *runWizardImpl(const QString &path, QWidget *parent, const QString &platform,
const QVariantMap &variables); const QVariantMap &variables) override;
// Create all wizards. As other plugins might register factories for derived // Create all wizards. As other plugins might register factories for derived
// classes. Called when the new file dialog is shown for the first time. // classes. Called when the new file dialog is shown for the first time.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment