Disable some menu actions while searching.

This commit is contained in:
Florian Geyer 2012-05-13 18:08:22 +02:00
parent 6b6c109903
commit 0e19b47755
3 changed files with 29 additions and 6 deletions

View File

@ -25,6 +25,7 @@ EntryView::EntryView(QWidget* parent)
: QTreeView(parent) : QTreeView(parent)
, m_model(new EntryModel(this)) , m_model(new EntryModel(this))
, m_sortModel(new QSortFilterProxyModel(this)) , m_sortModel(new QSortFilterProxyModel(this))
, m_inSearch(false)
{ {
m_sortModel->setSourceModel(m_model); m_sortModel->setSourceModel(m_model);
m_sortModel->setDynamicSortFilter(true); m_sortModel->setDynamicSortFilter(true);
@ -58,6 +59,11 @@ void EntryView::search(QList<Entry*> entries)
Q_EMIT entrySelectionChanged(); Q_EMIT entrySelectionChanged();
} }
bool EntryView::inSearch()
{
return m_inSearch;
}
void EntryView::emitEntryActivated(const QModelIndex& index) void EntryView::emitEntryActivated(const QModelIndex& index)
{ {
Q_EMIT entryActivated(entryFromIndex(index)); Q_EMIT entryActivated(entryFromIndex(index));
@ -98,9 +104,11 @@ Entry* EntryView::entryFromIndex(const QModelIndex& index)
void EntryView::switchToSearch() void EntryView::switchToSearch()
{ {
showColumn(0); showColumn(0);
m_inSearch = true;
} }
void EntryView::switchToView() void EntryView::switchToView()
{ {
hideColumn(0); hideColumn(0);
m_inSearch = false;
} }

View File

@ -37,6 +37,7 @@ public:
void setCurrentEntry(Entry* entry); void setCurrentEntry(Entry* entry);
Entry* entryFromIndex(const QModelIndex& index); Entry* entryFromIndex(const QModelIndex& index);
void search(QList<Entry *> entries); void search(QList<Entry *> entries);
bool inSearch();
public Q_SLOTS: public Q_SLOTS:
void setGroup(Group* group); void setGroup(Group* group);
@ -53,6 +54,7 @@ Q_SIGNALS:
private: private:
EntryModel* const m_model; EntryModel* const m_model;
QSortFilterProxyModel* const m_sortModel; QSortFilterProxyModel* const m_sortModel;
bool m_inSearch;
}; };
#endif // KEEPASSX_ENTRYVIEW_H #endif // KEEPASSX_ENTRYVIEW_H

View File

@ -102,8 +102,13 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
switch (mode) { switch (mode) {
case DatabaseWidget::ViewMode: case DatabaseWidget::ViewMode:
if (dbWidget->entryView()->inSearch()) {
m_ui->actionEntryNew->setEnabled(false);
}
else {
m_ui->actionEntryNew->setEnabled(true); m_ui->actionEntryNew->setEnabled(true);
m_ui->actionGroupNew->setEnabled(true); }
if (dbWidget->entryView()->currentIndex().isValid()) { if (dbWidget->entryView()->currentIndex().isValid()) {
m_ui->actionEntryEdit->setEnabled(true); m_ui->actionEntryEdit->setEnabled(true);
m_ui->actionEntryDelete->setEnabled(true); m_ui->actionEntryDelete->setEnabled(true);
@ -112,14 +117,22 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
m_ui->actionEntryEdit->setEnabled(false); m_ui->actionEntryEdit->setEnabled(false);
m_ui->actionEntryDelete->setEnabled(false); m_ui->actionEntryDelete->setEnabled(false);
} }
m_ui->actionGroupEdit->setEnabled(true);
if (dbWidget->entryView()->inSearch()) {
m_ui->actionGroupNew->setEnabled(false);
m_ui->actionGroupEdit->setEnabled(false);
m_ui->actionGroupDelete->setEnabled(false);
}
else {
m_ui->actionGroupNew->setEnabled(true);
m_ui->actionGroupEdit->setEnabled(true);
if (dbWidget->canDeleteCurrentGoup()) { if (dbWidget->canDeleteCurrentGoup()) {
m_ui->actionGroupDelete->setEnabled(true); m_ui->actionGroupDelete->setEnabled(true);
} }
else { else {
m_ui->actionGroupDelete->setEnabled(false); m_ui->actionGroupDelete->setEnabled(false);
} }
}
m_ui->actionChangeMasterKey->setEnabled(true); m_ui->actionChangeMasterKey->setEnabled(true);
m_ui->actionChangeDatabaseSettings->setEnabled(true); m_ui->actionChangeDatabaseSettings->setEnabled(true);
m_ui->actionDatabaseSave->setEnabled(true); m_ui->actionDatabaseSave->setEnabled(true);