New dialog: Replace "Preferred wizards" concept by remembering the last category

Reviewed-by: trustme
This commit is contained in:
Daniel Molkentin
2010-05-19 18:30:45 +02:00
parent 25a4429666
commit ebb8faae6d
10 changed files with 30 additions and 59 deletions

View File

@@ -56,7 +56,6 @@ ICore* ICore::instance()
} }
CoreImpl::CoreImpl(MainWindow *mainwindow) CoreImpl::CoreImpl(MainWindow *mainwindow)
: m_preferredWizardKinds(IWizard::ProjectWizard)
{ {
m_instance = this; m_instance = this;
m_mainwindow = mainwindow; m_mainwindow = mainwindow;
@@ -69,11 +68,6 @@ QStringList CoreImpl::showNewItemDialog(const QString &title,
return m_mainwindow->showNewItemDialog(title, wizards, defaultLocation); 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) bool CoreImpl::showOptionsDialog(const QString &group, const QString &page, QWidget *parent)
{ {
return m_mainwindow->showOptionsDialog(group, page, parent); return m_mainwindow->showOptionsDialog(group, page, parent);

View File

@@ -47,8 +47,6 @@ public:
QStringList showNewItemDialog(const QString &title, QStringList showNewItemDialog(const QString &title,
const QList<IWizard *> &wizards, const QList<IWizard *> &wizards,
const QString &defaultLocation = QString()); const QString &defaultLocation = QString());
void setNewItemDialogPreferredWizardKinds(IWizard::WizardKinds kinds);
IWizard::WizardKinds newItemDialogPreferredWizardKinds() { return m_preferredWizardKinds; }
bool showOptionsDialog(const QString &group = QString(), bool showOptionsDialog(const QString &group = QString(),
const QString &page = QString(), const QString &page = QString(),
QWidget *parent = 0); QWidget *parent = 0);
@@ -93,8 +91,6 @@ public:
private: private:
MainWindow *m_mainwindow; MainWindow *m_mainwindow;
friend class MainWindow; friend class MainWindow;
IWizard::WizardKinds m_preferredWizardKinds;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -152,8 +152,7 @@ using namespace Core::Internal;
NewDialog::NewDialog(QWidget *parent) : NewDialog::NewDialog(QWidget *parent) :
QDialog(parent), QDialog(parent),
m_ui(new Core::Internal::Ui::NewDialog), m_ui(new Core::Internal::Ui::NewDialog),
m_okButton(0), m_okButton(0)
m_preferredWizardKinds(0)
{ {
typedef QMap<QString, QStandardItem *> CategoryItemMap; typedef QMap<QString, QStandardItem *> CategoryItemMap;
m_ui->setupUi(this); m_ui->setupUi(this);
@@ -194,11 +193,6 @@ bool wizardLessThan(const IWizard *w1, const IWizard *w2)
return w1->id().compare(w2->id()) < 0; return w1->id().compare(w2->id()) < 0;
} }
void NewDialog::setPreferredWizardKinds(IWizard::WizardKinds kinds)
{
m_preferredWizardKinds = kinds;
}
void NewDialog::setWizards(QList<IWizard*> wizards) void NewDialog::setWizards(QList<IWizard*> wizards)
{ {
typedef QMap<QString, QStandardItem *> CategoryItemMap; typedef QMap<QString, QStandardItem *> CategoryItemMap;
@@ -243,9 +237,10 @@ void NewDialog::setWizards(QList<IWizard*> wizards)
break; break;
} }
kindItem->appendRow(categoryItem); kindItem->appendRow(categoryItem);
m_categoryItems.append(categoryItem);
categoryItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); categoryItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
categoryItem->setText(wizard->displayCategory()); categoryItem->setText(wizard->displayCategory());
categoryItem->setData(QVariant::fromValue(0), Qt::UserRole); categoryItem->setData(wizard->category(), Qt::UserRole);
cit = categories.insert(categoryName, categoryItem); cit = categories.insert(categoryName, categoryItem);
} }
// add item // add item
@@ -277,8 +272,20 @@ void NewDialog::setWizards(QList<IWizard*> wizards)
Core::IWizard *NewDialog::showDialog() Core::IWizard *NewDialog::showDialog()
{ {
// Select first category, first item by default static QString lastCategory;
m_ui->templateCategoryView->setCurrentIndex(m_proxyModel->index(0,0, m_proxyModel->index(0,0))); QModelIndex idx;
if (!lastCategory.isEmpty())
foreach(QStandardItem* item, m_categoryItems) {
if (item->data(Qt::UserRole) == lastCategory) {
idx = m_proxyModel->mapToSource(m_model->indexFromItem(item));
}
}
if (!idx.isValid())
idx = m_proxyModel->index(0,0, m_proxyModel->index(0,0));
m_ui->templateCategoryView->setCurrentIndex(idx);
// We need to set ensure that the category has default focus // We need to set ensure that the category has default focus
m_ui->templateCategoryView->setFocus(Qt::NoFocusReason); m_ui->templateCategoryView->setFocus(Qt::NoFocusReason);
@@ -289,8 +296,15 @@ Core::IWizard *NewDialog::showDialog()
currentItemChanged(m_ui->templatesView->rootIndex().child(0,0)); currentItemChanged(m_ui->templatesView->rootIndex().child(0,0));
updateOkButton(); updateOkButton();
if (exec() != Accepted)
const int retVal = exec();
idx = m_ui->templateCategoryView->currentIndex();
lastCategory = m_model->itemFromIndex(m_proxyModel->mapToSource(idx))->data(Qt::UserRole).toString();
if (retVal != Accepted)
return 0; return 0;
return currentWizard(); return currentWizard();
} }

View File

@@ -34,6 +34,7 @@
#include <QtGui/QDialog> #include <QtGui/QDialog>
#include <QtCore/QList> #include <QtCore/QList>
#include <QtCore/QModelIndex>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QAbstractProxyModel; class QAbstractProxyModel;
@@ -41,7 +42,6 @@ class QPushButton;
class QStandardItem; class QStandardItem;
class QStandardItemModel; class QStandardItemModel;
class QStringList; class QStringList;
class QModelIndex;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace Core { namespace Core {
@@ -61,7 +61,6 @@ public:
virtual ~NewDialog(); virtual ~NewDialog();
void setWizards(QList<IWizard*> wizards); void setWizards(QList<IWizard*> wizards);
void setPreferredWizardKinds(IWizard::WizardKinds kinds);
Core::IWizard *showDialog(); Core::IWizard *showDialog();
@@ -77,8 +76,8 @@ private:
QStandardItemModel *m_model; QStandardItemModel *m_model;
QAbstractProxyModel *m_proxyModel; QAbstractProxyModel *m_proxyModel;
QPushButton *m_okButton; QPushButton *m_okButton;
IWizard::WizardKinds m_preferredWizardKinds;
QPixmap m_dummyIcon; QPixmap m_dummyIcon;
QList<QStandardItem*> m_categoryItems;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -67,17 +67,6 @@
\sa Core::FileManager \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(), \fn bool ICore::showOptionsDialog(const QString &group = QString(),
const QString &page = QString()) const QString &page = QString())

View File

@@ -74,7 +74,6 @@ public:
virtual QStringList showNewItemDialog(const QString &title, virtual QStringList showNewItemDialog(const QString &title,
const QList<IWizard *> &wizards, const QList<IWizard *> &wizards,
const QString &defaultLocation = QString()) = 0; const QString &defaultLocation = QString()) = 0;
virtual void setNewItemDialogPreferredWizardKinds(IWizard::WizardKinds kinds) = 0;
virtual bool showOptionsDialog(const QString &group = QString(), virtual bool showOptionsDialog(const QString &group = QString(),
const QString &page = QString(), const QString &page = QString(),

View File

@@ -775,8 +775,7 @@ void MainWindow::registerDefaultActions()
void MainWindow::newFile() void MainWindow::newFile()
{ {
showNewItemDialog(tr("New", "Title of dialog"), IWizard::allWizards(), showNewItemDialog(tr("New", "Title of dialog"), IWizard::allWizards(), QString());
QString(), m_coreImpl->newItemDialogPreferredWizardKinds());
} }
void MainWindow::openFile() void MainWindow::openFile()
@@ -863,8 +862,7 @@ void MainWindow::setFocusToEditor()
QStringList MainWindow::showNewItemDialog(const QString &title, QStringList MainWindow::showNewItemDialog(const QString &title,
const QList<IWizard *> &wizards, 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 // Scan for wizards matching the filter and pick one. Don't show
// dialog if there is only one. // dialog if there is only one.
@@ -879,7 +877,6 @@ QStringList MainWindow::showNewItemDialog(const QString &title,
NewDialog dlg(this); NewDialog dlg(this);
dlg.setWizards(wizards); dlg.setWizards(wizards);
dlg.setWindowTitle(title); dlg.setWindowTitle(title);
dlg.setPreferredWizardKinds(preferredWizardKinds);
wizard = dlg.showDialog(); wizard = dlg.showDialog();
} }
break; break;

View File

@@ -134,8 +134,7 @@ public slots:
QStringList showNewItemDialog(const QString &title, QStringList showNewItemDialog(const QString &title,
const QList<IWizard *> &wizards, const QList<IWizard *> &wizards,
const QString &defaultLocation = QString(), const QString &defaultLocation = QString());
IWizard::WizardKinds preferredWizardKinds = 0);
bool showOptionsDialog(const QString &category = QString(), bool showOptionsDialog(const QString &category = QString(),
const QString &page = QString(), const QString &page = QString(),

View File

@@ -256,10 +256,6 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
this, SIGNAL(fileListChanged())); this, SIGNAL(fileListChanged()));
connect(d->m_session, SIGNAL(startupProjectChanged(ProjectExplorer::Project *)), connect(d->m_session, SIGNAL(startupProjectChanged(ProjectExplorer::Project *)),
this, SLOT(startupProjectChanged())); 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()));
connect(d->m_session, SIGNAL(dependencyChanged(ProjectExplorer::Project*,ProjectExplorer::Project*)), connect(d->m_session, SIGNAL(dependencyChanged(ProjectExplorer::Project*,ProjectExplorer::Project*)),
this, SLOT(updateActions())); this, SLOT(updateActions()));
@@ -1882,17 +1878,6 @@ void ProjectExplorerPlugin::openRecentProject()
openProject(fileName); 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) void ProjectExplorerPlugin::invalidateProject(Project *project)
{ {
if (debug) if (debug)

View File

@@ -170,7 +170,6 @@ private slots:
void updateRecentProjectMenu(); void updateRecentProjectMenu();
void openRecentProject(); void openRecentProject();
void openTerminalHere(); void openTerminalHere();
void updatePreferredWizardKinds();
void invalidateProject(ProjectExplorer::Project *project); void invalidateProject(ProjectExplorer::Project *project);