Commit 4a46d086 authored by con's avatar con
Browse files

Rename IWizard::Kind --> IWizard::WizardKind, add some logic for which wizard...

Rename IWizard::Kind --> IWizard::WizardKind, add some logic for which wizard kinds to collapse/expand.
parent d4be77b4
......@@ -184,9 +184,9 @@ bool GeneratedFile::write(QString *errorMessage) const
class BaseFileWizardParameterData : public QSharedData
{
public:
explicit BaseFileWizardParameterData(IWizard::Kind kind = IWizard::FileWizard);
explicit BaseFileWizardParameterData(IWizard::WizardKind kind = IWizard::FileWizard);
IWizard::Kind kind;
IWizard::WizardKind kind;
QIcon icon;
QString description;
QString displayName;
......@@ -195,12 +195,12 @@ public:
QString displayCategory;
};
BaseFileWizardParameterData::BaseFileWizardParameterData(IWizard::Kind k) :
BaseFileWizardParameterData::BaseFileWizardParameterData(IWizard::WizardKind k) :
kind(k)
{
}
BaseFileWizardParameters::BaseFileWizardParameters(IWizard::Kind kind) :
BaseFileWizardParameters::BaseFileWizardParameters(IWizard::WizardKind kind) :
m_d(new BaseFileWizardParameterData(kind))
{
}
......@@ -221,12 +221,12 @@ BaseFileWizardParameters::~BaseFileWizardParameters()
{
}
IWizard::Kind BaseFileWizardParameters::kind() const
IWizard::WizardKind BaseFileWizardParameters::kind() const
{
return m_d->kind;
}
void BaseFileWizardParameters::setKind(IWizard::Kind k)
void BaseFileWizardParameters::setKind(IWizard::WizardKind k)
{
m_d->kind = k;
}
......@@ -401,7 +401,7 @@ BaseFileWizard::~BaseFileWizard()
delete m_d;
}
IWizard::Kind BaseFileWizard::kind() const
IWizard::WizardKind BaseFileWizard::kind() const
{
return m_d->m_parameters.kind();
}
......
......@@ -100,13 +100,13 @@ typedef QList<GeneratedFile> GeneratedFiles;
class CORE_EXPORT BaseFileWizardParameters
{
public:
explicit BaseFileWizardParameters(IWizard::Kind kind = IWizard::FileWizard);
explicit BaseFileWizardParameters(IWizard::WizardKind kind = IWizard::FileWizard);
BaseFileWizardParameters(const BaseFileWizardParameters &);
BaseFileWizardParameters &operator=(const BaseFileWizardParameters&);
~BaseFileWizardParameters();
IWizard::Kind kind() const;
void setKind(IWizard::Kind k);
IWizard::WizardKind kind() const;
void setKind(IWizard::WizardKind k);
QIcon icon() const;
void setIcon(const QIcon &icon);
......@@ -151,7 +151,7 @@ public:
virtual ~BaseFileWizard();
// IWizard
virtual Kind kind() const;
virtual WizardKind kind() const;
virtual QIcon icon() const;
virtual QString description() const;
virtual QString displayName() const;
......
......@@ -53,6 +53,7 @@ ICore* ICore::instance()
}
CoreImpl::CoreImpl(MainWindow *mainwindow)
: m_preferredWizardKinds(IWizard::ProjectWizard)
{
m_instance = this;
m_mainwindow = mainwindow;
......@@ -65,6 +66,11 @@ QStringList CoreImpl::showNewItemDialog(const QString &title,
return m_mainwindow->showNewItemDialog(title, wizards, defaultLocation);
}
void CoreImpl::setNewItemDialogPreferredWizardKinds(IWizard::WizardKinds kinds)
{
m_preferredWizardKinds = kinds;
}
bool CoreImpl::showOptionsDialog(const QString &group, const QString &page, QWidget *parent)
{
return m_mainwindow->showOptionsDialog(group, page, parent);
......
......@@ -47,6 +47,8 @@ public:
QStringList showNewItemDialog(const QString &title,
const QList<IWizard *> &wizards,
const QString &defaultLocation = QString());
void setNewItemDialogPreferredWizardKinds(IWizard::WizardKinds kinds);
IWizard::WizardKinds newItemDialogPreferredWizardKinds() { return m_preferredWizardKinds; }
bool showOptionsDialog(const QString &group = QString(),
const QString &page = QString(),
QWidget *parent = 0);
......@@ -93,6 +95,8 @@ public:
private:
MainWindow *m_mainwindow;
friend class MainWindow;
IWizard::WizardKinds m_preferredWizardKinds;
};
} // namespace Internal
......
......@@ -61,7 +61,7 @@
*/
/*!
\enum Core::IWizard::Kind
\enum Core::IWizard::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.
......@@ -158,13 +158,13 @@ QList<IWizard*> IWizard::allWizards()
class WizardKindPredicate {
public:
WizardKindPredicate(IWizard::Kind kind) : m_kind(kind) {}
WizardKindPredicate(IWizard::WizardKind kind) : m_kind(kind) {}
bool operator()(const IWizard &w) const { return w.kind() == m_kind; }
private:
const IWizard::Kind m_kind;
const IWizard::WizardKind m_kind;
};
QList<IWizard*> IWizard::wizardsOfKind(Kind kind)
QList<IWizard*> IWizard::wizardsOfKind(WizardKind kind)
{
return findWizards(WizardKindPredicate(kind));
}
......
......@@ -44,16 +44,17 @@ class CORE_EXPORT IWizard
{
Q_OBJECT
public:
enum Kind {
FileWizard,
ClassWizard,
ProjectWizard
enum WizardKind {
FileWizard = 0x01,
ClassWizard = 0x02,
ProjectWizard = 0x04
};
Q_DECLARE_FLAGS(WizardKinds, WizardKind)
IWizard(QObject *parent = 0) : QObject(parent) {}
virtual ~IWizard() {}
virtual Kind kind() const = 0;
virtual WizardKind kind() const = 0;
virtual QIcon icon() const = 0;
virtual QString description() const = 0;
virtual QString displayName() const = 0;
......@@ -67,9 +68,11 @@ public:
// Utility to find all registered wizards
static QList<IWizard*> allWizards();
// Utility to find all registered wizards of a certain kind
static QList<IWizard*> wizardsOfKind(Kind kind);
static QList<IWizard*> wizardsOfKind(WizardKind kind);
};
} // namespace Core
Q_DECLARE_OPERATORS_FOR_FLAGS(Core::IWizard::WizardKinds)
#endif // IWIZARD_H
......@@ -53,7 +53,8 @@ using namespace Core::Internal;
NewDialog::NewDialog(QWidget *parent) :
QDialog(parent),
m_ui(new Core::Internal::Ui::NewDialog),
m_okButton(0)
m_okButton(0),
m_preferredWizardKinds(0)
{
typedef QMap<QString, QTreeWidgetItem *> CategoryItemMap;
m_ui->setupUi(this);
......@@ -79,6 +80,11 @@ bool wizardLessThan(const IWizard *w1, const IWizard *w2)
return w1->id().compare(w2->id()) < 0;
}
void NewDialog::setPreferredWizardKinds(IWizard::WizardKinds kinds)
{
m_preferredWizardKinds = kinds;
}
void NewDialog::setWizards(QList<IWizard*> wizards)
{
typedef QMap<QString, QTreeWidgetItem *> CategoryItemMap;
......@@ -112,11 +118,34 @@ void NewDialog::setWizards(QList<IWizard*> wizards)
Core::IWizard *NewDialog::showDialog()
{
m_ui->templatesTree->expandAll();
if (QTreeWidgetItem *rootItem = m_ui->templatesTree->topLevelItem(0)) {
m_ui->templatesTree->scrollToItem(rootItem);
if (rootItem->childCount())
m_ui->templatesTree->setCurrentItem(rootItem->child(0));
QTreeWidgetItem *itemToSelect = 0;
if (m_preferredWizardKinds == 0) {
m_ui->templatesTree->expandAll();
if (QTreeWidgetItem *rootItem = m_ui->templatesTree->topLevelItem(0)) {
if (rootItem->childCount())
itemToSelect = rootItem->child(0);
}
} else {
for (int i = 0; i < m_ui->templatesTree->topLevelItemCount(); ++i) {
QTreeWidgetItem *category = m_ui->templatesTree->topLevelItem(i);
bool hasOnlyPreferred = true;
for (int j = 0; j < category->childCount(); ++j) {
QTreeWidgetItem *item = category->child(j);
if (!(item->data(0, Qt::UserRole).value<IWizard*>()
->kind() & m_preferredWizardKinds)) {
hasOnlyPreferred = false;
break;
}
}
category->setExpanded(hasOnlyPreferred);
if (hasOnlyPreferred && itemToSelect == 0 && category->childCount() > 0) {
itemToSelect = category->child(0);
}
}
}
if (itemToSelect) {
m_ui->templatesTree->scrollToItem(itemToSelect);
m_ui->templatesTree->setCurrentItem(itemToSelect);
}
updateOkButton();
if (exec() != Accepted)
......
......@@ -30,6 +30,8 @@
#ifndef NEWDIALOG_H
#define NEWDIALOG_H
#include "iwizard.h"
#include <QtGui/QDialog>
#include <QtCore/QList>
......@@ -41,8 +43,6 @@ QT_END_NAMESPACE
namespace Core {
class IWizard;
namespace Internal {
namespace Ui {
......@@ -58,6 +58,7 @@ public:
virtual ~NewDialog();
void setWizards(QList<IWizard*> wizards);
void setPreferredWizardKinds(IWizard::WizardKinds kinds);
Core::IWizard *showDialog();
......@@ -71,6 +72,7 @@ private:
Ui::NewDialog *m_ui;
QPushButton *m_okButton;
IWizard::WizardKinds m_preferredWizardKinds;
};
} // namespace Internal
......
......@@ -67,6 +67,17 @@
\sa Core::FileManager
*/
/*!
\fn void setNewItemDialogPreferredWizardKinds(IWizard::WizardKinds kinds)
\internal
When set to true, the general "New File or Project" dialog will
collapse the project categories.
This is set by the project explorer: When projects are open, the preferred
thing is to create files/classes, if no projects are open, the preferred thing
to create are projects.
*/
/*!
\fn bool ICore::showOptionsDialog(const QString &group = QString(),
const QString &page = QString())
......
......@@ -31,6 +31,8 @@
#define ICORE_H
#include "core_global.h"
#include "dialogs/iwizard.h"
#include <QtCore/QObject>
#include <QtCore/QSettings>
......@@ -48,7 +50,6 @@ class ActionManager;
class EditorManager;
class FileManager;
class IContext;
class IWizard;
class MessageManager;
class MimeDatabase;
class ModeManager;
......@@ -72,6 +73,7 @@ public:
virtual QStringList showNewItemDialog(const QString &title,
const QList<IWizard *> &wizards,
const QString &defaultLocation = QString()) = 0;
virtual void setNewItemDialogPreferredWizardKinds(IWizard::WizardKinds kinds) = 0;
virtual bool showOptionsDialog(const QString &group = QString(),
const QString &page = QString(),
......
......@@ -56,7 +56,6 @@
#include "statusbarmanager.h"
#include "uniqueidmanager.h"
#include "manhattanstyle.h"
#include "dialogs/iwizard.h"
#include "navigationwidget.h"
#include "rightpane.h"
#include "editormanager/ieditorfactory.h"
......@@ -744,7 +743,8 @@ void MainWindow::registerDefaultActions()
void MainWindow::newFile()
{
showNewItemDialog(tr("New...", "Title of dialog"), IWizard::allWizards());
showNewItemDialog(tr("New...", "Title of dialog"), IWizard::allWizards(),
QString(), m_coreImpl->newItemDialogPreferredWizardKinds());
}
void MainWindow::openFile()
......@@ -836,7 +836,8 @@ void MainWindow::setFocusToEditor()
QStringList MainWindow::showNewItemDialog(const QString &title,
const QList<IWizard *> &wizards,
const QString &defaultLocation)
const QString &defaultLocation,
IWizard::WizardKinds preferredWizardKinds)
{
// Scan for wizards matching the filter and pick one. Don't show
// dialog if there is only one.
......@@ -851,6 +852,7 @@ QStringList MainWindow::showNewItemDialog(const QString &title,
NewDialog dlg(this);
dlg.setWizards(wizards);
dlg.setWindowTitle(title);
dlg.setPreferredWizardKinds(preferredWizardKinds);
wizard = dlg.showDialog();
}
break;
......
......@@ -31,6 +31,7 @@
#define MAINWINDOW_H
#include "core_global.h"
#include "dialogs/iwizard.h"
#include "eventfilteringmainwindow.h"
......@@ -134,7 +135,8 @@ public slots:
QStringList showNewItemDialog(const QString &title,
const QList<IWizard *> &wizards,
const QString &defaultLocation = QString());
const QString &defaultLocation = QString(),
IWizard::WizardKinds preferredWizardKinds = 0);
bool showOptionsDialog(const QString &category = QString(),
const QString &page = QString(),
......
......@@ -244,6 +244,10 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
this, SIGNAL(fileListChanged()));
connect(d->m_session, SIGNAL(startupProjectChanged(ProjectExplorer::Project *)),
this, SLOT(startupProjectChanged()));
connect(d->m_session, SIGNAL(projectAdded(ProjectExplorer::Project*)),
this, SLOT(updatePreferredWizardKinds()));
connect(d->m_session, SIGNAL(projectRemoved(ProjectExplorer::Project*)),
this, SLOT(updatePreferredWizardKinds()));
d->m_proWindow = new ProjectWindow;
......@@ -1748,6 +1752,17 @@ void ProjectExplorerPlugin::openRecentProject()
openProject(fileName);
}
void ProjectExplorerPlugin::updatePreferredWizardKinds()
{
if (d->m_session->projects().count()) {
Core::ICore::instance()->setNewItemDialogPreferredWizardKinds(
Core::IWizard::FileWizard | Core::IWizard::ClassWizard);
} else {
Core::ICore::instance()->setNewItemDialogPreferredWizardKinds(
Core::IWizard::ProjectWizard);
}
}
void ProjectExplorerPlugin::invalidateProject(Project *project)
{
if (debug)
......
......@@ -195,6 +195,7 @@ private slots:
void updateRecentProjectMenu();
void openRecentProject();
void openTerminalHere();
void updatePreferredWizardKinds();
void invalidateProject(ProjectExplorer::Project *project);
......
......@@ -70,7 +70,7 @@ BaseCheckoutWizard::~BaseCheckoutWizard()
delete d;
}
Core::IWizard::Kind BaseCheckoutWizard::kind() const
Core::IWizard::WizardKind BaseCheckoutWizard::kind() const
{
return Core::IWizard::ProjectWizard;
}
......
......@@ -67,7 +67,7 @@ public:
explicit BaseCheckoutWizard(QObject *parent = 0);
virtual ~BaseCheckoutWizard();
virtual Kind kind() const;
virtual WizardKind kind() const;
virtual QString category() const;
virtual QString displayCategory() const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment