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,15 +186,16 @@ 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",
|
||||||
|
qPrintable(
|
||||||
|
Tr::tr("Factory with id=\"%1\" already registered. Deleting.")
|
||||||
.arg(existingFactory->id().toString())));
|
.arg(existingFactory->id().toString())));
|
||||||
delete newFactory;
|
delete newFactory;
|
||||||
continue;
|
continue;
|
||||||
@@ -215,6 +216,7 @@ QList<IWizardFactory*> IWizardFactory::allWizardFactories()
|
|||||||
s_allFactories << newFactory;
|
s_allFactories << newFactory;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return s_allFactories;
|
return s_allFactories;
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
return createWizardFactory(data, currentFile.parentDir(), &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));
|
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,
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user