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;
|
QHash<Id, IWizardFactory *> sanityCheck;
|
||||||
for (const FactoryCreator &fc : qAsConst(s_factoryCreators)) {
|
for (const FactoryCreator &fc : qAsConst(s_factoryCreators)) {
|
||||||
const QList<IWizardFactory *> tmp = fc();
|
IWizardFactory *newFactory = fc();
|
||||||
for (IWizardFactory *newFactory : tmp) {
|
QTC_ASSERT(newFactory, continue);
|
||||||
QTC_ASSERT(newFactory, 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("Factory with id=\"%1\" already registered. Deleting.")
|
qWarning("%s", qPrintable(tr("Factory with id=\"%1\" already registered. Deleting.")
|
||||||
.arg(existingFactory->id().toString())));
|
.arg(existingFactory->id().toString())));
|
||||||
delete newFactory;
|
delete newFactory;
|
||||||
continue;
|
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(!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;
|
virtual bool isAvailable(Utils::Id platformId) const;
|
||||||
QSet<Utils::Id> supportedPlatforms() const;
|
QSet<Utils::Id> supportedPlatforms() const;
|
||||||
|
|
||||||
using FactoryCreator = std::function<QList<IWizardFactory *>()>;
|
using FactoryCreator = std::function<IWizardFactory *()>;
|
||||||
static void registerFactoryCreator(const FactoryCreator &creator);
|
static void registerFactoryCreator(const FactoryCreator &creator);
|
||||||
|
|
||||||
// Utility to find all registered wizards
|
// Utility to find all registered wizards
|
||||||
|
@@ -64,19 +64,18 @@ bool FormEditorPlugin::initialize(const QStringList &arguments, QString *error)
|
|||||||
d = new FormEditorPluginPrivate;
|
d = new FormEditorPluginPrivate;
|
||||||
|
|
||||||
#ifdef CPP_ENABLED
|
#ifdef CPP_ENABLED
|
||||||
IWizardFactory::registerFactoryCreator(
|
IWizardFactory::registerFactoryCreator([]() -> IWizardFactory * {
|
||||||
[]() -> QList<IWizardFactory *> {
|
IWizardFactory *wizard = new FormClassWizard;
|
||||||
IWizardFactory *wizard = new FormClassWizard;
|
wizard->setCategory(Core::Constants::WIZARD_CATEGORY_QT);
|
||||||
wizard->setCategory(Core::Constants::WIZARD_CATEGORY_QT);
|
wizard->setDisplayCategory(QCoreApplication::translate("Core", Core::Constants::WIZARD_TR_CATEGORY_QT));
|
||||||
wizard->setDisplayCategory(QCoreApplication::translate("Core", Core::Constants::WIZARD_TR_CATEGORY_QT));
|
wizard->setDisplayName(Tr::tr("Qt Designer Form Class"));
|
||||||
wizard->setDisplayName(Tr::tr("Qt Designer Form Class"));
|
wizard->setIcon({}, "ui/h");
|
||||||
wizard->setIcon({}, "ui/h");
|
wizard->setId("C.FormClass");
|
||||||
wizard->setId("C.FormClass");
|
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
|
||||||
|
|
||||||
ProjectExplorer::JsonWizardFactory::registerPageFactory(new Internal::FormPageFactory);
|
ProjectExplorer::JsonWizardFactory::registerPageFactory(new Internal::FormPageFactory);
|
||||||
|
@@ -63,7 +63,7 @@ GenericProjectPluginPrivate::GenericProjectPluginPrivate()
|
|||||||
{
|
{
|
||||||
ProjectManager::registerProjectType<GenericProject>(Constants::GENERICMIMETYPE);
|
ProjectManager::registerProjectType<GenericProject>(Constants::GENERICMIMETYPE);
|
||||||
|
|
||||||
IWizardFactory::registerFactoryCreator([] { return QList<IWizardFactory *>{new GenericProjectWizard}; });
|
IWizardFactory::registerFactoryCreator([] { return new GenericProjectWizard; });
|
||||||
|
|
||||||
ActionContainer *mproject = ActionManager::actionContainer(PEC::M_PROJECTCONTEXT);
|
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.
|
containing valid configuration files and parse them into wizards.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QList<IWizardFactory *> CustomWizard::createWizards()
|
void CustomWizard::createWizards()
|
||||||
{
|
{
|
||||||
QString errorMessage;
|
QString errorMessage;
|
||||||
QString verboseLog;
|
QString verboseLog;
|
||||||
@@ -379,7 +379,7 @@ QList<IWizardFactory *> CustomWizard::createWizards()
|
|||||||
if (!templateDir.exists()) {
|
if (!templateDir.exists()) {
|
||||||
if (CustomWizardPrivate::verbose)
|
if (CustomWizardPrivate::verbose)
|
||||||
qWarning("Custom project template path %s does not exist.", qPrintable(templateDir.absolutePath()));
|
qWarning("Custom project template path %s does not exist.", qPrintable(templateDir.absolutePath()));
|
||||||
return {};
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QDir userTemplateDir(userTemplateDirName);
|
const QDir userTemplateDir(userTemplateDirName);
|
||||||
@@ -411,8 +411,9 @@ QList<IWizardFactory *> CustomWizard::createWizards()
|
|||||||
switch (parameters->parse(dir.absoluteFilePath(configFile), &errorMessage)) {
|
switch (parameters->parse(dir.absoluteFilePath(configFile), &errorMessage)) {
|
||||||
case CustomWizardParameters::ParseOk:
|
case CustomWizardParameters::ParseOk:
|
||||||
if (!Utils::contains(toCreate, [parameters](CustomWizardParametersPtr p) { return parameters->id == p->id; })) {
|
if (!Utils::contains(toCreate, [parameters](CustomWizardParametersPtr p) { return parameters->id == p->id; })) {
|
||||||
parameters->directory = dir.absolutePath();
|
|
||||||
toCreate.append(parameters);
|
toCreate.append(parameters);
|
||||||
|
parameters->directory = dir.absolutePath();
|
||||||
|
IWizardFactory::registerFactoryCreator([parameters] { return createWizard(parameters); });
|
||||||
} else {
|
} else {
|
||||||
verboseLog += QString::fromLatin1("Customwizard: Ignoring wizard in %1 due to duplicate Id %2.\n")
|
verboseLog += QString::fromLatin1("Customwizard: Ignoring wizard in %1 due to duplicate Id %2.\n")
|
||||||
.arg(dir.absolutePath()).arg(parameters->id.toString());
|
.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
|
// Create all wizards. As other plugins might register factories for derived
|
||||||
// classes, call it in extensionsInitialized().
|
// classes, call it in extensionsInitialized().
|
||||||
static QList<IWizardFactory *> createWizards();
|
static void createWizards();
|
||||||
|
|
||||||
static void setVerbose(int);
|
static void setVerbose(int);
|
||||||
static int verbose();
|
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
|
//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()
|
||||||
QList<Core::IWizardFactory *> JsonWizardFactory::createWizardFactories()
|
void JsonWizardFactory::createWizardFactories()
|
||||||
{
|
{
|
||||||
QString errorMessage;
|
QString errorMessage;
|
||||||
QString verboseLog;
|
QString verboseLog;
|
||||||
const QString wizardFileName = QLatin1String(WIZARD_FILE);
|
const QString wizardFileName = QLatin1String(WIZARD_FILE);
|
||||||
|
|
||||||
QList <Core::IWizardFactory *> result;
|
|
||||||
const Utils::FilePaths paths = searchPaths();
|
const Utils::FilePaths paths = searchPaths();
|
||||||
for (const Utils::FilePath &path : paths) {
|
for (const Utils::FilePath &path : paths) {
|
||||||
if (path.isEmpty())
|
if (path.isEmpty())
|
||||||
@@ -449,13 +448,10 @@ QList<Core::IWizardFactory *> JsonWizardFactory::createWizardFactories()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonWizardFactory *factory = createWizardFactory(data, currentDir, &errorMessage);
|
IWizardFactory::registerFactoryCreator([data, currentDir] {
|
||||||
if (!factory) {
|
QString errorMessage;
|
||||||
verboseLog.append(tr("* Failed to create: %1\n").arg(errorMessage));
|
return createWizardFactory(data, currentDir, &errorMessage);
|
||||||
continue;
|
});
|
||||||
}
|
|
||||||
|
|
||||||
result << factory;
|
|
||||||
} else {
|
} else {
|
||||||
FilePaths subDirs = currentDir.dirEntries(filter, sortflags);
|
FilePaths subDirs = currentDir.dirEntries(filter, sortflags);
|
||||||
if (!subDirs.isEmpty()) {
|
if (!subDirs.isEmpty()) {
|
||||||
@@ -474,7 +470,6 @@ QList<Core::IWizardFactory *> JsonWizardFactory::createWizardFactories()
|
|||||||
Core::MessageManager::writeDisrupting(verboseLog);
|
Core::MessageManager::writeDisrupting(verboseLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonWizardFactory *JsonWizardFactory::createWizardFactory(const QVariantMap &data,
|
JsonWizardFactory *JsonWizardFactory::createWizardFactory(const QVariantMap &data,
|
||||||
@@ -485,6 +480,7 @@ JsonWizardFactory *JsonWizardFactory::createWizardFactory(const QVariantMap &dat
|
|||||||
if (!factory->initialize(data, baseDir, errorMessage)) {
|
if (!factory->initialize(data, baseDir, errorMessage)) {
|
||||||
delete factory;
|
delete factory;
|
||||||
factory = nullptr;
|
factory = nullptr;
|
||||||
|
Core::MessageManager::writeDisrupting(*errorMessage);
|
||||||
}
|
}
|
||||||
return factory;
|
return factory;
|
||||||
}
|
}
|
||||||
|
@@ -69,7 +69,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 QList<IWizardFactory *> createWizardFactories();
|
static void 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);
|
||||||
|
@@ -833,13 +833,9 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
|||||||
|
|
||||||
IWizardFactory::registerFeatureProvider(new KitFeatureProvider);
|
IWizardFactory::registerFeatureProvider(new KitFeatureProvider);
|
||||||
|
|
||||||
IWizardFactory::registerFactoryCreator([]() -> QList<IWizardFactory *> {
|
IWizardFactory::registerFactoryCreator([] { return new SimpleProjectWizard; });
|
||||||
QList<IWizardFactory *> result;
|
CustomWizard::createWizards();
|
||||||
result << CustomWizard::createWizards();
|
JsonWizardFactory::createWizardFactories();
|
||||||
result << JsonWizardFactory::createWizardFactories();
|
|
||||||
result << new SimpleProjectWizard;
|
|
||||||
return result;
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(&dd->m_welcomePage, &ProjectWelcomePage::manageSessions,
|
connect(&dd->m_welcomePage, &ProjectWelcomePage::manageSessions,
|
||||||
dd, &ProjectExplorerPluginPrivate::showSessionManager);
|
dd, &ProjectExplorerPluginPrivate::showSessionManager);
|
||||||
|
@@ -140,12 +140,8 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
|
|||||||
//create and register objects
|
//create and register objects
|
||||||
ProjectManager::registerProjectType<QmakeProject>(QmakeProjectManager::Constants::PROFILE_MIMETYPE);
|
ProjectManager::registerProjectType<QmakeProject>(QmakeProjectManager::Constants::PROFILE_MIMETYPE);
|
||||||
|
|
||||||
IWizardFactory::registerFactoryCreator([] {
|
IWizardFactory::registerFactoryCreator([] { return new SubdirsProjectWizard; });
|
||||||
return QList<IWizardFactory *> {
|
IWizardFactory::registerFactoryCreator([] { return new CustomWidgetWizard; });
|
||||||
new SubdirsProjectWizard,
|
|
||||||
new CustomWidgetWizard
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
//menus
|
//menus
|
||||||
ActionContainer *mbuild =
|
ActionContainer *mbuild =
|
||||||
|
Reference in New Issue
Block a user