Commit 0e554fac authored by Friedemann Kleint's avatar Friedemann Kleint

Wizards: Sort

Introduce new QString id() const-API and sort wizards by
[untranslated] category and id. Introduce respective constants.
Rubber-stamped-by: default avatarcon <qtc-committer@nokia.com>
parent 4827ba9d
......@@ -39,10 +39,6 @@
#include <QtCore/QStringList>
#include <QtGui/QAction>
namespace Core {
class IWizard;
}
namespace BINEditor {
class BinEditor;
namespace Internal {
......@@ -85,8 +81,6 @@ private:
friend class BinEditorFactory;
Core::IEditor *createEditor(QWidget *parent);
typedef QList<Core::IWizard *> WizardList;
WizardList m_wizards;
BinEditorFactory *m_factory;
QPointer<BinEditor> m_currentEditor;
};
......
......@@ -190,8 +190,9 @@ public:
QIcon icon;
QString description;
QString name;
QString id;
QString category;
QString trCategory;
QString trCategory;
};
BaseFileWizardParameterData::BaseFileWizardParameterData(IWizard::Kind k) :
......@@ -250,7 +251,6 @@ void BaseFileWizardParameters::setDescription(const QString &v)
m_d->description = v;
}
QString BaseFileWizardParameters::name() const
{
return m_d->name;
......@@ -261,6 +261,15 @@ void BaseFileWizardParameters::setName(const QString &v)
m_d->name = v;
}
QString BaseFileWizardParameters::id() const
{
return m_d->id;
}
void BaseFileWizardParameters::setId(const QString &v)
{
m_d->id = v;
}
QString BaseFileWizardParameters::category() const
{
......@@ -412,6 +421,11 @@ QString BaseFileWizard::name() const
return m_d->m_parameters.name();
}
QString BaseFileWizard::id() const
{
return m_d->m_parameters.id();
}
QString BaseFileWizard::category() const
{
return m_d->m_parameters.category();
......
......@@ -117,6 +117,9 @@ public:
QString name() const;
void setName(const QString &name);
QString id() const;
void setId(const QString &id);
QString category() const;
void setCategory(const QString &category);
......@@ -152,6 +155,7 @@ public:
virtual QIcon icon() const;
virtual QString description() const;
virtual QString name() const;
virtual QString id() const;
virtual QString category() const;
virtual QString trCategory() const;
......
......@@ -30,6 +30,8 @@
#ifndef CORECONSTANTS_H
#define CORECONSTANTS_H
#include <QtCore/QtGlobal>
namespace Core {
namespace Constants {
......@@ -218,9 +220,8 @@ const char * const ICON_RESET = ":/core/images/reset.png";
const char * const ICON_MAGNIFIER = ":/core/images/magnifier.png";
const char * const ICON_TOGGLE_SIDEBAR = ":/core/images/sidebaricon.png";
// wizard kind
const char * const WIZARD_TYPE_FILE = "QtCreator::WizardType::File";
const char * const WIZARD_TYPE_CLASS = "QtCreator::WizardType::Class";
const char * const WIZARD_CATEGORY_QT = "M.Qt";
const char * const WIZARD_TR_CATEGORY_QT = QT_TRANSLATE_NOOP("Core", "Qt");
} // namespace Constants
} // namespace Core
......
......@@ -106,6 +106,12 @@
dialog.
*/
/*!
\fn QString IWizard::id() const
Returns an arbitrary id that is used for sorting within the category.
*/
/*!
\fn QString IWizard::category() const
Returns a category ID to add the wizard to.
......
......@@ -57,6 +57,7 @@ public:
virtual QIcon icon() const = 0;
virtual QString description() const = 0;
virtual QString name() const = 0;
virtual QString id() const = 0;
virtual QString category() const = 0;
virtual QString trCategory() const = 0;
......
......@@ -36,6 +36,7 @@
#include <QtGui/QHeaderView>
#include <QtGui/QPushButton>
#include <QtCore/QDebug>
Q_DECLARE_METATYPE(Core::IWizard*)
......@@ -70,10 +71,20 @@ NewDialog::NewDialog(QWidget *parent) :
connect(m_ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
}
void NewDialog::setWizards(const QList<IWizard*> wizards)
// Sort by category. id
bool wizardLessThan(const IWizard *w1, const IWizard *w2)
{
if (const int cc = w1->category().compare(w2->category()))
return cc < 0;
return w1->id().compare(w2->id()) < 0;
}
void NewDialog::setWizards(QList<IWizard*> wizards)
{
typedef QMap<QString, QTreeWidgetItem *> CategoryItemMap;
qStableSort(wizards.begin(), wizards.end(), wizardLessThan);
CategoryItemMap categories;
QVariant wizardPtr;
......
......@@ -57,7 +57,7 @@ public:
explicit NewDialog(QWidget *parent);
virtual ~NewDialog();
void setWizards(const QList<IWizard*> wizards);
void setWizards(QList<IWizard*> wizards);
Core::IWizard *showDialog();
......
......@@ -203,20 +203,24 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess
CppFileWizard::BaseFileWizardParameters wizardParameters(Core::IWizard::FileWizard);
wizardParameters.setCategory(QLatin1String("C++"));
wizardParameters.setCategory(QLatin1String("C.C++"));
wizardParameters.setTrCategory(tr("C++"));
wizardParameters.setDescription(tr("Creates a C++ header file."));
wizardParameters.setName(tr("C++ Header File"));
addAutoReleasedObject(new CppFileWizard(wizardParameters, Header, core));
wizardParameters.setName(tr("C++ Class"));
wizardParameters.setId(QLatin1String("A.Class"));
wizardParameters.setKind(Core::IWizard::ClassWizard);
wizardParameters.setDescription(tr("Creates a header and a source file for a new class."));
addAutoReleasedObject(new CppClassWizard(wizardParameters, core));
wizardParameters.setKind(Core::IWizard::FileWizard);
wizardParameters.setDescription(tr("Creates a C++ source file."));
wizardParameters.setName(tr("C++ Source File"));
wizardParameters.setId(QLatin1String("B.Source"));
addAutoReleasedObject(new CppFileWizard(wizardParameters, Source, core));
wizardParameters.setKind(Core::IWizard::ClassWizard);
wizardParameters.setName(tr("C++ Class"));
wizardParameters.setDescription(tr("Creates a header and a source file for a new class."));
addAutoReleasedObject(new CppClassWizard(wizardParameters, core));
wizardParameters.setDescription(tr("Creates a C++ header file."));
wizardParameters.setName(tr("C++ Header File"));
wizardParameters.setId(QLatin1String("C.Header"));
addAutoReleasedObject(new CppFileWizard(wizardParameters, Header, core));
QList<int> context;
context << core->uniqueIDManager()->uniqueIdentifier(CppEditor::Constants::C_CPPEDITOR);
......
......@@ -32,6 +32,7 @@
#include "cvsplugin.h"
#include <vcsbase/checkoutjobs.h>
#include <vcsbase/vcsbaseconstants.h>
#include <utils/qtcassert.h>
#include <QtGui/QIcon>
......@@ -42,6 +43,7 @@ namespace Internal {
CheckoutWizard::CheckoutWizard(QObject *parent) :
VCSBase::BaseCheckoutWizard(parent)
{
setId(QLatin1String(VCSBase::Constants::VCS_ID_CVS));
}
QIcon CheckoutWizard::icon() const
......
......@@ -133,16 +133,18 @@ void FormEditorPlugin::extensionsInitialized()
void FormEditorPlugin::initializeTemplates()
{
FormWizard::BaseFileWizardParameters wizardParameters(Core::IWizard::FileWizard);
wizardParameters.setCategory(QLatin1String("Qt"));
wizardParameters.setTrCategory(tr("Qt"));
wizardParameters.setCategory(QLatin1String(Core::Constants::WIZARD_CATEGORY_QT));
wizardParameters.setTrCategory(QCoreApplication::translate("Core", Core::Constants::WIZARD_TR_CATEGORY_QT));
const QString formFileType = QLatin1String(Constants::FORM_FILE_TYPE);
wizardParameters.setName(tr("Qt Designer Form"));
wizardParameters.setId(QLatin1String("D.Form"));
wizardParameters.setDescription(tr("Creates a Qt Designer form file (.ui)."));
addAutoReleasedObject(new FormWizard(wizardParameters, this));
#ifdef CPP_ENABLED
wizardParameters.setKind(Core::IWizard::ClassWizard);
wizardParameters.setName(tr("Qt Designer Form Class"));
wizardParameters.setId(QLatin1String("C.FormClass"));
wizardParameters.setDescription(tr("Creates a Qt Designer form file (.ui) with a matching class."));
addAutoReleasedObject(new FormClassWizard(wizardParameters, this));
addAutoReleasedObject(new CppSettingsPage);
......
......@@ -32,92 +32,22 @@
#include <coreplugin/icore.h>
#include <coreplugin/mimedatabase.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <utils/filenamevalidatinglineedit.h>
#include <utils/filewizardpage.h>
#include <utils/pathchooser.h>
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
#include <QtCore/QtDebug>
#include <QtGui/QDirModel>
#include <QtGui/QFormLayout>
#include <QtGui/QListView>
#include <QtGui/QTreeView>
#include <QtCore/QCoreApplication>
using namespace GenericProjectManager::Internal;
using namespace Utils;
namespace {
class DirModel : public QDirModel
{
public:
DirModel(QObject *parent)
: QDirModel(parent)
{ setFilter(QDir::Dirs | QDir::NoDotAndDotDot); }
virtual ~DirModel()
{ }
public:
virtual int columnCount(const QModelIndex &) const
{ return 1; }
virtual Qt::ItemFlags flags(const QModelIndex &index) const
{ return QDirModel::flags(index) | Qt::ItemIsUserCheckable; }
virtual QVariant data(const QModelIndex &index, int role) const
{
if (index.column() == 0 && role == Qt::CheckStateRole) {
if (m_selectedPaths.contains(index))
return Qt::Checked;
return Qt::Unchecked;
}
return QDirModel::data(index, role);
}
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
{
if (index.column() == 0 && role == Qt::CheckStateRole) {
if (value.toBool())
m_selectedPaths.insert(index);
else
m_selectedPaths.remove(index);
return true;
}
return QDirModel::setData(index, value, role);
}
void clearSelectedPaths()
{ m_selectedPaths.clear(); }
QSet<QString> selectedPaths() const
{
QSet<QString> paths;
foreach (const QModelIndex &index, m_selectedPaths)
paths.insert(filePath(index));
return paths;
}
private:
QSet<QModelIndex> m_selectedPaths;
};
} // end of anonymous namespace
//////////////////////////////////////////////////////////////////////////////
// GenericProjectWizardDialog
//////////////////////////////////////////////////////////////////////////////
GenericProjectWizardDialog::GenericProjectWizardDialog(QWidget *parent)
: QWizard(parent)
{
......@@ -130,44 +60,6 @@ GenericProjectWizardDialog::GenericProjectWizardDialog(QWidget *parent)
m_firstPage->setPathLabel(tr("Location:"));
addPage(m_firstPage);
#if 0
// second page
QWizardPage *secondPage = new QWizardPage;
secondPage->setTitle(tr("Second Page Title"));
QFormLayout *secondPageLayout = new QFormLayout(secondPage);
m_dirView = new QTreeView;
m_dirModel = new DirModel(this);
m_dirView->setModel(_dirModel);
Core::ICore *core = Core::ICore::instance();
Core::MimeDatabase *mimeDatabase = core->mimeDatabase();
const QStringList suffixes = mimeDatabase->suffixes();
QStringList nameFilters;
foreach (const QString &suffix, suffixes) {
QString nameFilter;
nameFilter.append(QLatin1String("*."));
nameFilter.append(suffix);
nameFilters.append(nameFilter);
}
m_filesView = new QListView;
m_filesModel = new QDirModel(this);
m_filesModel->setNameFilters(nameFilters);
m_filesModel->setFilter(QDir::Files);
connect(_dirView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
this, SLOT(updateFilesView(QModelIndex,QModelIndex)));
secondPageLayout->addRow(_dirView);
secondPageLayout->addRow(_filesView);
m_secondPageId = addPage(secondPage);
#endif
}
GenericProjectWizardDialog::~GenericProjectWizardDialog()
......@@ -188,50 +80,6 @@ QString GenericProjectWizardDialog::projectName() const
return m_firstPage->name();
}
void GenericProjectWizardDialog::updateFilesView(const QModelIndex &current,
const QModelIndex &)
{
if (! current.isValid())
m_filesView->setModel(0);
else {
const QString selectedPath = m_dirModel->filePath(current);
if (! m_filesView->model())
m_filesView->setModel(m_filesModel);
m_filesView->setRootIndex(m_filesModel->index(selectedPath));
}
}
void GenericProjectWizardDialog::initializePage(int id)
{
Q_UNUSED(id)
#if 0
if (id == m_secondPageId) {
using namespace Utils;
const QString projectPath = m_pathChooser->path();
QDirModel *dirModel = qobject_cast<QDirModel *>(_dirView->model());
m_dirView->setRootIndex(dirModel->index(projectPath));
}
#endif
}
bool GenericProjectWizardDialog::validateCurrentPage()
{
using namespace Utils;
#if 0
if (currentId() == m_secondPageId) {
return true;
}
#endif
return QWizard::validateCurrentPage();
}
GenericProjectWizard::GenericProjectWizard()
: Core::BaseFileWizard(parameters())
{ }
......@@ -244,9 +92,10 @@ Core::BaseFileWizardParameters GenericProjectWizard::parameters()
static Core::BaseFileWizardParameters parameters(ProjectWizard);
parameters.setIcon(QIcon(":/wizards/images/console.png"));
parameters.setName(tr("Import of Makefile-based Project"));
parameters.setId(QLatin1String("Z.Makefile"));
parameters.setDescription(tr("Creates a generic project, supporting any build system."));
parameters.setCategory(QLatin1String("Projects"));
parameters.setTrCategory(tr("Projects"));
parameters.setCategory(QLatin1String(ProjectExplorer::Constants::PROJECT_WIZARD_CATEGORY));
parameters.setTrCategory(QCoreApplication::translate("ProjectExplorer", ProjectExplorer::Constants::PROJECT_WIZARD_TR_CATEGORY));
return parameters;
}
......
......@@ -35,13 +35,8 @@
#include <QtGui/QWizard>
QT_BEGIN_NAMESPACE
class QDir;
class QDirModel;
class QFileInfo;
class QListView;
class QModelIndex;
class QStringList;
class QTreeView;
class QDir;
QT_END_NAMESPACE
namespace Utils {
......@@ -66,24 +61,7 @@ public:
QString projectName() const;
private Q_SLOTS:
void updateFilesView(const QModelIndex &current,
const QModelIndex &previous);
protected:
virtual void initializePage(int id);
virtual bool validateCurrentPage();
private:
int m_secondPageId;
Utils::FileWizardPage *m_firstPage;
QTreeView *m_dirView;
QDirModel *m_dirModel;
QListView *m_filesView;
QDirModel *m_filesModel;
};
class GenericProjectWizard : public Core::BaseFileWizard
......
......@@ -31,6 +31,7 @@
#include "clonewizardpage.h"
#include <vcsbase/checkoutjobs.h>
#include <vcsbase/vcsbaseconstants.h>
#include <utils/qtcassert.h>
#include <QtGui/QIcon>
......@@ -41,6 +42,7 @@ namespace Internal {
CloneWizard::CloneWizard(QObject *parent) :
VCSBase::BaseCheckoutWizard(parent)
{
setId(QLatin1String(VCSBase::Constants::VCS_ID_GIT));
}
QIcon CloneWizard::icon() const
......
......@@ -34,6 +34,7 @@
#include "clonewizardpage.h"
#include <vcsbase/checkoutjobs.h>
#include <vcsbase/vcsbaseconstants.h>
#include <utils/qtcassert.h>
#include <QtCore/QUrl>
......@@ -69,6 +70,7 @@ void GitoriousCloneWizardPage::initializePage()
GitoriousCloneWizard::GitoriousCloneWizard(QObject *parent) :
VCSBase::BaseCheckoutWizard(parent)
{
setId(QLatin1String(VCSBase::Constants::VCS_ID_GIT));
}
QIcon GitoriousCloneWizard::icon() const
......
......@@ -33,6 +33,7 @@
#include "mercurialsettings.h"
#include <vcsbase/checkoutjobs.h>
#include <vcsbase/vcsbaseconstants.h>
#include <QtCore/QDebug>
......@@ -42,6 +43,7 @@ CloneWizard::CloneWizard(QObject *parent)
: VCSBase::BaseCheckoutWizard(parent),
m_icon(QIcon(QLatin1String(":/mercurial/images/hg.png")))
{
setId(QLatin1String(VCSBase::Constants::VCS_ID_MERCURIAL));
}
QIcon CloneWizard::icon() const
......
......@@ -30,6 +30,8 @@
#ifndef PROJECTEXPLORERCONSTANTS_H
#define PROJECTEXPLORERCONSTANTS_H
#include <QtCore/QtGlobal>
namespace ProjectExplorer {
namespace Constants {
......@@ -194,6 +196,10 @@ const char * const PROJECTEXPLORER_PAGE = "ProjectExplorer.Projec
const char * const TASK_CATEGORY_COMPILE = "Task.Category.Compile";
const char * const TASK_CATEGORY_BUILDSYSTEM = "Task.Category.Buildsystem";
// Wizard category
const char * const PROJECT_WIZARD_CATEGORY = "R.Projects"; // (after Qt)
const char * const PROJECT_WIZARD_TR_CATEGORY = QT_TRANSLATE_NOOP("ProjectExplorer", "Projects");
} // namespace Constants
} // namespace ProjectExplorer
......
......@@ -102,10 +102,11 @@ bool QmlEditorPlugin::initialize(const QStringList & /*arguments*/, QString *err
addObject(m_editor);
Core::BaseFileWizardParameters wizardParameters(Core::IWizard::FileWizard);
wizardParameters.setCategory(QLatin1String("Qt"));
wizardParameters.setTrCategory(tr("Qt"));
wizardParameters.setCategory(QLatin1String(Core::Constants::WIZARD_CATEGORY_QT));
wizardParameters.setTrCategory(QCoreApplication::translate("Core", Core::Constants::WIZARD_TR_CATEGORY_QT));
wizardParameters.setDescription(tr("Creates a Qt QML file."));
wizardParameters.setName(tr("Qt QML File"));
wizardParameters.setId(QLatin1String("Q.Qml"));
addAutoReleasedObject(new QmlFileWizard(wizardParameters, core));
m_actionHandler = new TextEditor::TextEditorActionHandler(QmlEditor::Constants::C_QMLEDITOR,
......
......@@ -30,8 +30,10 @@
#include "qmlnewprojectwizard.h"
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <QtCore/QTextStream>
#include <QtCore/QCoreApplication>
using namespace QmlProjectManager::Internal;
......@@ -56,11 +58,12 @@ QmlNewProjectWizard::~QmlNewProjectWizard()
Core::BaseFileWizardParameters QmlNewProjectWizard::parameters()
{
static Core::BaseFileWizardParameters parameters(ProjectWizard);
parameters.setIcon(QIcon(":/wizards/images/console.png"));
parameters.setIcon(QIcon(QLatin1String(":/wizards/images/console.png")));
parameters.setName(tr("QML Application"));
parameters.setId(QLatin1String("QA.QML Application"));
parameters.setDescription(tr("Creates a QML application."));
parameters.setCategory(QLatin1String("Projects"));
parameters.setTrCategory(tr("Projects"));
parameters.setCategory(QLatin1String(ProjectExplorer::Constants::PROJECT_WIZARD_CATEGORY));
parameters.setTrCategory(QCoreApplication::translate("ProjectExplorer", ProjectExplorer::Constants::PROJECT_WIZARD_TR_CATEGORY));
return parameters;
}
......
......@@ -32,92 +32,22 @@
#include <coreplugin/icore.h>
#include <coreplugin/mimedatabase.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <utils/filenamevalidatinglineedit.h>
#include <utils/filewizardpage.h>
#include <utils/pathchooser.h>
#include <QtCore/QDir>
#include <QtCore/QtDebug>
#include <QtGui/QDirModel>
#include <QtGui/QFormLayout>
#include <QtGui/QListView>
#include <QtGui/QTreeView>
#include <QtCore/QCoreApplication>
using namespace QmlProjectManager::Internal;
using namespace Utils;
namespace {
class DirModel : public QDirModel
{
public:
DirModel(QObject *parent)
: QDirModel(parent)
{ setFilter(QDir::Dirs | QDir::NoDotAndDotDot); }