From 4076b37378248ffcacddc8b3b722b4d61e0920bb Mon Sep 17 00:00:00 2001 From: thez3ro Date: Tue, 24 Oct 2017 19:23:55 +0200 Subject: [PATCH] disable the save button if there isn't anything to save --- src/gui/DatabaseTabWidget.cpp | 10 ++++++++++ src/gui/DatabaseTabWidget.h | 1 + src/gui/MainWindow.cpp | 3 ++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/gui/DatabaseTabWidget.cpp b/src/gui/DatabaseTabWidget.cpp index 4c9445ccc..8510279b5 100644 --- a/src/gui/DatabaseTabWidget.cpp +++ b/src/gui/DatabaseTabWidget.cpp @@ -539,6 +539,16 @@ bool DatabaseTabWidget::readOnly(int index) return indexDatabaseManagerStruct(index).readOnly; } +bool DatabaseTabWidget::canSave(int index) +{ + if (index == -1) { + index = currentIndex(); + } + + const DatabaseManagerStruct& dbStruct = indexDatabaseManagerStruct(index); + return !dbStruct.saveToFilename || (dbStruct.modified && !dbStruct.readOnly); +} + bool DatabaseTabWidget::isModified(int index) { if (index == -1) { diff --git a/src/gui/DatabaseTabWidget.h b/src/gui/DatabaseTabWidget.h index 847eaef05..db237d98c 100644 --- a/src/gui/DatabaseTabWidget.h +++ b/src/gui/DatabaseTabWidget.h @@ -78,6 +78,7 @@ public slots: void changeMasterKey(); void changeDatabaseSettings(); bool readOnly(int index = -1); + bool canSave(int index = -1); bool isModified(int index = -1); void performGlobalAutoType(); void lockDatabases(); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index e8a1728f0..c82ea1751 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -454,7 +454,7 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode) m_ui->actionGroupEmptyRecycleBin->setEnabled(recycleBinSelected); m_ui->actionChangeMasterKey->setEnabled(true); m_ui->actionChangeDatabaseSettings->setEnabled(true); - m_ui->actionDatabaseSave->setEnabled(true); + m_ui->actionDatabaseSave->setEnabled(m_ui->tabWidget->canSave()); m_ui->actionDatabaseSaveAs->setEnabled(true); m_ui->actionExportCsv->setEnabled(true); m_ui->actionDatabaseMerge->setEnabled(m_ui->tabWidget->currentIndex() != -1); @@ -560,6 +560,7 @@ void MainWindow::updateWindowTitle() if (m_ui->tabWidget->readOnly(tabWidgetIndex)) { customWindowTitlePart.append(QString(" [%1]").arg(tr("read-only"))); } + m_ui->actionDatabaseSave->setEnabled(m_ui->tabWidget->canSave(tabWidgetIndex)); } else if (stackedWidgetIndex == 1) { customWindowTitlePart = tr("Settings"); }