Commit a8e89101 authored by Tobias Hunger's avatar Tobias Hunger

IWizard->IWizardFactory

Start at splitting up the wizard functionality a bit. Currently
it is a factory but also contains a lot of logic that is invoked by
the real wizard dialogs.

This change renames/moves a couple of things only.

Change-Id: I1fa114ee3ee262f7c0690841f361bbf09e674725
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
parent ca415576
......@@ -39,7 +39,7 @@ using namespace Android::Internal;
JavaFileWizard::JavaFileWizard()
{
setWizardKind(Core::IWizard::FileWizard);
setWizardKind(Core::IWizardFactory::FileWizard);
setCategory(QLatin1String(Constants::JAVA_WIZARD_CATEGORY));
setDisplayCategory(QCoreApplication::translate("Android", Constants::JAVA_DISPLAY_CATEGORY));
setDescription(tr("Creates a Java file with boilerplate code."));
......
......@@ -34,7 +34,7 @@
#include "generatedfile.h"
#include "featureprovider.h"
#include <coreplugin/dialogs/iwizard.h>
#include <coreplugin/iwizardfactory.h>
#include <extensionsystem/iplugin.h>
......@@ -103,7 +103,7 @@ private:
QVariantMap m_extraValues;
};
class CORE_EXPORT BaseFileWizard : public IWizard
class CORE_EXPORT BaseFileWizard : public IWizardFactory
{
Q_OBJECT
......
......@@ -14,6 +14,7 @@ include(../../shared/scriptwrapper/scriptwrapper.pri)
win32-msvc*:QMAKE_CXXFLAGS += -wd4251 -wd4290 -wd4250
SOURCES += mainwindow.cpp \
editmode.cpp \
iwizardfactory.cpp \
tabpositionindicator.cpp \
fancyactionbar.cpp \
fancytabwidget.cpp \
......@@ -71,7 +72,6 @@ SOURCES += mainwindow.cpp \
infobar.cpp \
editormanager/ieditor.cpp \
dialogs/ioptionspage.cpp \
dialogs/iwizard.cpp \
settingsdatabase.cpp \
imode.cpp \
editormanager/systemeditor.cpp \
......@@ -102,6 +102,7 @@ SOURCES += mainwindow.cpp \
HEADERS += mainwindow.h \
editmode.h \
iwizardfactory.h \
tabpositionindicator.h \
fancyactionbar.h \
fancytabwidget.h \
......@@ -136,7 +137,6 @@ HEADERS += mainwindow.h \
dialogs/readonlyfilesdialog.h \
dialogs/shortcutsettings.h \
dialogs/openwithdialog.h \
dialogs/iwizard.h \
dialogs/ioptionspage.h \
progressmanager/progressmanager_p.h \
progressmanager/progressview.h \
......
......@@ -41,27 +41,27 @@
#include <QPainter>
#include <QDebug>
Q_DECLARE_METATYPE(Core::IWizard*)
Q_DECLARE_METATYPE(Core::IWizardFactory*)
namespace {
const int ICON_SIZE = 22;
class WizardContainer
class WizardFactoryContainer
{
public:
WizardContainer() : wizard(0), wizardOption(0) {}
WizardContainer(Core::IWizard *w, int i): wizard(w), wizardOption(i) {}
Core::IWizard *wizard;
WizardFactoryContainer() : wizard(0), wizardOption(0) {}
WizardFactoryContainer(Core::IWizardFactory *w, int i): wizard(w), wizardOption(i) {}
Core::IWizardFactory *wizard;
int wizardOption;
};
inline Core::IWizard *wizardOfItem(const QStandardItem *item = 0)
inline Core::IWizardFactory *factoryOfItem(const QStandardItem *item = 0)
{
if (!item)
return 0;
return item->data(Qt::UserRole).value<WizardContainer>().wizard;
return item->data(Qt::UserRole).value<WizardFactoryContainer>().wizard;
}
class PlatformFilterProxyModel : public QSortFilterProxyModel
......@@ -82,7 +82,7 @@ public:
return true;
QModelIndex sourceIndex = sourceModel()->index(sourceRow, 0, sourceParent);
Core::IWizard *wizard = wizardOfItem(qobject_cast<QStandardItemModel*>(sourceModel())->itemFromIndex(sourceIndex));
Core::IWizardFactory *wizard = factoryOfItem(qobject_cast<QStandardItemModel*>(sourceModel())->itemFromIndex(sourceIndex));
if (wizard)
return m_platform.isEmpty() || wizard->isAvailable(m_platform);
......@@ -178,7 +178,7 @@ public:
}
Q_DECLARE_METATYPE(WizardContainer)
Q_DECLARE_METATYPE(WizardFactoryContainer)
using namespace Core;
using namespace Core::Internal;
......@@ -229,25 +229,25 @@ NewDialog::NewDialog(QWidget *parent) :
}
// Sort by category. id
bool wizardLessThan(const IWizard *w1, const IWizard *w2)
static bool wizardFactoryLessThan(const IWizardFactory *f1, const IWizardFactory *f2)
{
if (const int cc = w1->category().compare(w2->category()))
if (const int cc = f1->category().compare(f2->category()))
return cc < 0;
return w1->id().compare(w2->id()) < 0;
return f1->id().compare(f2->id()) < 0;
}
void NewDialog::setWizards(QList<IWizard*> wizards)
void NewDialog::setWizardFactories(QList<IWizardFactory*> factories)
{
qStableSort(wizards.begin(), wizards.end(), wizardLessThan);
qStableSort(factories.begin(), factories.end(), wizardFactoryLessThan);
m_model->clear();
QStandardItem *parentItem = m_model->invisibleRootItem();
QStandardItem *projectKindItem = new QStandardItem(tr("Projects"));
projectKindItem->setData(IWizard::ProjectWizard, Qt::UserRole);
projectKindItem->setData(IWizardFactory::ProjectWizard, Qt::UserRole);
projectKindItem->setFlags(0); // disable item to prevent focus
QStandardItem *filesClassesKindItem = new QStandardItem(tr("Files and Classes"));
filesClassesKindItem->setData(IWizard::FileWizard, Qt::UserRole);
filesClassesKindItem->setData(IWizardFactory::FileWizard, Qt::UserRole);
filesClassesKindItem->setFlags(0); // disable item to prevent focus
parentItem->appendRow(projectKindItem);
......@@ -256,11 +256,11 @@ void NewDialog::setWizards(QList<IWizard*> wizards)
if (m_dummyIcon.isNull())
m_dummyIcon = QIcon(QLatin1String(Core::Constants::ICON_NEWFILE));
QStringList availablePlatforms = IWizard::allAvailablePlatforms();
QStringList availablePlatforms = IWizardFactory::allAvailablePlatforms();
m_ui->comboBox->addItem(tr("All Templates"), QString());
foreach (const QString &platform, availablePlatforms) {
const QString displayNameForPlatform = IWizard::displayNameForPlatform(platform);
const QString displayNameForPlatform = IWizardFactory::displayNameForPlatform(platform);
m_ui->comboBox->addItem(tr("%1 Templates").arg(displayNameForPlatform), platform);
}
......@@ -269,25 +269,25 @@ void NewDialog::setWizards(QList<IWizard*> wizards)
else
m_ui->comboBox->setDisabled(true);
foreach (IWizard *wizard, wizards) {
foreach (IWizardFactory *factory, factories) {
QStandardItem *kindItem;
switch (wizard->kind()) {
case IWizard::ProjectWizard:
switch (factory->kind()) {
case IWizardFactory::ProjectWizard:
kindItem = projectKindItem;
break;
case IWizard::ClassWizard:
case IWizard::FileWizard:
case IWizardFactory::ClassWizard:
case IWizardFactory::FileWizard:
default:
kindItem = filesClassesKindItem;
break;
}
addItem(kindItem, wizard);
addItem(kindItem, factory);
}
if (projectKindItem->columnCount() == 0)
parentItem->removeRow(0);
}
Core::IWizard *NewDialog::showDialog()
Core::IWizardFactory *NewDialog::showDialog()
{
static QString lastCategory;
QModelIndex idx;
......@@ -323,7 +323,7 @@ Core::IWizard *NewDialog::showDialog()
if (retVal != Accepted)
return 0;
return currentWizard();
return currentWizardFactory();
}
QString NewDialog::selectedPlatform() const
......@@ -338,15 +338,15 @@ NewDialog::~NewDialog()
delete m_ui;
}
IWizard *NewDialog::currentWizard() const
IWizardFactory *NewDialog::currentWizardFactory() const
{
QModelIndex index = m_filterProxyModel->mapToSource(m_ui->templatesView->currentIndex());
return wizardOfItem(m_model->itemFromIndex(index));
return factoryOfItem(m_model->itemFromIndex(index));
}
void NewDialog::addItem(QStandardItem *topLevelCategoryItem, IWizard *wizard)
void NewDialog::addItem(QStandardItem *topLevelCategoryItem, IWizardFactory *factory)
{
const QString categoryName = wizard->category();
const QString categoryName = factory->category();
QStandardItem *categoryItem = 0;
for (int i = 0; i < topLevelCategoryItem->rowCount(); i++) {
if (topLevelCategoryItem->child(i, 0)->data(Qt::UserRole) == categoryName)
......@@ -357,20 +357,20 @@ void NewDialog::addItem(QStandardItem *topLevelCategoryItem, IWizard *wizard)
topLevelCategoryItem->appendRow(categoryItem);
m_categoryItems.append(categoryItem);
categoryItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
categoryItem->setText(QLatin1String(" ") + wizard->displayCategory());
categoryItem->setData(wizard->category(), Qt::UserRole);
categoryItem->setText(QLatin1String(" ") + factory->displayCategory());
categoryItem->setData(factory->category(), Qt::UserRole);
}
QStandardItem *wizardItem = new QStandardItem(wizard->displayName());
QStandardItem *wizardItem = new QStandardItem(factory->displayName());
QIcon wizardIcon;
// spacing hack. Add proper icons instead
if (wizard->icon().isNull())
if (factory->icon().isNull())
wizardIcon = m_dummyIcon;
else
wizardIcon = wizard->icon();
wizardIcon = factory->icon();
wizardItem->setIcon(wizardIcon);
wizardItem->setData(QVariant::fromValue(WizardContainer(wizard, 0)), Qt::UserRole);
wizardItem->setData(QVariant::fromValue(WizardFactoryContainer(factory, 0)), Qt::UserRole);
wizardItem->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable);
categoryItem->appendRow(wizardItem);
......@@ -391,15 +391,15 @@ void NewDialog::currentItemChanged(const QModelIndex &index)
{
QModelIndex sourceIndex = m_filterProxyModel->mapToSource(index);
QStandardItem* cat = (m_model->itemFromIndex(sourceIndex));
if (const IWizard *wizard = wizardOfItem(cat)) {
if (const IWizardFactory *wizard = factoryOfItem(cat)) {
QString desciption = wizard->description();
QStringList displayNamesForSupportedPlatforms;
foreach (const QString &platform, wizard->supportedPlatforms())
displayNamesForSupportedPlatforms << IWizard::displayNameForPlatform(platform);
displayNamesForSupportedPlatforms << IWizardFactory::displayNameForPlatform(platform);
if (!Qt::mightBeRichText(desciption))
desciption.replace(QLatin1Char('\n'), QLatin1String("<br>"));
desciption += QLatin1String("<br><br><b>");
if (wizard->flags().testFlag(IWizard::PlatformIndependent))
if (wizard->flags().testFlag(IWizardFactory::PlatformIndependent))
desciption += tr("Platform independent") + QLatin1String("</b>");
else
desciption += tr("Supported Platforms")
......@@ -430,7 +430,7 @@ void NewDialog::okButtonClicked()
void NewDialog::updateOkButton()
{
m_okButton->setEnabled(currentWizard() != 0);
m_okButton->setEnabled(currentWizardFactory() != 0);
}
void NewDialog::setSelectedPlatform(const QString & /*platform*/)
......
......@@ -30,7 +30,7 @@
#ifndef NEWDIALOG_H
#define NEWDIALOG_H
#include "iwizard.h"
#include "../iwizardfactory.h"
#include <QDialog>
#include <QIcon>
......@@ -60,9 +60,9 @@ public:
explicit NewDialog(QWidget *parent);
virtual ~NewDialog();
void setWizards(QList<IWizard*> wizards);
void setWizardFactories(QList<IWizardFactory*> factories);
Core::IWizard *showDialog();
Core::IWizardFactory *showDialog();
QString selectedPlatform() const;
private slots:
......@@ -73,8 +73,8 @@ private slots:
void setSelectedPlatform(const QString &platform);
private:
Core::IWizard *currentWizard() const;
void addItem(QStandardItem *topLevelCategoryItem, IWizard *wizard);
Core::IWizardFactory *currentWizardFactory() const;
void addItem(QStandardItem *topLevelCategoryItem, IWizardFactory *factory);
Ui::NewDialog *m_ui;
QStandardItemModel *m_model;
......
......@@ -327,11 +327,11 @@ ICore::~ICore()
}
void ICore::showNewItemDialog(const QString &title,
const QList<IWizard *> &wizards,
const QList<IWizardFactory *> &factories,
const QString &defaultLocation,
const QVariantMap &extraVariables)
{
m_mainwindow->showNewItemDialog(title, wizards, defaultLocation, extraVariables);
m_mainwindow->showNewItemDialog(title, factories, defaultLocation, extraVariables);
}
bool ICore::showOptionsDialog(const Id group, const Id page, QWidget *parent)
......
......@@ -44,7 +44,7 @@ template <class T> class QList;
QT_END_NAMESPACE
namespace Core {
class IWizard;
class IWizardFactory;
class Context;
class IContext;
class ProgressManager;
......@@ -68,7 +68,7 @@ public:
static ICore *instance();
static void showNewItemDialog(const QString &title,
const QList<IWizard *> &wizards,
const QList<IWizardFactory *> &factories,
const QString &defaultLocation = QString(),
const QVariantMap &extraVariables = QVariantMap());
......
......@@ -42,7 +42,7 @@ QT_END_NAMESPACE
namespace Core {
class IWizard;
class IWizardFactory;
class GeneratedFile;
/*!
......@@ -55,7 +55,7 @@ class CORE_EXPORT IFileWizardExtension : public QObject
public:
/* Return a list of pages to be added to the Wizard (empty list if not
* applicable). */
virtual QList<QWizardPage *> extensionPages(const IWizard *wizard) = 0;
virtual QList<QWizardPage *> extensionPages(const IWizardFactory *wizard) = 0;
/* Process the files using the extension parameters */
virtual bool processFiles(const QList<GeneratedFile> &files,
......
......@@ -27,7 +27,7 @@
**
****************************************************************************/
#include "iwizard.h"
#include "iwizardfactory.h"
#include <coreplugin/icore.h>
#include <coreplugin/featureprovider.h>
......@@ -36,10 +36,10 @@
#include <QStringList>
/*!
\class Core::IWizard
\class Core::IWizardFactory
\mainclass
\brief The class IWizard is the base class for all wizards
\brief The class IWizardFactory is the base class for all wizard factories
(for example shown in \gui {File | New}).
The wizard interface is a very thin abstraction for the \gui{New...} wizards.
......@@ -50,13 +50,13 @@
creating files. Often it is not necessary to create your own wizard from scratch,
instead use one of the predefined wizards and adapt it to your needs.
To make your wizard known to the system, add your IWizard instance to the
To make your wizard known to the system, add your IWizardFactory instance to the
plugin manager's object pool in your plugin's initialize function:
\code
bool MyPlugin::initialize(const QStringList &arguments, QString *errorString)
{
// ... do setup
addAutoReleasedObject(new MyWizard);
addAutoReleasedObject(new MyWizardFactory);
// ... do more setup
}
\endcode
......@@ -65,7 +65,7 @@
*/
/*!
\enum Core::IWizard::WizardKind
\enum Core::IWizardFactory::WizardKind
Used to specify what kind of objects the wizard creates. This information is used
to show e.g. only wizards that create projects when selecting a \gui{New Project}
menu item.
......@@ -78,57 +78,57 @@
*/
/*!
\fn IWizard::IWizard(QObject *parent)
\fn IWizardFactory::IWizardFactory(QObject *parent)
\internal
*/
/*!
\fn IWizard::~IWizard()
\fn IWizardFactory::~IWizardFactory()
\internal
*/
/*!
\fn Kind IWizard::kind() const
\fn Kind IWizardFactory::kind() const
Returns what kind of objects are created by the wizard.
\sa Kind
*/
/*!
\fn QIcon IWizard::icon() const
\fn QIcon IWizardFactory::icon() const
Returns an icon to show in the wizard selection dialog.
*/
/*!
\fn QString IWizard::description() const
\fn QString IWizardFactory::description() const
Returns a translated description to show when this wizard is selected
in the dialog.
*/
/*!
\fn QString IWizard::displayName() const
\fn QString IWizardFactory::displayName() const
Returns the translated name of the wizard, how it should appear in the
dialog.
*/
/*!
\fn QString IWizard::id() const
\fn QString IWizardFactory::id() const
Returns an arbitrary id that is used for sorting within the category.
*/
/*!
\fn QString IWizard::category() const
\fn QString IWizardFactory::category() const
Returns a category ID to add the wizard to.
*/
/*!
\fn QString IWizard::displayCategory() const
\fn QString IWizardFactory::displayCategory() const
Returns the translated string of the category, how it should appear
in the dialog.
*/
/*!
\fn void IWizard::runWizard(const QString &path,
\fn void IWizardFactory::runWizard(const QString &path,
QWidget *parent,
const QString &platform,
const QVariantMap &variables)
......@@ -144,43 +144,43 @@ using namespace Core;
/* A utility to find all wizards supporting a view mode and matching a predicate */
template <class Predicate>
QList<IWizard*> findWizards(Predicate predicate)
QList<IWizardFactory*> findWizardFactories(Predicate predicate)
{
// Hack: Trigger delayed creation of wizards
ICore::emitNewItemsDialogRequested();
// Filter all wizards
const QList<IWizard*> allWizards = IWizard::allWizards();
QList<IWizard*> rc;
const QList<IWizard*>::const_iterator cend = allWizards.constEnd();
for (QList<IWizard*>::const_iterator it = allWizards.constBegin(); it != cend; ++it)
const QList<IWizardFactory*> allFactories = IWizardFactory::allWizardFactories();
QList<IWizardFactory*> rc;
const QList<IWizardFactory*>::const_iterator cend = allFactories.constEnd();
for (QList<IWizardFactory*>::const_iterator it = allFactories.constBegin(); it != cend; ++it)
if (predicate(*(*it)))
rc.push_back(*it);
return rc;
}
QList<IWizard*> IWizard::allWizards()
QList<IWizardFactory*> IWizardFactory::allWizardFactories()
{
// Hack: Trigger delayed creation of wizards
ICore::emitNewItemsDialogRequested();
return ExtensionSystem::PluginManager::getObjects<IWizard>();
return ExtensionSystem::PluginManager::getObjects<IWizardFactory>();
}
// Utility to find all registered wizards of a certain kind
class WizardKindPredicate {
public:
WizardKindPredicate(IWizard::WizardKind kind) : m_kind(kind) {}
bool operator()(const IWizard &w) const { return w.kind() == m_kind; }
WizardKindPredicate(IWizardFactory::WizardKind kind) : m_kind(kind) {}
bool operator()(const IWizardFactory &w) const { return w.kind() == m_kind; }
private:
const IWizard::WizardKind m_kind;
const IWizardFactory::WizardKind m_kind;
};
QList<IWizard*> IWizard::wizardsOfKind(WizardKind kind)
QList<IWizardFactory*> IWizardFactory::wizardFactoriesOfKind(WizardKind kind)
{
return findWizards(WizardKindPredicate(kind));
return findWizardFactories(WizardKindPredicate(kind));
}
bool IWizard::isAvailable(const QString &platformName) const
bool IWizardFactory::isAvailable(const QString &platformName) const
{
FeatureSet availableFeatures;
......@@ -192,7 +192,7 @@ bool IWizard::isAvailable(const QString &platformName) const
return availableFeatures.contains(requiredFeatures());
}
QStringList IWizard::supportedPlatforms() const
QStringList IWizardFactory::supportedPlatforms() const
{
QStringList stringList;
......@@ -204,7 +204,7 @@ QStringList IWizard::supportedPlatforms() const
return stringList;
}
QStringList IWizard::allAvailablePlatforms()
QStringList IWizardFactory::allAvailablePlatforms()
{
QStringList platforms;
......@@ -217,7 +217,7 @@ QStringList IWizard::allAvailablePlatforms()
return platforms;
}
QString IWizard::displayNameForPlatform(const QString &string)
QString IWizardFactory::displayNameForPlatform(const QString &string)
{
const QList<Core::IFeatureProvider*> featureManagers =
ExtensionSystem::PluginManager::getObjects<Core::IFeatureProvider>();
......
......@@ -27,8 +27,8 @@
**
****************************************************************************/
#ifndef IWIZARD_H
#define IWIZARD_H
#ifndef IWIZARDFACTORY_H
#define IWIZARDFACTORY_H
#include <coreplugin/core_global.h>
#include <coreplugin/id.h>
......@@ -40,7 +40,7 @@
namespace Core {
class CORE_EXPORT IWizard
class CORE_EXPORT IWizardFactory
: public QObject
{
Q_OBJECT
......@@ -60,9 +60,9 @@ public:
class CORE_EXPORT Data
{
public:
Data() : kind(IWizard::FileWizard) {}
Data() : kind(IWizardFactory::FileWizard) {}
IWizard::WizardKind kind;
IWizardFactory::WizardKind kind;
QIcon icon;
QString description;
QString displayName;
......@@ -70,11 +70,11 @@ public:
QString category;
QString displayCategory;
FeatureSet requiredFeatures;
IWizard::WizardFlags flags;
IWizardFactory::WizardFlags flags;
QString descriptionImage;
};
IWizard() { }
IWizardFactory() { }
QString id() const { return m_data.id; }
WizardKind kind() const { return m_data.kind; }
......@@ -106,9 +106,9 @@ public:
QStringList supportedPlatforms() const;
// Utility to find all registered wizards
static QList<IWizard*> allWizards();
static QList<IWizardFactory*> allWizardFactories();
// Utility to find all registered wizards of a certain kind
static QList<IWizard*> wizardsOfKind(WizardKind kind);
static QList<IWizardFactory*> wizardFactoriesOfKind(WizardKind kind);
static QStringList allAvailablePlatforms();
static QString displayNameForPlatform(const QString &string);
......@@ -118,7 +118,7 @@ private:
} // namespace Core
Q_DECLARE_OPERATORS_FOR_FLAGS(Core::IWizard::WizardKinds)
Q_DECLARE_OPERATORS_FOR_FLAGS(Core::IWizard::WizardFlags)
Q_DECLARE_OPERATORS_FOR_FLAGS(Core::IWizardFactory::WizardKinds)
Q_DECLARE_OPERATORS_FOR_FLAGS(Core::IWizardFactory::WizardFlags)
#endif // IWIZARD_H
#endif // IWIZARDFACTORY_H
......@@ -785,7 +785,7 @@ void MainWindow::registerDefaultActions()
void MainWindow::newFile()
{
showNewItemDialog(tr("New", "Title of dialog"), IWizard::allWizards(), QString());
showNewItemDialog(tr("New", "Title of dialog"), IWizardFactory::allWizardFactories(), QString());
}
void MainWindow::openFile()
......@@ -865,23 +865,23 @@ void MainWindow::setFocusToEditor()
}
void MainWindow::showNewItemDialog(const QString &title,
const QList<IWizard *> &wizards,
const QList<IWizardFactory *> &factories,
const QString &defaultLocation,
const QVariantMap &extraVariables)
{
// Scan for wizards matching the filter and pick one. Don't show
// dialog if there is only one.
IWizard *wizard = 0;
IWizardFactory *wizard = 0;
QString selectedPlatform;
switch (wizards.size()) {
switch (factories.size()) {
case 0:
break;
case 1:
wizard = wizards.front();
wizard = factories.front();
break;
default: {
NewDialog dlg(this);
dlg.setWizards(wizards);
dlg.setWizardFactories(factories);
dlg.setWindowTitle(title);
wizard = dlg.showDialog();
selectedPlatform = dlg.selectedPlatform();
......@@ -895,7 +895,7 @@ void MainWindow::showNewItemDialog(const QString &title,
QString path = defaultLocation;
if (path.isEmpty()) {
switch (wizard->kind()) {
case IWizard::ProjectWizard: