Fix clearing the list of wizard factories

Clearing the list of wizard factories did not result in updating the
available JSON wizards. The JSON wizard paths were scanned only once at
startup. Instead partially revert back to before
1cf6b031cf and let the JSON "factory
creator" parse the directories and return a list of wizard factories.

Change-Id: Ifc253479973be801c5323588800bb264610187b6
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Eike Ziller
2023-11-16 14:53:44 +01:00
parent 4362318c14
commit b60fd77fc1
6 changed files with 50 additions and 33 deletions

View File

@@ -186,33 +186,35 @@ QList<IWizardFactory*> IWizardFactory::allWizardFactories()
QHash<Id, IWizardFactory *> sanityCheck; QHash<Id, IWizardFactory *> sanityCheck;
for (const FactoryCreator &fc : std::as_const(s_factoryCreators)) { for (const FactoryCreator &fc : std::as_const(s_factoryCreators)) {
IWizardFactory *newFactory = fc(); for (IWizardFactory *newFactory : fc()) {
// skip factories referencing wizard page generators provided by plugins not loaded if (!newFactory) // should not happen, but maybe something went wrong
if (!newFactory) continue;
continue; IWizardFactory *existingFactory = sanityCheck.value(newFactory->id());
IWizardFactory *existingFactory = sanityCheck.value(newFactory->id());
QTC_ASSERT(existingFactory != newFactory, continue); QTC_ASSERT(existingFactory != newFactory, continue);
if (existingFactory) { if (existingFactory) {
qWarning("%s", qPrintable(Tr::tr("Factory with id=\"%1\" already registered. Deleting.") qWarning("%s",
.arg(existingFactory->id().toString()))); qPrintable(
delete newFactory; Tr::tr("Factory with id=\"%1\" already registered. Deleting.")
continue; .arg(existingFactory->id().toString())));
} delete newFactory;
continue;
QTC_ASSERT(!newFactory->m_action, continue);
newFactory->m_action = new QAction(newFactory->displayName(), newFactory);
ActionManager::registerAction(newFactory->m_action, actionId(newFactory));
connect(newFactory->m_action, &QAction::triggered, newFactory, [newFactory] {
if (!ICore::isNewItemDialogRunning()) {
FilePath path = newFactory->runPath({});
newFactory->runWizard(path, ICore::dialogParent(), Id(), QVariantMap());
} }
});
sanityCheck.insert(newFactory->id(), newFactory); QTC_ASSERT(!newFactory->m_action, continue);
s_allFactories << newFactory; newFactory->m_action = new QAction(newFactory->displayName(), newFactory);
ActionManager::registerAction(newFactory->m_action, actionId(newFactory));
connect(newFactory->m_action, &QAction::triggered, newFactory, [newFactory] {
if (!ICore::isNewItemDialogRunning()) {
FilePath path = newFactory->runPath({});
newFactory->runWizard(path, ICore::dialogParent(), Id(), QVariantMap());
}
});
sanityCheck.insert(newFactory->id(), newFactory);
s_allFactories << newFactory;
}
} }
} }
@@ -322,6 +324,11 @@ void IWizardFactory::registerFactoryCreator(const IWizardFactory::FactoryCreator
s_factoryCreators << creator; s_factoryCreators << creator;
} }
void IWizardFactory::registerFactoryCreator(const std::function<IWizardFactory *()> &creator)
{
s_factoryCreators << [creator] { return QList<IWizardFactory *>({creator()}); };
}
QSet<Id> IWizardFactory::allAvailablePlatforms() QSet<Id> IWizardFactory::allAvailablePlatforms()
{ {
QSet<Id> platforms; QSet<Id> platforms;

View File

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

View File

@@ -100,7 +100,7 @@ bool FormEditorPlugin::initialize([[maybe_unused]] const QStringList &arguments,
wizard->setDescription(Tr::tr("Creates a Qt Designer form along with a matching class (C++ header and source file) " 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.")); "for implementation purposes. You can add the form and class to an existing Qt Widget Project."));
return wizard; return {wizard};
}); });
#endif #endif

View File

@@ -402,8 +402,9 @@ JsonWizardFactory::Page JsonWizardFactory::parsePage(const QVariant &value, QStr
//FIXME: loadDefaultValues() has an almost identical loop. Make the loop return the results instead of //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 //internal processing and create a separate function for it. Then process the results in
//loadDefaultValues() and loadDefaultValues() //loadDefaultValues() and loadDefaultValues()
void JsonWizardFactory::createWizardFactories() QList<Core::IWizardFactory *> JsonWizardFactory::createWizardFactories()
{ {
QList<Core::IWizardFactory *> result;
QString verboseLog; QString verboseLog;
const QString wizardFileName = QLatin1String("wizard.json"); const QString wizardFileName = QLatin1String("wizard.json");
@@ -465,10 +466,16 @@ void JsonWizardFactory::createWizardFactories()
continue; continue;
} }
IWizardFactory::registerFactoryCreator([data, currentFile] { QString errorMessage;
QString errorMessage; JsonWizardFactory *factory = createWizardFactory(data,
return createWizardFactory(data, currentFile.parentDir(), &errorMessage); currentFile.parentDir(),
}); &errorMessage);
if (!factory) {
verboseLog.append(tr("* Failed to create: %1\n").arg(errorMessage));
continue;
}
result << factory;
} }
} }
@@ -476,6 +483,7 @@ void JsonWizardFactory::createWizardFactories()
qWarning("%s", qPrintable(verboseLog)); qWarning("%s", qPrintable(verboseLog));
Core::MessageManager::writeDisrupting(verboseLog); Core::MessageManager::writeDisrupting(verboseLog);
} }
return result;
} }
JsonWizardFactory *JsonWizardFactory::createWizardFactory(const QVariantMap &data, JsonWizardFactory *JsonWizardFactory::createWizardFactory(const QVariantMap &data,

View File

@@ -63,7 +63,7 @@ private:
// 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.
static void createWizardFactories(); static QList<IWizardFactory *> createWizardFactories();
static JsonWizardFactory *createWizardFactory(const QVariantMap &data, static JsonWizardFactory *createWizardFactory(const QVariantMap &data,
const Utils::FilePath &baseDir, const Utils::FilePath &baseDir,
QString *errorMessage); QString *errorMessage);

View File

@@ -2042,7 +2042,8 @@ void ProjectExplorerPluginPrivate::closeAllProjects()
void ProjectExplorerPlugin::extensionsInitialized() void ProjectExplorerPlugin::extensionsInitialized()
{ {
CustomWizard::createWizards(); CustomWizard::createWizards();
JsonWizardFactory::createWizardFactories(); IWizardFactory::registerFactoryCreator(
[] { return JsonWizardFactory::createWizardFactories(); });
// Register factories for all project managers // Register factories for all project managers