Skip to content

Commit b9bcbfc

Browse files
Jesssullivandroidmonkey
authored andcommitted
Fix: address #12631
1 parent 80c2ad7 commit b9bcbfc

3 files changed

Lines changed: 74 additions & 0 deletions

File tree

src/gui/DatabaseWidget.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,11 @@ void DatabaseWidget::expireSelectedEntries()
585585

586586
void DatabaseWidget::deleteSelectedEntries()
587587
{
588+
// Prevent deletion when a modal dialog (e.g., file save dialog) is active
589+
if (QApplication::activeModalWidget()) {
590+
return;
591+
}
592+
588593
const QModelIndexList selected = m_entryView->selectionModel()->selectedRows();
589594
if (selected.isEmpty()) {
590595
return;
@@ -1100,6 +1105,11 @@ void DatabaseWidget::cloneGroup()
11001105

11011106
void DatabaseWidget::deleteGroup()
11021107
{
1108+
// Prevent deletion when a modal dialog is active
1109+
if (QApplication::activeModalWidget()) {
1110+
return;
1111+
}
1112+
11031113
Group* currentGroup = m_groupView->currentGroup();
11041114
Q_ASSERT(currentGroup && canDeleteCurrentGroup());
11051115
if (!currentGroup || !canDeleteCurrentGroup()) {

tests/gui/TestGui.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <QCheckBox>
2323
#include <QClipboard>
24+
#include <QDialog>
2425
#include <QListWidget>
2526
#include <QMenu>
2627
#include <QMenuBar>
@@ -2504,6 +2505,68 @@ void TestGui::testMenuActionStates()
25042505
QVERIFY(isActionEnabled("actionPasswordGenerator"));
25052506
}
25062507

2508+
void TestGui::testDeleteEntryDuringModalDialog()
2509+
{
2510+
// Delete key in native file dialogs on macOS
2511+
// should not delete password entries
2512+
2513+
// Add canned entries for consistent testing
2514+
addCannedEntries();
2515+
2516+
auto* entryView = m_dbWidget->findChild<EntryView*>("entryView");
2517+
auto* entryDeleteAction = m_mainWindow->findChild<QAction*>("actionEntryDelete");
2518+
2519+
// Count initial entries
2520+
int initialEntryCount = entryView->model()->rowCount();
2521+
QVERIFY(initialEntryCount > 0);
2522+
2523+
// Select the first entry
2524+
clickIndex(entryView->model()->index(0, 1), entryView, Qt::LeftButton);
2525+
entryView->setFocus();
2526+
QApplication::processEvents();
2527+
2528+
// Create and show a modal dialog to simulate the file save dialog
2529+
QDialog modalDialog(m_mainWindow.data());
2530+
modalDialog.setModal(true);
2531+
2532+
// Use a timer to trigger the delete action while modal dialog is shown
2533+
bool deleteTriggered = false;
2534+
QTimer::singleShot(50, [&]() {
2535+
// Verify modal dialog is active
2536+
QVERIFY(QApplication::activeModalWidget() == &modalDialog);
2537+
2538+
// Trigger delete action while modal is open
2539+
entryDeleteAction->trigger();
2540+
deleteTriggered = true;
2541+
2542+
// Close the modal dialog
2543+
modalDialog.accept();
2544+
});
2545+
2546+
// Show modal dialog (blocks until closed)
2547+
modalDialog.exec();
2548+
2549+
QVERIFY(deleteTriggered);
2550+
QApplication::processEvents();
2551+
2552+
// Verify entry count unchanged - delete should have been blocked
2553+
QCOMPARE(entryView->model()->rowCount(), initialEntryCount);
2554+
2555+
// Now verify normal deletion still works after modal closes
2556+
clickIndex(entryView->model()->index(0, 1), entryView, Qt::LeftButton);
2557+
entryView->setFocus();
2558+
QApplication::processEvents();
2559+
2560+
if (!config()->get(Config::Security_NoConfirmMoveEntryToRecycleBin).toBool()) {
2561+
MessageBox::setNextAnswer(MessageBox::Move);
2562+
}
2563+
entryDeleteAction->trigger();
2564+
QApplication::processEvents();
2565+
2566+
// Verify entry was deleted normally
2567+
QCOMPARE(entryView->model()->rowCount(), initialEntryCount - 1);
2568+
}
2569+
25072570
void TestGui::addCannedEntries()
25082571
{
25092572
// Find buttons

tests/gui/TestGui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ private slots:
7171
void testTrayRestoreHide();
7272
void testShortcutConfig();
7373
void testMenuActionStates();
74+
void testDeleteEntryDuringModalDialog();
7475

7576
private:
7677
void addCannedEntries();

0 commit comments

Comments
 (0)