diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 263a265f7..f549b2005 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -1787,8 +1787,8 @@ bool DatabaseWidget::focusNextPrevChild(bool next) bool DatabaseWidget::lock() { - if (isLocked()) { - return true; + if (isLocked() || m_attemptingLock) { + return isLocked(); } // Don't try to lock the database while saving, this will cause a deadlock @@ -1797,6 +1797,8 @@ bool DatabaseWidget::lock() return false; } + m_attemptingLock = true; + emit databaseLockRequested(); // Force close any modal widgets associated with this widget @@ -1821,6 +1823,7 @@ bool DatabaseWidget::lock() MessageBox::Discard | MessageBox::Cancel, MessageBox::Cancel); if (result == MessageBox::Cancel) { + m_attemptingLock = false; return false; } } @@ -1847,9 +1850,11 @@ bool DatabaseWidget::lock() MessageBox::Save); if (result == MessageBox::Save) { if (!save()) { + m_attemptingLock = false; return false; } } else if (result == MessageBox::Cancel) { + m_attemptingLock = false; return false; } } @@ -1881,6 +1886,7 @@ bool DatabaseWidget::lock() auto newDb = QSharedPointer::create(m_db->filePath()); replaceDatabase(newDb); + m_attemptingLock = false; emit databaseLocked(); return true; diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index 4e564ea2f..dbee174ec 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -305,6 +305,7 @@ private: QUuid m_entryBeforeLock; int m_saveAttempts; + bool m_attemptingLock = false; // Search state QScopedPointer m_entrySearcher;