forked from qt-creator/qt-creator
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:
@@ -174,33 +174,31 @@ QList<IWizardFactory*> IWizardFactory::allWizardFactories()
|
||||
|
||||
QHash<Id, IWizardFactory *> sanityCheck;
|
||||
for (const FactoryCreator &fc : qAsConst(s_factoryCreators)) {
|
||||
const QList<IWizardFactory *> tmp = fc();
|
||||
for (IWizardFactory *newFactory : tmp) {
|
||||
QTC_ASSERT(newFactory, continue);
|
||||
IWizardFactory *existingFactory = sanityCheck.value(newFactory->id());
|
||||
IWizardFactory *newFactory = fc();
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -64,19 +64,18 @@ bool FormEditorPlugin::initialize(const QStringList &arguments, QString *error)
|
||||
d = new FormEditorPluginPrivate;
|
||||
|
||||
#ifdef CPP_ENABLED
|
||||
IWizardFactory::registerFactoryCreator(
|
||||
[]() -> QList<IWizardFactory *> {
|
||||
IWizardFactory *wizard = new FormClassWizard;
|
||||
wizard->setCategory(Core::Constants::WIZARD_CATEGORY_QT);
|
||||
wizard->setDisplayCategory(QCoreApplication::translate("Core", Core::Constants::WIZARD_TR_CATEGORY_QT));
|
||||
wizard->setDisplayName(Tr::tr("Qt Designer Form Class"));
|
||||
wizard->setIcon({}, "ui/h");
|
||||
wizard->setId("C.FormClass");
|
||||
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."));
|
||||
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));
|
||||
wizard->setDisplayName(Tr::tr("Qt Designer Form Class"));
|
||||
wizard->setIcon({}, "ui/h");
|
||||
wizard->setId("C.FormClass");
|
||||
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
|
||||
|
||||
ProjectExplorer::JsonWizardFactory::registerPageFactory(new Internal::FormPageFactory);
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@@ -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();
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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 =
|
||||
|
Reference in New Issue
Block a user