Wizards: Better selection of project wizards to show

E.g. only show wizards that can create qmake projects when
contining after a SUBDIR-project wizard.

Change-Id: Ib189b1efa479f5b986fdec8658715245e2f2db40
Reviewed-by: Niels Weber <niels.weber@theqtcompany.com>
Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
This commit is contained in:
Tobias Hunger
2015-12-11 14:43:46 +01:00
parent 9e16554e25
commit d5e7262e68
5 changed files with 23 additions and 29 deletions

View File

@@ -203,19 +203,6 @@ private:
NewItemDialogData s_reopenData; NewItemDialogData s_reopenData;
} }
/* A utility to find all wizards supporting a view mode and matching a predicate */
QList<IWizardFactory*> findWizardFactories(const std::function<bool(IWizardFactory*)> &predicate)
{
const QList<IWizardFactory *> allFactories = IWizardFactory::allWizardFactories();
QList<IWizardFactory *> rc;
auto cend = allFactories.constEnd();
for (auto it = allFactories.constBegin(); it != cend; ++it) {
if (predicate(*it))
rc.push_back(*it);
}
return rc;
}
static Id actionId(const IWizardFactory *factory) static Id actionId(const IWizardFactory *factory)
{ {
return factory->id().withPrefix("Wizard.Impl."); return factory->id().withPrefix("Wizard.Impl.");
@@ -263,12 +250,6 @@ QList<IWizardFactory*> IWizardFactory::allWizardFactories()
return s_allFactories; return s_allFactories;
} }
// Utility to find all registered wizards of a certain kind
QList<IWizardFactory*> IWizardFactory::wizardFactoriesOfKind(WizardKind kind)
{
return findWizardFactories([kind](IWizardFactory *f) { return f->kind() == kind; });
}
QString IWizardFactory::runPath(const QString &defaultPath) QString IWizardFactory::runPath(const QString &defaultPath)
{ {
QString path = defaultPath; QString path = defaultPath;

View File

@@ -100,8 +100,6 @@ public:
// 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
static QList<IWizardFactory*> wizardFactoriesOfKind(WizardKind kind);
static QSet<Id> allAvailablePlatforms(); static QSet<Id> allAvailablePlatforms();
static QString displayNameForPlatform(Id i); static QString displayNameForPlatform(Id i);

View File

@@ -1559,7 +1559,8 @@ void ProjectExplorerPluginPrivate::newProject()
qDebug() << "ProjectExplorerPlugin::newProject"; qDebug() << "ProjectExplorerPlugin::newProject";
ICore::showNewItemDialog(tr("New Project", "Title of dialog"), ICore::showNewItemDialog(tr("New Project", "Title of dialog"),
IWizardFactory::wizardFactoriesOfKind(IWizardFactory::ProjectWizard)); Utils::filtered(IWizardFactory::allWizardFactories(),
[](IWizardFactory *f) { return !f->supportedProjectTypes().isEmpty(); }));
updateActions(); updateActions();
} }
@@ -3098,8 +3099,9 @@ void ProjectExplorerPluginPrivate::addNewFile()
map.insert(QLatin1String(Constants::PROJECT_KIT_IDS), QVariant::fromValue(profileIds)); map.insert(QLatin1String(Constants::PROJECT_KIT_IDS), QVariant::fromValue(profileIds));
} }
ICore::showNewItemDialog(tr("New File", "Title of dialog"), ICore::showNewItemDialog(tr("New File", "Title of dialog"),
IWizardFactory::wizardFactoriesOfKind(IWizardFactory::FileWizard), Utils::filtered(IWizardFactory::allWizardFactories(),
location, map); [](IWizardFactory *f) { return f->supportedPlatforms().isEmpty(); }),
location, map);
} }
void ProjectExplorerPluginPrivate::addNewSubproject() void ProjectExplorerPluginPrivate::addNewSubproject()
@@ -3113,14 +3115,20 @@ void ProjectExplorerPluginPrivate::addNewSubproject()
currentNode).contains(AddSubProject)) { currentNode).contains(AddSubProject)) {
QVariantMap map; QVariantMap map;
map.insert(QLatin1String(Constants::PREFERRED_PROJECT_NODE), QVariant::fromValue(currentNode)); map.insert(QLatin1String(Constants::PREFERRED_PROJECT_NODE), QVariant::fromValue(currentNode));
if (ProjectTree::currentProject()) { Project *project = ProjectTree::currentProject();
Core::Id projectType;
if (project) {
QList<Id> profileIds = Utils::transform(ProjectTree::currentProject()->targets(), &Target::id); QList<Id> profileIds = Utils::transform(ProjectTree::currentProject()->targets(), &Target::id);
map.insert(QLatin1String(Constants::PROJECT_KIT_IDS), QVariant::fromValue(profileIds)); map.insert(QLatin1String(Constants::PROJECT_KIT_IDS), QVariant::fromValue(profileIds));
projectType = project->id();
} }
ICore::showNewItemDialog(tr("New Subproject", "Title of dialog"), ICore::showNewItemDialog(tr("New Subproject", "Title of dialog"),
IWizardFactory::wizardFactoriesOfKind(IWizardFactory::ProjectWizard), Utils::filtered(IWizardFactory::allWizardFactories(),
location, map); [projectType](IWizardFactory *f) {
return projectType.isValid() ? f->supportedPlatforms().contains(projectType)
: !f->supportedPlatforms().isEmpty(); }),
location, map);
} }
} }

View File

@@ -252,7 +252,8 @@ void ProjectWelcomePage::reloadWelcomeScreenData()
void ProjectWelcomePage::newProject() void ProjectWelcomePage::newProject()
{ {
Core::ICore::showNewItemDialog(tr("New Project"), Core::ICore::showNewItemDialog(tr("New Project"),
Core::IWizardFactory::wizardFactoriesOfKind(Core::IWizardFactory::ProjectWizard)); Utils::filtered(Core::IWizardFactory::allWizardFactories(),
[](Core::IWizardFactory *f) { return !f->supportedProjectTypes().isEmpty(); }));
} }
void ProjectWelcomePage::openProject() void ProjectWelcomePage::openProject()

View File

@@ -31,11 +31,14 @@
#include "subdirsprojectwizard.h" #include "subdirsprojectwizard.h"
#include "subdirsprojectwizarddialog.h" #include "subdirsprojectwizarddialog.h"
#include "../qmakeprojectmanagerconstants.h"
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <qtsupport/qtsupportconstants.h> #include <qtsupport/qtsupportconstants.h>
#include <utils/algorithm.h>
#include <QCoreApplication> #include <QCoreApplication>
namespace QmakeProjectManager { namespace QmakeProjectManager {
@@ -93,7 +96,10 @@ bool SubdirsProjectWizard::postGenerateFiles(const QWizard *w, const Core::Gener
map.insert(QLatin1String(ProjectExplorer::Constants::PREFERRED_PROJECT_NODE), profileName); map.insert(QLatin1String(ProjectExplorer::Constants::PREFERRED_PROJECT_NODE), profileName);
map.insert(QLatin1String(ProjectExplorer::Constants::PROJECT_KIT_IDS), QVariant::fromValue(wizard->selectedKits())); map.insert(QLatin1String(ProjectExplorer::Constants::PROJECT_KIT_IDS), QVariant::fromValue(wizard->selectedKits()));
IWizardFactory::requestNewItemDialog(tr("New Subproject", "Title of dialog"), IWizardFactory::requestNewItemDialog(tr("New Subproject", "Title of dialog"),
Core::IWizardFactory::wizardFactoriesOfKind(Core::IWizardFactory::ProjectWizard), Utils::filtered(Core::IWizardFactory::allWizardFactories(),
[](Core::IWizardFactory *f) {
return f->supportedPlatforms().contains(Constants::QMAKEPROJECT_ID);
}),
wizard->parameters().projectPath(), map); wizard->parameters().projectPath(), map);
} else { } else {
return false; return false;