Add a function to database widget to access enabled state of actions.

This commit is contained in:
Florian Geyer 2012-05-26 19:40:02 +02:00
parent 267e88001b
commit 4751f40c2b
3 changed files with 51 additions and 13 deletions

View File

@ -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());

View File

@ -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();

View File

@ -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);