forked from qt-creator/qt-creator
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:
@@ -186,33 +186,35 @@ QList<IWizardFactory*> IWizardFactory::allWizardFactories()
|
||||
|
||||
QHash<Id, IWizardFactory *> sanityCheck;
|
||||
for (const FactoryCreator &fc : std::as_const(s_factoryCreators)) {
|
||||
IWizardFactory *newFactory = fc();
|
||||
// skip factories referencing wizard page generators provided by plugins not loaded
|
||||
if (!newFactory)
|
||||
continue;
|
||||
IWizardFactory *existingFactory = sanityCheck.value(newFactory->id());
|
||||
for (IWizardFactory *newFactory : fc()) {
|
||||
if (!newFactory) // should not happen, but maybe something went wrong
|
||||
continue;
|
||||
IWizardFactory *existingFactory = sanityCheck.value(newFactory->id());
|
||||
|
||||
QTC_ASSERT(existingFactory != newFactory, continue);
|
||||
if (existingFactory) {
|
||||
qWarning("%s", qPrintable(Tr::tr("Factory with id=\"%1\" already registered. Deleting.")
|
||||
.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());
|
||||
QTC_ASSERT(existingFactory != newFactory, continue);
|
||||
if (existingFactory) {
|
||||
qWarning("%s",
|
||||
qPrintable(
|
||||
Tr::tr("Factory with id=\"%1\" already registered. Deleting.")
|
||||
.arg(existingFactory->id().toString())));
|
||||
delete newFactory;
|
||||
continue;
|
||||
}
|
||||
});
|
||||
|
||||
sanityCheck.insert(newFactory->id(), newFactory);
|
||||
s_allFactories << newFactory;
|
||||
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);
|
||||
s_allFactories << newFactory;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,6 +324,11 @@ void IWizardFactory::registerFactoryCreator(const IWizardFactory::FactoryCreator
|
||||
s_factoryCreators << creator;
|
||||
}
|
||||
|
||||
void IWizardFactory::registerFactoryCreator(const std::function<IWizardFactory *()> &creator)
|
||||
{
|
||||
s_factoryCreators << [creator] { return QList<IWizardFactory *>({creator()}); };
|
||||
}
|
||||
|
||||
QSet<Id> IWizardFactory::allAvailablePlatforms()
|
||||
{
|
||||
QSet<Id> platforms;
|
||||
|
||||
@@ -77,8 +77,9 @@ public:
|
||||
virtual bool isAvailable(Utils::Id platformId) 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 std::function<IWizardFactory *()> &creator);
|
||||
|
||||
// Utility to find all registered wizards
|
||||
static QList<IWizardFactory*> allWizardFactories();
|
||||
|
||||
@@ -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) "
|
||||
"for implementation purposes. You can add the form and class to an existing Qt Widget Project."));
|
||||
|
||||
return wizard;
|
||||
return {wizard};
|
||||
});
|
||||
#endif
|
||||
|
||||
|
||||
@@ -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
|
||||
//internal processing and create a separate function for it. Then process the results in
|
||||
//loadDefaultValues() and loadDefaultValues()
|
||||
void JsonWizardFactory::createWizardFactories()
|
||||
QList<Core::IWizardFactory *> JsonWizardFactory::createWizardFactories()
|
||||
{
|
||||
QList<Core::IWizardFactory *> result;
|
||||
QString verboseLog;
|
||||
const QString wizardFileName = QLatin1String("wizard.json");
|
||||
|
||||
@@ -465,10 +466,16 @@ void JsonWizardFactory::createWizardFactories()
|
||||
continue;
|
||||
}
|
||||
|
||||
IWizardFactory::registerFactoryCreator([data, currentFile] {
|
||||
QString errorMessage;
|
||||
return createWizardFactory(data, currentFile.parentDir(), &errorMessage);
|
||||
});
|
||||
QString errorMessage;
|
||||
JsonWizardFactory *factory = createWizardFactory(data,
|
||||
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));
|
||||
Core::MessageManager::writeDisrupting(verboseLog);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
JsonWizardFactory *JsonWizardFactory::createWizardFactory(const QVariantMap &data,
|
||||
|
||||
@@ -63,7 +63,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 void createWizardFactories();
|
||||
static QList<IWizardFactory *> createWizardFactories();
|
||||
static JsonWizardFactory *createWizardFactory(const QVariantMap &data,
|
||||
const Utils::FilePath &baseDir,
|
||||
QString *errorMessage);
|
||||
|
||||
@@ -2042,7 +2042,8 @@ void ProjectExplorerPluginPrivate::closeAllProjects()
|
||||
void ProjectExplorerPlugin::extensionsInitialized()
|
||||
{
|
||||
CustomWizard::createWizards();
|
||||
JsonWizardFactory::createWizardFactories();
|
||||
IWizardFactory::registerFactoryCreator(
|
||||
[] { return JsonWizardFactory::createWizardFactories(); });
|
||||
|
||||
// Register factories for all project managers
|
||||
|
||||
|
||||
Reference in New Issue
Block a user