mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-28 00:39:43 -05:00
Disable/enable menu actions depending on what currently can be done.
This commit is contained in:
parent
eb4f82a7ed
commit
fec19b475e
@ -360,6 +360,7 @@ void DatabaseTabWidget::insertDatabase(Database* db, const DatabaseManagerStruct
|
|||||||
connect(dbStruct.dbWidget->entryView(), SIGNAL(entrySelectionChanged()), SLOT(emitEntrySelectionChanged()));
|
connect(dbStruct.dbWidget->entryView(), SIGNAL(entrySelectionChanged()), SLOT(emitEntrySelectionChanged()));
|
||||||
connect(dbStruct.dbWidget, SIGNAL(closeRequest()), SLOT(closeDatabase()));
|
connect(dbStruct.dbWidget, SIGNAL(closeRequest()), SLOT(closeDatabase()));
|
||||||
connect(db, SIGNAL(modified()), SLOT(modified()));
|
connect(db, SIGNAL(modified()), SLOT(modified()));
|
||||||
|
connect(dbStruct.dbWidget, SIGNAL(currentIndexChanged(int)), this, SIGNAL(currentWidgetIndexChanged(int)));
|
||||||
}
|
}
|
||||||
|
|
||||||
DatabaseWidget* DatabaseTabWidget::currentDatabaseWidget()
|
DatabaseWidget* DatabaseTabWidget::currentDatabaseWidget()
|
||||||
|
@ -65,6 +65,7 @@ public Q_SLOTS:
|
|||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void entrySelectionChanged(bool singleEntrySelected);
|
void entrySelectionChanged(bool singleEntrySelected);
|
||||||
|
void currentWidgetIndexChanged(int index);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void updateTabName(Database* db);
|
void updateTabName(Database* db);
|
||||||
|
@ -185,6 +185,11 @@ void DatabaseWidget::switchToMasterKeyChange()
|
|||||||
setCurrentIndex(3);
|
setCurrentIndex(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DatabaseWidget::setCurrentIndex(int index) {
|
||||||
|
QStackedWidget::setCurrentIndex(index);
|
||||||
|
Q_EMIT currentIndexChanged(index);
|
||||||
|
}
|
||||||
|
|
||||||
bool DatabaseWidget::dbHasKey()
|
bool DatabaseWidget::dbHasKey()
|
||||||
{
|
{
|
||||||
return m_db->hasKey();
|
return m_db->hasKey();
|
||||||
|
@ -41,6 +41,7 @@ public:
|
|||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void closeRequest();
|
void closeRequest();
|
||||||
|
void currentIndexChanged(int index);
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void createEntry();
|
void createEntry();
|
||||||
@ -48,6 +49,7 @@ public Q_SLOTS:
|
|||||||
void switchToEntryEdit();
|
void switchToEntryEdit();
|
||||||
void switchToGroupEdit();
|
void switchToGroupEdit();
|
||||||
void switchToMasterKeyChange();
|
void switchToMasterKeyChange();
|
||||||
|
void setCurrentIndex(int index);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void switchToView(bool accepted);
|
void switchToView(bool accepted);
|
||||||
|
@ -35,6 +35,7 @@ EntryView::EntryView(QWidget* parent)
|
|||||||
void EntryView::setGroup(Group* group)
|
void EntryView::setGroup(Group* group)
|
||||||
{
|
{
|
||||||
m_model->setGroup(group);
|
m_model->setGroup(group);
|
||||||
|
Q_EMIT entrySelectionChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntryView::emitEntryActivated(const QModelIndex& index)
|
void EntryView::emitEntryActivated(const QModelIndex& index)
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "core/DataPath.h"
|
#include "core/DataPath.h"
|
||||||
#include "core/Metadata.h"
|
#include "core/Metadata.h"
|
||||||
#include "gui/DatabaseWidget.h"
|
#include "gui/DatabaseWidget.h"
|
||||||
|
#include "gui/EntryView.h"
|
||||||
|
|
||||||
MainWindow::MainWindow()
|
MainWindow::MainWindow()
|
||||||
: m_ui(new Ui::MainWindow())
|
: m_ui(new Ui::MainWindow())
|
||||||
@ -32,9 +33,9 @@ MainWindow::MainWindow()
|
|||||||
|
|
||||||
setWindowIcon(dataPath()->applicationIcon());
|
setWindowIcon(dataPath()->applicationIcon());
|
||||||
|
|
||||||
connect(m_ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(currentTabChanged(int)));
|
connect(m_ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(setMenuActionState()));
|
||||||
connect(m_ui->tabWidget, SIGNAL(entrySelectionChanged(bool)), m_ui->actionEntryEdit, SLOT(setEnabled(bool)));
|
connect(m_ui->tabWidget, SIGNAL(entrySelectionChanged(bool)), SLOT(setMenuActionState()));
|
||||||
connect(m_ui->tabWidget, SIGNAL(entrySelectionChanged(bool)), m_ui->actionEntryDelete, SLOT(setEnabled(bool)));
|
connect(m_ui->tabWidget, SIGNAL(currentWidgetIndexChanged(int)), SLOT(setMenuActionState(int)));
|
||||||
|
|
||||||
connect(m_ui->actionDatabaseNew, SIGNAL(triggered()), m_ui->tabWidget, SLOT(newDatabase()));
|
connect(m_ui->actionDatabaseNew, SIGNAL(triggered()), m_ui->tabWidget, SLOT(newDatabase()));
|
||||||
connect(m_ui->actionDatabaseOpen, SIGNAL(triggered()), m_ui->tabWidget, SLOT(openDatabase()));
|
connect(m_ui->actionDatabaseOpen, SIGNAL(triggered()), m_ui->tabWidget, SLOT(openDatabase()));
|
||||||
@ -53,17 +54,75 @@ MainWindow::~MainWindow()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::currentTabChanged(int index)
|
void MainWindow::setMenuActionState(int index)
|
||||||
{
|
{
|
||||||
bool hasTab = (index != -1);
|
if (m_ui->tabWidget->currentIndex() != -1)
|
||||||
|
{
|
||||||
|
m_ui->actionDatabaseClose->setEnabled(true);
|
||||||
|
DatabaseWidget* dbWidget = m_ui->tabWidget->currentDatabaseWidget();
|
||||||
|
Q_ASSERT(dbWidget);
|
||||||
|
|
||||||
m_ui->actionDatabaseSave->setEnabled(hasTab);
|
if (index == -1) {
|
||||||
m_ui->actionDatabaseSaveAs->setEnabled(hasTab);
|
index = dbWidget->currentIndex();
|
||||||
m_ui->actionDatabaseClose->setEnabled(hasTab);
|
}
|
||||||
m_ui->actionEntryNew->setEnabled(hasTab);
|
|
||||||
m_ui->actionGroupNew->setEnabled(hasTab);
|
switch(index) {
|
||||||
m_ui->actionGroupEdit->setEnabled(hasTab);
|
case 0: // view
|
||||||
m_ui->actionChangeMasterKey->setEnabled(hasTab);
|
m_ui->actionEntryNew->setEnabled(true);
|
||||||
|
m_ui->actionGroupNew->setEnabled(true);
|
||||||
|
if (dbWidget->entryView()->currentIndex().isValid()) {
|
||||||
|
m_ui->actionEntryEdit->setEnabled(true);
|
||||||
|
m_ui->actionEntryDelete->setEnabled(true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_ui->actionEntryEdit->setEnabled(false);
|
||||||
|
m_ui->actionEntryDelete->setEnabled(false);
|
||||||
|
}
|
||||||
|
m_ui->actionGroupEdit->setEnabled(true);
|
||||||
|
// TODO
|
||||||
|
/*
|
||||||
|
if () { //check if root group selected
|
||||||
|
m_ui->actiocGroupDelete->setEnabled(true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_ui->actiocGroupDelete->setEnabled(false);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
m_ui->actionChangeMasterKey->setEnabled(true);
|
||||||
|
m_ui->actionDatabaseSave->setEnabled(true);
|
||||||
|
m_ui->actionDatabaseSaveAs->setEnabled(true);
|
||||||
|
break;
|
||||||
|
case 1: // entry edit
|
||||||
|
case 2: // group edit
|
||||||
|
case 3: // change master key
|
||||||
|
m_ui->actionEntryNew->setEnabled(false);
|
||||||
|
m_ui->actionGroupNew->setEnabled(false);
|
||||||
|
m_ui->actionEntryEdit->setEnabled(false);
|
||||||
|
m_ui->actionGroupEdit->setEnabled(false);
|
||||||
|
m_ui->actionEntryDelete->setEnabled(false);
|
||||||
|
m_ui->actiocGroupDelete->setEnabled(false);
|
||||||
|
m_ui->actionChangeMasterKey->setEnabled(false);
|
||||||
|
m_ui->actionDatabaseSave->setEnabled(false);
|
||||||
|
m_ui->actionDatabaseSaveAs->setEnabled(false);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Q_ASSERT(false);
|
||||||
|
}
|
||||||
|
m_ui->actionDatabaseClose->setEnabled(true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_ui->actionEntryNew->setEnabled(false);
|
||||||
|
m_ui->actionGroupNew->setEnabled(false);
|
||||||
|
m_ui->actionEntryEdit->setEnabled(false);
|
||||||
|
m_ui->actionGroupEdit->setEnabled(false);
|
||||||
|
m_ui->actionEntryDelete->setEnabled(false);
|
||||||
|
m_ui->actiocGroupDelete->setEnabled(false);
|
||||||
|
m_ui->actionChangeMasterKey->setEnabled(false);
|
||||||
|
m_ui->actionDatabaseSave->setEnabled(false);
|
||||||
|
m_ui->actionDatabaseSaveAs->setEnabled(false);
|
||||||
|
|
||||||
|
m_ui->actionDatabaseClose->setEnabled(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::closeEvent(QCloseEvent *event) {
|
void MainWindow::closeEvent(QCloseEvent *event) {
|
||||||
@ -75,3 +134,5 @@ void MainWindow::closeEvent(QCloseEvent *event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,7 +36,8 @@ protected:
|
|||||||
void closeEvent(QCloseEvent *event);
|
void closeEvent(QCloseEvent *event);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void currentTabChanged(int index);
|
void setMenuActionState(int index = -1);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QScopedPointer<Ui::MainWindow> m_ui;
|
QScopedPointer<Ui::MainWindow> m_ui;
|
||||||
|
Loading…
Reference in New Issue
Block a user