Commit ebb8faae authored by Daniel Molkentin's avatar Daniel Molkentin

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

Reviewed-by: trustme
parent 25a44296
......@@ -56,7 +56,6 @@ ICore* ICore::instance()
}
CoreImpl::CoreImpl(MainWindow *mainwindow)
: m_preferredWizardKinds(IWizard::ProjectWizard)
{
m_instance = this;
m_mainwindow = mainwindow;
......@@ -69,11 +68,6 @@ 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,8 +47,6 @@ 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,8 +91,6 @@ public:
private:
MainWindow *m_mainwindow;
friend class MainWindow;
IWizard::WizardKinds m_preferredWizardKinds;
};
} // namespace Internal
......
......@@ -152,8 +152,7 @@ using namespace Core::Internal;
NewDialog::NewDialog(QWidget *parent) :
QDialog(parent),
m_ui(new Core::Internal::Ui::NewDialog),
m_okButton(0),
m_preferredWizardKinds(0)
m_okButton(0)
{
typedef QMap<QString, QStandardItem *> CategoryItemMap;
m_ui->setupUi(this);
......@@ -194,11 +193,6 @@ 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, QStandardItem *> CategoryItemMap;
......@@ -243,9 +237,10 @@ void NewDialog::setWizards(QList<IWizard*> wizards)
break;
}
kindItem->appendRow(categoryItem);
m_categoryItems.append(categoryItem);
categoryItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
categoryItem->setText(wizard->displayCategory());
categoryItem->setData(QVariant::fromValue(0), Qt::UserRole);
categoryItem->setData(wizard->category(), Qt::UserRole);
cit = categories.insert(categoryName, categoryItem);
}
// add item
......@@ -277,8 +272,20 @@ void NewDialog::setWizards(QList<IWizard*> wizards)
Core::IWizard *NewDialog::showDialog()
{
// Select first category, first item by default
m_ui->templateCategoryView->setCurrentIndex(m_proxyModel->index(0,0, m_proxyModel->index(0,0)));
static QString lastCategory;
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
m_ui->templateCategoryView->setFocus(Qt::NoFocusReason);
......@@ -289,8 +296,15 @@ Core::IWizard *NewDialog::showDialog()
currentItemChanged(m_ui->templatesView->rootIndex().child(0,0));
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 currentWizard();
}
......
......@@ -34,6 +34,7 @@
#include <QtGui/QDialog>
#include <QtCore/QList>
#include <QtCore/QModelIndex>
QT_BEGIN_NAMESPACE
class QAbstractProxyModel;
......@@ -41,7 +42,6 @@ class QPushButton;
class QStandardItem;
class QStandardItemModel;
class QStringList;
class QModelIndex;
QT_END_NAMESPACE
namespace Core {
......@@ -61,7 +61,6 @@ public:
virtual ~NewDialog();
void setWizards(QList<IWizard*> wizards);
void setPreferredWizardKinds(IWizard::WizardKinds kinds);
Core::IWizard *showDialog();
......@@ -77,8 +76,8 @@ private:
QStandardItemModel *m_model;
QAbstractProxyModel *m_proxyModel;
QPushButton *m_okButton;
IWizard::WizardKinds m_preferredWizardKinds;
QPixmap m_dummyIcon;
QList<QStandardItem*> m_categoryItems;
};
} // namespace Internal
......
......@@ -67,17 +67,6 @@
\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())
......
......@@ -74,7 +74,6 @@ 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(),
......
......@@ -775,8 +775,7 @@ void MainWindow::registerDefaultActions()
void MainWindow::newFile()
{
showNewItemDialog(tr("New", "Title of dialog"), IWizard::allWizards(),
QString(), m_coreImpl->newItemDialogPreferredWizardKinds());
showNewItemDialog(tr("New", "Title of dialog"), IWizard::allWizards(), QString());
}
void MainWindow::openFile()
......@@ -863,8 +862,7 @@ void MainWindow::setFocusToEditor()
QStringList MainWindow::showNewItemDialog(const QString &title,
const QList<IWizard *> &wizards,
const QString &defaultLocation,
IWizard::WizardKinds preferredWizardKinds)
const QString &defaultLocation)
{
// Scan for wizards matching the filter and pick one. Don't show
// dialog if there is only one.
......@@ -879,7 +877,6 @@ QStringList MainWindow::showNewItemDialog(const QString &title,
NewDialog dlg(this);
dlg.setWizards(wizards);
dlg.setWindowTitle(title);
dlg.setPreferredWizardKinds(preferredWizardKinds);
wizard = dlg.showDialog();
}
break;
......
......@@ -134,8 +134,7 @@ public slots:
QStringList showNewItemDialog(const QString &title,
const QList<IWizard *> &wizards,
const QString &defaultLocation = QString(),
IWizard::WizardKinds preferredWizardKinds = 0);
const QString &defaultLocation = QString());
bool showOptionsDialog(const QString &category = QString(),
const QString &page = QString(),
......
......@@ -256,10 +256,6 @@ 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()));
connect(d->m_session, SIGNAL(dependencyChanged(ProjectExplorer::Project*,ProjectExplorer::Project*)),
this, SLOT(updateActions()));
......@@ -1882,17 +1878,6 @@ 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)
......
......@@ -170,7 +170,6 @@ private slots:
void updateRecentProjectMenu();
void openRecentProject();
void openTerminalHere();
void updatePreferredWizardKinds();
void invalidateProject(ProjectExplorer::Project *project);
......
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