Commit 25f2f8e1 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

IWizardFactory: Create wizards with factoryCreators



Do not use the object pool to hold potential wizards. Register
FactoryCreator functions with IWizardFactory instead and use
those to create the wizards when necessary.

This saves us a couple of cycles during startup since we can now
delay construction of all wizards and it makes us more flexible
wrt. managing the lifecycle of the wizard factories.

Change-Id: I95d6a6dfcdf0fd995e1934a9fefcd96c6a676753
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent b5e3f2e5
...@@ -185,6 +185,8 @@ bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage) ...@@ -185,6 +185,8 @@ bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage)
InfoBar::initializeGloballySuppressed(); InfoBar::initializeGloballySuppressed();
} }
IWizardFactory::initialize();
// Make sure we respect the process's umask when creating new files // Make sure we respect the process's umask when creating new files
SaveFile::initializeUmask(); SaveFile::initializeUmask();
......
...@@ -533,11 +533,6 @@ void ICore::openFiles(const QStringList &arguments, ICore::OpenFilesFlags flags) ...@@ -533,11 +533,6 @@ void ICore::openFiles(const QStringList &arguments, ICore::OpenFilesFlags flags)
m_mainwindow->openFiles(arguments, flags); m_mainwindow->openFiles(arguments, flags);
} }
void ICore::emitNewItemsDialogRequested()
{
emit m_instance->newItemsDialogRequested();
}
void ICore::saveSettings() void ICore::saveSettings()
{ {
emit m_instance->saveSettingsRequested(); emit m_instance->saveSettingsRequested();
......
...@@ -123,15 +123,12 @@ public: ...@@ -123,15 +123,12 @@ public:
}; };
static void openFiles(const QStringList &fileNames, OpenFilesFlags flags = None); static void openFiles(const QStringList &fileNames, OpenFilesFlags flags = None);
static void emitNewItemsDialogRequested();
public slots: public slots:
static void saveSettings(); static void saveSettings();
signals: signals:
void coreAboutToOpen(); void coreAboutToOpen();
void coreOpened(); void coreOpened();
void newItemsDialogRequested();
void newItemDialogRunningChanged(); void newItemDialogRunningChanged();
void saveSettingsRequested(); void saveSettingsRequested();
void optionsDialogRequested(); void optionsDialogRequested();
......
...@@ -147,16 +147,18 @@ ...@@ -147,16 +147,18 @@
using namespace Core; using namespace Core;
namespace { namespace {
static QList<IFeatureProvider *> s_providerList; static QList<IFeatureProvider *> s_providerList;
QList<IWizardFactory *> s_allFactories;
QList<IWizardFactory::FactoryCreator> s_factoryCreators;
bool s_areFactoriesLoaded = false;
} }
/* A utility to find all wizards supporting a view mode and matching a predicate */ /* A utility to find all wizards supporting a view mode and matching a predicate */
template <class Predicate> template <class Predicate>
QList<IWizardFactory*> findWizardFactories(Predicate predicate) QList<IWizardFactory*> findWizardFactories(Predicate predicate)
{ {
// Hack: Trigger delayed creation of wizards
ICore::emitNewItemsDialogRequested();
// Filter all wizards // Filter all wizards
const QList<IWizardFactory*> allFactories = IWizardFactory::allWizardFactories(); const QList<IWizardFactory*> allFactories = IWizardFactory::allWizardFactories();
QList<IWizardFactory*> rc; QList<IWizardFactory*> rc;
...@@ -169,9 +171,33 @@ template <class Predicate> ...@@ -169,9 +171,33 @@ template <class Predicate>
QList<IWizardFactory*> IWizardFactory::allWizardFactories() QList<IWizardFactory*> IWizardFactory::allWizardFactories()
{ {
// Hack: Trigger delayed creation of wizards if (!s_areFactoriesLoaded) {
ICore::emitNewItemsDialogRequested(); QTC_ASSERT(s_allFactories.isEmpty(), return s_allFactories);
return ExtensionSystem::PluginManager::getObjects<IWizardFactory>();
s_areFactoriesLoaded = true;
QHash<Id, IWizardFactory *> sanityCheck;
foreach (const FactoryCreator &fc, s_factoryCreators) {
QList<IWizardFactory *> tmp = fc();
foreach (IWizardFactory *newFactory, tmp) {
QTC_ASSERT(newFactory, continue);
IWizardFactory *existingFactory = sanityCheck.value(newFactory->id());
QTC_ASSERT(existingFactory != newFactory, continue);
if (existingFactory) {
qWarning("%s", qPrintable(tr("Factory with id=\"%1\" already registered. Deleting.")
.arg(existingFactory->id().toString())));
delete newFactory;
continue;
}
sanityCheck.insert(newFactory->id(), newFactory);
s_allFactories << newFactory;
}
}
}
return s_allFactories;
} }
// Utility to find all registered wizards of a certain kind // Utility to find all registered wizards of a certain kind
...@@ -211,6 +237,11 @@ QStringList IWizardFactory::supportedPlatforms() const ...@@ -211,6 +237,11 @@ QStringList IWizardFactory::supportedPlatforms() const
return stringList; return stringList;
} }
void IWizardFactory::registerFactoryCreator(const IWizardFactory::FactoryCreator &creator)
{
s_factoryCreators << creator;
}
QStringList IWizardFactory::allAvailablePlatforms() QStringList IWizardFactory::allAvailablePlatforms()
{ {
QStringList platforms; QStringList platforms;
...@@ -257,3 +288,9 @@ FeatureSet IWizardFactory::pluginFeatures() const ...@@ -257,3 +288,9 @@ FeatureSet IWizardFactory::pluginFeatures() const
} }
return plugins; return plugins;
} }
void IWizardFactory::initialize()
{
connect(ICore::instance(), &ICore::coreAboutToClose,
ICore::instance(), []() { qDeleteAll(s_allFactories); s_allFactories.clear(); });
}
...@@ -38,6 +38,8 @@ ...@@ -38,6 +38,8 @@
#include <QObject> #include <QObject>
#include <QString> #include <QString>
#include <functional>
namespace Core { namespace Core {
namespace Internal { class CorePlugin; } namespace Internal { class CorePlugin; }
...@@ -87,6 +89,9 @@ public: ...@@ -87,6 +89,9 @@ public:
bool isAvailable(const QString &platformName) const; bool isAvailable(const QString &platformName) const;
QStringList supportedPlatforms() const; QStringList supportedPlatforms() const;
typedef std::function<QList<IWizardFactory *>()> FactoryCreator;
static void registerFactoryCreator(const FactoryCreator &creator);
// Utility to find all registered wizards // Utility to find all registered wizards
static QList<IWizardFactory*> allWizardFactories(); static QList<IWizardFactory*> allWizardFactories();
// Utility to find all registered wizards of a certain kind // Utility to find all registered wizards of a certain kind
...@@ -100,6 +105,7 @@ protected: ...@@ -100,6 +105,7 @@ protected:
FeatureSet pluginFeatures() const; FeatureSet pluginFeatures() const;
private: private:
static void initialize();
static void destroyFeatureProvider(); static void destroyFeatureProvider();
IWizardFactory::WizardKind m_kind; IWizardFactory::WizardKind m_kind;
......
...@@ -85,7 +85,21 @@ bool FormEditorPlugin::initialize(const QStringList &arguments, QString *error) ...@@ -85,7 +85,21 @@ bool FormEditorPlugin::initialize(const QStringList &arguments, QString *error)
{ {
Q_UNUSED(arguments) Q_UNUSED(arguments)
initializeTemplates(); #ifdef CPP_ENABLED
IWizardFactory::registerFactoryCreator(
[]() -> QList<IWizardFactory *> {
IWizardFactory *wizard = new FormClassWizard;
wizard->setWizardKind(IWizardFactory::FileWizard);
wizard->setCategory(QLatin1String(Core::Constants::WIZARD_CATEGORY_QT));
wizard->setDisplayCategory(QCoreApplication::translate("Core", Core::Constants::WIZARD_TR_CATEGORY_QT));
wizard->setDisplayName(tr("Qt Designer Form Class"));
wizard->setId("C.FormClass");
wizard->setDescription(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 QList<IWizardFactory *>() << wizard;
});
#endif
ProjectExplorer::JsonWizardFactory::registerPageFactory(new Internal::FormPageFactory); ProjectExplorer::JsonWizardFactory::registerPageFactory(new Internal::FormPageFactory);
addAutoReleasedObject(new FormEditorFactory); addAutoReleasedObject(new FormEditorFactory);
...@@ -130,21 +144,6 @@ void FormEditorPlugin::extensionsInitialized() ...@@ -130,21 +144,6 @@ void FormEditorPlugin::extensionsInitialized()
// //
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
void FormEditorPlugin::initializeTemplates()
{
#ifdef CPP_ENABLED
IWizardFactory *wizard = new FormClassWizard;
wizard->setWizardKind(IWizardFactory::FileWizard);
wizard->setCategory(QLatin1String(Core::Constants::WIZARD_CATEGORY_QT));
wizard->setDisplayCategory(QCoreApplication::translate("Core", Core::Constants::WIZARD_TR_CATEGORY_QT));
wizard->setDisplayName(tr("Qt Designer Form Class"));
wizard->setId("C.FormClass");
wizard->setDescription(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."));
addAutoReleasedObject(wizard);
#endif
}
// Find out current existing editor file // Find out current existing editor file
static QString currentFile() static QString currentFile()
{ {
......
...@@ -70,9 +70,10 @@ bool GenericProjectPlugin::initialize(const QStringList &, QString *errorMessage ...@@ -70,9 +70,10 @@ bool GenericProjectPlugin::initialize(const QStringList &, QString *errorMessage
addAutoReleasedObject(new Manager); addAutoReleasedObject(new Manager);
addAutoReleasedObject(new ProjectFilesFactory); addAutoReleasedObject(new ProjectFilesFactory);
addAutoReleasedObject(new GenericMakeStepFactory); addAutoReleasedObject(new GenericMakeStepFactory);
addAutoReleasedObject(new GenericProjectWizard);
addAutoReleasedObject(new GenericBuildConfigurationFactory); addAutoReleasedObject(new GenericBuildConfigurationFactory);
IWizardFactory::registerFactoryCreator([]() { return QList<IWizardFactory *>() << new GenericProjectWizard; });
ActionContainer *mproject = ActionContainer *mproject =
ActionManager::actionContainer(ProjectExplorer::Constants::M_PROJECTCONTEXT); ActionManager::actionContainer(ProjectExplorer::Constants::M_PROJECTCONTEXT);
......
...@@ -356,9 +356,9 @@ CustomWizard *CustomWizard::createWizard(const CustomProjectWizard::CustomWizard ...@@ -356,9 +356,9 @@ CustomWizard *CustomWizard::createWizard(const CustomProjectWizard::CustomWizard
containing valid configuration files and parse them into wizards. containing valid configuration files and parse them into wizards.
*/ */
QList<CustomWizard*> CustomWizard::createWizards() QList<Core::IWizardFactory *> CustomWizard::createWizards()
{ {
QList<CustomWizard*> rc; QList<Core::IWizardFactory *> rc;
QString errorMessage; QString errorMessage;
QString verboseLog; QString verboseLog;
const QString templateDirName = Core::ICore::resourcePath() + const QString templateDirName = Core::ICore::resourcePath() +
......
...@@ -102,7 +102,7 @@ public: ...@@ -102,7 +102,7 @@ public:
// Create all wizards. As other plugins might register factories for derived // Create all wizards. As other plugins might register factories for derived
// classes, call it in extensionsInitialized(). // classes, call it in extensionsInitialized().
static QList<CustomWizard*> createWizards(); static QList<IWizardFactory *> createWizards();
static void setVerbose(int); static void setVerbose(int);
static int verbose(); static int verbose();
......
...@@ -205,13 +205,13 @@ static JsonWizardFactory::Page parsePage(const QVariant &value, QString *errorMe ...@@ -205,13 +205,13 @@ static JsonWizardFactory::Page parsePage(const QVariant &value, QString *errorMe
return p; return p;
} }
QList<JsonWizardFactory *> JsonWizardFactory::createWizardFactories() QList<Core::IWizardFactory *> JsonWizardFactory::createWizardFactories()
{ {
QString errorMessage; QString errorMessage;
QString verboseLog; QString verboseLog;
const QString wizardFileName = QLatin1String(WIZARD_FILE); const QString wizardFileName = QLatin1String(WIZARD_FILE);
QList <JsonWizardFactory *> result; QList <Core::IWizardFactory *> result;
foreach (const Utils::FileName &path, searchPaths()) { foreach (const Utils::FileName &path, searchPaths()) {
if (path.isEmpty()) if (path.isEmpty())
continue; continue;
......
...@@ -95,7 +95,7 @@ public: ...@@ -95,7 +95,7 @@ public:
private: 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 QList<JsonWizardFactory *> createWizardFactories(); static QList<IWizardFactory *> createWizardFactories();
static JsonWizardFactory *createWizardFactory(const QVariantMap &data, const QDir &baseDir, static JsonWizardFactory *createWizardFactory(const QVariantMap &data, const QDir &baseDir,
QString *errorMessage); QString *errorMessage);
static QList<Utils::FileName> &searchPaths(); static QList<Utils::FileName> &searchPaths();
......
...@@ -284,7 +284,6 @@ public: ...@@ -284,7 +284,6 @@ public:
void slotUpdateRunActions(); void slotUpdateRunActions();
void currentModeChanged(Core::IMode *mode, Core::IMode *oldMode); void currentModeChanged(Core::IMode *mode, Core::IMode *oldMode);
void loadCustomWizards();
void updateWelcomePage(); void updateWelcomePage();
...@@ -490,8 +489,12 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er ...@@ -490,8 +489,12 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
addAutoReleasedObject(new TaskHub); addAutoReleasedObject(new TaskHub);
connect(ICore::instance(), &ICore::newItemsDialogRequested, IWizardFactory::registerFactoryCreator([]() -> QList<IWizardFactory *> {
dd, &ProjectExplorerPluginPrivate::loadCustomWizards); QList<IWizardFactory *> result;
result << CustomWizard::createWizards();
result << JsonWizardFactory::createWizardFactories();
return result;
});
dd->m_welcomePage = new ProjectWelcomePage; dd->m_welcomePage = new ProjectWelcomePage;
connect(dd->m_welcomePage, &ProjectWelcomePage::manageSessions, connect(dd->m_welcomePage, &ProjectWelcomePage::manageSessions,
...@@ -1504,20 +1507,6 @@ void ProjectExplorerPlugin::extensionsInitialized() ...@@ -1504,20 +1507,6 @@ void ProjectExplorerPlugin::extensionsInitialized()
dd->m_kitManager->restoreKits(); dd->m_kitManager->restoreKits();
} }
void ProjectExplorerPluginPrivate::loadCustomWizards()
{
// Add custom wizards, for which other plugins might have registered
// class factories
static bool firstTime = true;
if (firstTime) {
firstTime = false;
foreach (IWizardFactory *cpw, CustomWizard::createWizards())
m_instance->addAutoReleasedObject(cpw);
foreach (IWizardFactory *cpw, JsonWizardFactory::createWizardFactories())
m_instance->addAutoReleasedObject(cpw);
}
}
void ProjectExplorerPluginPrivate::updateRunWithoutDeployMenu() void ProjectExplorerPluginPrivate::updateRunWithoutDeployMenu()
{ {
m_runWithoutDeployAction->setVisible(m_projectExplorerSettings.deployBeforeRun); m_runWithoutDeployAction->setVisible(m_projectExplorerSettings.deployBeforeRun);
......
...@@ -106,11 +106,12 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString ...@@ -106,11 +106,12 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
ProjectExplorer::KitManager::registerKitInformation(new QmakeKitInformation); ProjectExplorer::KitManager::registerKitInformation(new QmakeKitInformation);
addAutoReleasedObject(new SubdirsProjectWizard); IWizardFactory::registerFactoryCreator([]() {
addAutoReleasedObject(new GuiAppWizard); QList<IWizardFactory *> result;
addAutoReleasedObject(new LibraryWizard); result << new SubdirsProjectWizard << new GuiAppWizard << new LibraryWizard
addAutoReleasedObject(new TestWizard); << new TestWizard << new CustomWidgetWizard;
addAutoReleasedObject(new CustomWidgetWizard); return result;
});
addAutoReleasedObject(new CustomWizardMetaFactory<CustomQmakeProjectWizard> addAutoReleasedObject(new CustomWizardMetaFactory<CustomQmakeProjectWizard>
(QLatin1String("qmakeproject"), IWizardFactory::ProjectWizard)); (QLatin1String("qmakeproject"), IWizardFactory::ProjectWizard));
......
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