ProjectExplorer: Create wizards one by one

Makes it easier to shuffle them around.

Change-Id: Id80064a05ff6d2b76ec9033b4e0065f0bd0d81ae
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
hjk
2022-09-27 16:54:47 +02:00
parent 55ed34ced8
commit 1cf6b031cf
10 changed files with 53 additions and 84 deletions

View File

@@ -174,8 +174,7 @@ QList<IWizardFactory*> IWizardFactory::allWizardFactories()
QHash<Id, IWizardFactory *> sanityCheck;
for (const FactoryCreator &fc : qAsConst(s_factoryCreators)) {
const QList<IWizardFactory *> tmp = fc();
for (IWizardFactory *newFactory : tmp) {
IWizardFactory *newFactory = fc();
QTC_ASSERT(newFactory, continue);
IWizardFactory *existingFactory = sanityCheck.value(newFactory->id());
@@ -202,7 +201,6 @@ QList<IWizardFactory*> IWizardFactory::allWizardFactories()
s_allFactories << newFactory;
}
}
}
return s_allFactories;
}

View File

@@ -77,7 +77,7 @@ public:
virtual bool isAvailable(Utils::Id platformId) const;
QSet<Utils::Id> supportedPlatforms() const;
using FactoryCreator = std::function<QList<IWizardFactory *>()>;
using FactoryCreator = std::function<IWizardFactory *()>;
static void registerFactoryCreator(const FactoryCreator &creator);
// Utility to find all registered wizards

View File

@@ -64,8 +64,7 @@ bool FormEditorPlugin::initialize(const QStringList &arguments, QString *error)
d = new FormEditorPluginPrivate;
#ifdef CPP_ENABLED
IWizardFactory::registerFactoryCreator(
[]() -> QList<IWizardFactory *> {
IWizardFactory::registerFactoryCreator([]() -> IWizardFactory * {
IWizardFactory *wizard = new FormClassWizard;
wizard->setCategory(Core::Constants::WIZARD_CATEGORY_QT);
wizard->setDisplayCategory(QCoreApplication::translate("Core", Core::Constants::WIZARD_TR_CATEGORY_QT));
@@ -75,7 +74,7 @@ bool FormEditorPlugin::initialize(const QStringList &arguments, QString *error)
wizard->setDescription(Tr::tr("Creates a Qt Designer form along with a matching class (C++ header and source file) "
"for implementation purposes. You can add the form and class to an existing Qt Widget Project."));
return {wizard};
return wizard;
});
#endif

View File

@@ -63,7 +63,7 @@ GenericProjectPluginPrivate::GenericProjectPluginPrivate()
{
ProjectManager::registerProjectType<GenericProject>(Constants::GENERICMIMETYPE);
IWizardFactory::registerFactoryCreator([] { return QList<IWizardFactory *>{new GenericProjectWizard}; });
IWizardFactory::registerFactoryCreator([] { return new GenericProjectWizard; });
ActionContainer *mproject = ActionManager::actionContainer(PEC::M_PROJECTCONTEXT);

View File

@@ -365,7 +365,7 @@ CustomWizard *CustomWizard::createWizard(const CustomProjectWizard::CustomWizard
containing valid configuration files and parse them into wizards.
*/
QList<IWizardFactory *> CustomWizard::createWizards()
void CustomWizard::createWizards()
{
QString errorMessage;
QString verboseLog;
@@ -379,7 +379,7 @@ QList<IWizardFactory *> CustomWizard::createWizards()
if (!templateDir.exists()) {
if (CustomWizardPrivate::verbose)
qWarning("Custom project template path %s does not exist.", qPrintable(templateDir.absolutePath()));
return {};
return;
}
const QDir userTemplateDir(userTemplateDirName);
@@ -411,8 +411,9 @@ QList<IWizardFactory *> CustomWizard::createWizards()
switch (parameters->parse(dir.absoluteFilePath(configFile), &errorMessage)) {
case CustomWizardParameters::ParseOk:
if (!Utils::contains(toCreate, [parameters](CustomWizardParametersPtr p) { return parameters->id == p->id; })) {
parameters->directory = dir.absolutePath();
toCreate.append(parameters);
parameters->directory = dir.absolutePath();
IWizardFactory::registerFactoryCreator([parameters] { return createWizard(parameters); });
} else {
verboseLog += QString::fromLatin1("Customwizard: Ignoring wizard in %1 due to duplicate Id %2.\n")
.arg(dir.absolutePath()).arg(parameters->id.toString());
@@ -438,23 +439,6 @@ QList<IWizardFactory *> CustomWizard::createWizards()
}
}
}
QList<IWizardFactory *> rc;
for (CustomWizardParametersPtr p : qAsConst(toCreate)) {
if (CustomWizard *w = createWizard(p)) {
rc.push_back(w);
} else {
qWarning("Custom wizard factory function failed for %s from %s.",
qPrintable(p->id.toString()), qPrintable(p->directory));
}
}
if (CustomWizardPrivate::verbose) { // Print to output pane for Windows.
qWarning("%s", qPrintable(verboseLog));
MessageManager::writeDisrupting(verboseLog);
}
return rc;
}
/*!

View File

@@ -73,7 +73,7 @@ public:
// Create all wizards. As other plugins might register factories for derived
// classes, call it in extensionsInitialized().
static QList<IWizardFactory *> createWizards();
static void createWizards();
static void setVerbose(int);
static int verbose();

View File

@@ -377,13 +377,12 @@ JsonWizardFactory::Page JsonWizardFactory::parsePage(const QVariant &value, QStr
//FIXME: loadDefaultValues() has an almost identical loop. Make the loop return the results instead of
//internal processing and create a separate function for it. Then process the results in
//loadDefaultValues() and loadDefaultValues()
QList<Core::IWizardFactory *> JsonWizardFactory::createWizardFactories()
void JsonWizardFactory::createWizardFactories()
{
QString errorMessage;
QString verboseLog;
const QString wizardFileName = QLatin1String(WIZARD_FILE);
QList <Core::IWizardFactory *> result;
const Utils::FilePaths paths = searchPaths();
for (const Utils::FilePath &path : paths) {
if (path.isEmpty())
@@ -449,13 +448,10 @@ QList<Core::IWizardFactory *> JsonWizardFactory::createWizardFactories()
continue;
}
JsonWizardFactory *factory = createWizardFactory(data, currentDir, &errorMessage);
if (!factory) {
verboseLog.append(tr("* Failed to create: %1\n").arg(errorMessage));
continue;
}
result << factory;
IWizardFactory::registerFactoryCreator([data, currentDir] {
QString errorMessage;
return createWizardFactory(data, currentDir, &errorMessage);
});
} else {
FilePaths subDirs = currentDir.dirEntries(filter, sortflags);
if (!subDirs.isEmpty()) {
@@ -474,7 +470,6 @@ QList<Core::IWizardFactory *> JsonWizardFactory::createWizardFactories()
Core::MessageManager::writeDisrupting(verboseLog);
}
return result;
}
JsonWizardFactory *JsonWizardFactory::createWizardFactory(const QVariantMap &data,
@@ -485,6 +480,7 @@ JsonWizardFactory *JsonWizardFactory::createWizardFactory(const QVariantMap &dat
if (!factory->initialize(data, baseDir, errorMessage)) {
delete factory;
factory = nullptr;
Core::MessageManager::writeDisrupting(*errorMessage);
}
return factory;
}

View File

@@ -69,7 +69,7 @@ private:
// Create all wizards. As other plugins might register factories for derived
// classes. Called when the new file dialog is shown for the first time.
static QList<IWizardFactory *> createWizardFactories();
static void createWizardFactories();
static JsonWizardFactory *createWizardFactory(const QVariantMap &data,
const Utils::FilePath &baseDir,
QString *errorMessage);

View File

@@ -833,13 +833,9 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
IWizardFactory::registerFeatureProvider(new KitFeatureProvider);
IWizardFactory::registerFactoryCreator([]() -> QList<IWizardFactory *> {
QList<IWizardFactory *> result;
result << CustomWizard::createWizards();
result << JsonWizardFactory::createWizardFactories();
result << new SimpleProjectWizard;
return result;
});
IWizardFactory::registerFactoryCreator([] { return new SimpleProjectWizard; });
CustomWizard::createWizards();
JsonWizardFactory::createWizardFactories();
connect(&dd->m_welcomePage, &ProjectWelcomePage::manageSessions,
dd, &ProjectExplorerPluginPrivate::showSessionManager);

View File

@@ -140,12 +140,8 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
//create and register objects
ProjectManager::registerProjectType<QmakeProject>(QmakeProjectManager::Constants::PROFILE_MIMETYPE);
IWizardFactory::registerFactoryCreator([] {
return QList<IWizardFactory *> {
new SubdirsProjectWizard,
new CustomWidgetWizard
};
});
IWizardFactory::registerFactoryCreator([] { return new SubdirsProjectWizard; });
IWizardFactory::registerFactoryCreator([] { return new CustomWidgetWizard; });
//menus
ActionContainer *mbuild =