mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-04-04 13:07:38 +03:00
Add a context menu entry to delete entries from health check reports (#6537)
* Closes #4986 - Allow deleting entries from the reports view * Closes #4533 - Exclude & delete multiple entries in a report * Also allow deleting selected entries using the delete key * Introduce GuiTools namespace to collect shared GUI prompts and actions * Add functionality to HIBP report to mirror health check report Co-authored-by: Jonathan White <support@dmapps.us>
This commit is contained in:
parent
1f50ac6045
commit
6acd0b25ae
11 changed files with 307 additions and 169 deletions
|
@ -50,6 +50,7 @@
|
|||
#include "gui/DatabaseOpenWidget.h"
|
||||
#include "gui/EntryPreviewWidget.h"
|
||||
#include "gui/FileDialog.h"
|
||||
#include "gui/GuiTools.h"
|
||||
#include "gui/KeePass1OpenWidget.h"
|
||||
#include "gui/MainWindow.h"
|
||||
#include "gui/MessageBox.h"
|
||||
|
@ -487,57 +488,11 @@ void DatabaseWidget::deleteEntries(QList<Entry*> selectedEntries, bool confirm)
|
|||
bool permanent = (recycleBin && recycleBin->findEntryByUuid(selectedEntries.first()->uuid()))
|
||||
|| !m_db->metadata()->recycleBinEnabled();
|
||||
|
||||
if (confirm && !confirmDeleteEntries(selectedEntries, permanent)) {
|
||||
if (confirm && !GuiTools::confirmDeleteEntries(this, selectedEntries, permanent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Find references to selected entries and prompt for direction if necessary
|
||||
auto it = selectedEntries.begin();
|
||||
while (confirm && it != selectedEntries.end()) {
|
||||
auto references = m_db->rootGroup()->referencesRecursive(*it);
|
||||
if (!references.isEmpty()) {
|
||||
// Ignore references that are selected for deletion
|
||||
for (auto* entry : selectedEntries) {
|
||||
references.removeAll(entry);
|
||||
}
|
||||
|
||||
if (!references.isEmpty()) {
|
||||
// Prompt for reference handling
|
||||
auto result = MessageBox::question(
|
||||
this,
|
||||
tr("Replace references to entry?"),
|
||||
tr("Entry \"%1\" has %2 reference(s). "
|
||||
"Do you want to overwrite references with values, skip this entry, or delete anyway?",
|
||||
"",
|
||||
references.size())
|
||||
.arg((*it)->title().toHtmlEscaped())
|
||||
.arg(references.size()),
|
||||
MessageBox::Overwrite | MessageBox::Skip | MessageBox::Delete,
|
||||
MessageBox::Overwrite);
|
||||
|
||||
if (result == MessageBox::Overwrite) {
|
||||
for (auto* entry : references) {
|
||||
entry->replaceReferencesWithValues(*it);
|
||||
}
|
||||
} else if (result == MessageBox::Skip) {
|
||||
it = selectedEntries.erase(it);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
it++;
|
||||
}
|
||||
|
||||
if (permanent) {
|
||||
for (auto* entry : asConst(selectedEntries)) {
|
||||
delete entry;
|
||||
}
|
||||
} else {
|
||||
for (auto* entry : asConst(selectedEntries)) {
|
||||
m_db->recycleEntry(entry);
|
||||
}
|
||||
}
|
||||
GuiTools::deleteEntriesResolveReferences(this, selectedEntries, permanent);
|
||||
|
||||
refreshSearch();
|
||||
|
||||
|
@ -550,49 +505,6 @@ void DatabaseWidget::deleteEntries(QList<Entry*> selectedEntries, bool confirm)
|
|||
}
|
||||
}
|
||||
|
||||
bool DatabaseWidget::confirmDeleteEntries(QList<Entry*> entries, bool permanent)
|
||||
{
|
||||
if (entries.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (permanent) {
|
||||
QString prompt;
|
||||
if (entries.size() == 1) {
|
||||
prompt = tr("Do you really want to delete the entry \"%1\" for good?")
|
||||
.arg(entries.first()->title().toHtmlEscaped());
|
||||
} else {
|
||||
prompt = tr("Do you really want to delete %n entry(s) for good?", "", entries.size());
|
||||
}
|
||||
|
||||
auto answer = MessageBox::question(this,
|
||||
tr("Delete entry(s)?", "", entries.size()),
|
||||
prompt,
|
||||
MessageBox::Delete | MessageBox::Cancel,
|
||||
MessageBox::Cancel);
|
||||
|
||||
return answer == MessageBox::Delete;
|
||||
} else if (config()->get(Config::Security_NoConfirmMoveEntryToRecycleBin).toBool()) {
|
||||
return true;
|
||||
} else {
|
||||
QString prompt;
|
||||
if (entries.size() == 1) {
|
||||
prompt = tr("Do you really want to move entry \"%1\" to the recycle bin?")
|
||||
.arg(entries.first()->title().toHtmlEscaped());
|
||||
} else {
|
||||
prompt = tr("Do you really want to move %n entry(s) to the recycle bin?", "", entries.size());
|
||||
}
|
||||
|
||||
auto answer = MessageBox::question(this,
|
||||
tr("Move entry(s) to recycle bin?", "", entries.size()),
|
||||
prompt,
|
||||
MessageBox::Move | MessageBox::Cancel,
|
||||
MessageBox::Cancel);
|
||||
|
||||
return answer == MessageBox::Move;
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseWidget::setFocus(Qt::FocusReason reason)
|
||||
{
|
||||
if (reason == Qt::BacktabFocusReason) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue