diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index f35b6d2e0..6c687203f 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -177,6 +177,33 @@ DatabaseWidget::Mode DatabaseWidget::currentMode() } } +bool DatabaseWidget::actionEnabled(Action action) +{ + switch (action) { + case GroupNew: + return m_actionGroupNew->isEnabled(); + case GroupEdit: + return m_actionGroupEdit->isEnabled(); + case GroupDelete: + return m_actionGroupDelete->isEnabled(); + case EntryNew: + return m_actionEntryNew->isEnabled(); + case EntryClone: + return m_actionEntryClone->isEnabled(); + case EntryEditView: + return m_actionEntryEditView->isEnabled(); + case EntryDelete: + return m_actionEntryDelete->isEnabled(); + case EntryCopyUsername: + return m_actionEntryCopyUsername->isEnabled(); + case EntryCopyPassword: + return m_actionEntryCopyPassword->isEnabled(); + default: + Q_ASSERT(false); + return false; + } +} + void DatabaseWidget::emitCurrentModeChanged() { Q_EMIT currentModeChanged(currentMode()); diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index 80b8be23e..c70f15555 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -47,6 +47,18 @@ public: ViewMode, EditMode }; + enum Action + { + GroupNew, + GroupEdit, + GroupDelete, + EntryNew, + EntryClone, + EntryEditView, + EntryDelete, + EntryCopyUsername, + EntryCopyPassword + }; explicit DatabaseWidget(Database* db, QWidget* parent = 0); ~DatabaseWidget(); @@ -57,6 +69,7 @@ public: int addWidget(QWidget* w); void setCurrentIndex(int index); DatabaseWidget::Mode currentMode(); + bool actionEnabled(Action action); Q_SIGNALS: void closeRequest(); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 8e0350984..b47875603 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -120,20 +120,18 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode) switch (mode) { case DatabaseWidget::ViewMode: { - bool inSearch = dbWidget->entryView()->inSearch(); - bool singleEntry = dbWidget->entryView()->isSingleEntrySelected(); - - m_ui->actionEntryNew->setEnabled(!inSearch); - m_ui->actionEntryClone->setEnabled(!inSearch && singleEntry); - m_ui->actionEntryEdit->setEnabled(singleEntry); - m_ui->actionEntryDelete->setEnabled(singleEntry); - m_ui->actionEntryCopyUsername->setEnabled(singleEntry); - m_ui->actionEntryCopyPassword->setEnabled(singleEntry); - m_ui->actionGroupNew->setEnabled(!inSearch); - m_ui->actionGroupEdit->setEnabled(!inSearch); - m_ui->actionGroupDelete->setEnabled(!inSearch && dbWidget->canDeleteCurrentGoup()); + m_ui->actionEntryNew->setEnabled(dbWidget->actionEnabled(DatabaseWidget::EntryNew)); + m_ui->actionEntryClone->setEnabled(dbWidget->actionEnabled(DatabaseWidget::EntryClone)); + m_ui->actionEntryEdit->setEnabled(dbWidget->actionEnabled(DatabaseWidget::EntryEditView)); + m_ui->actionEntryDelete->setEnabled(dbWidget->actionEnabled(DatabaseWidget::EntryDelete)); + m_ui->actionEntryCopyUsername->setEnabled(dbWidget->actionEnabled(DatabaseWidget::EntryCopyUsername)); + m_ui->actionEntryCopyPassword->setEnabled(dbWidget->actionEnabled(DatabaseWidget::EntryCopyPassword)); + m_ui->actionGroupNew->setEnabled(dbWidget->actionEnabled(DatabaseWidget::GroupNew)); + m_ui->actionGroupEdit->setEnabled(dbWidget->actionEnabled(DatabaseWidget::GroupEdit)); + m_ui->actionGroupDelete->setEnabled(dbWidget->actionEnabled(DatabaseWidget::GroupDelete)); m_ui->actionSearch->setEnabled(true); - m_ui->actionSearch->setChecked(inSearch); + // TODO: get checked state from db widget + m_ui->actionSearch->setChecked(dbWidget->entryView()->inSearch()); m_ui->actionChangeMasterKey->setEnabled(true); m_ui->actionChangeDatabaseSettings->setEnabled(true); m_ui->actionDatabaseSave->setEnabled(true);