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

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