Customize buttons on MessageBox and confirm before recycling (#2376)

* Add confirmation prompt before moving groups to the recycling bin

Spawn a yes/no QMessage box when "Delete Group" is selected on a group
that is not already in the recycle bin (note: the prompt for deletion
from the recycle bin was already implemented).  This follows the same
pattern and language as entry deletion.

Fixes #2125

* Make prompts for destructive operations use action words on buttons

Replace yes/no, yes/cancel (and other such buttons on prompts that cause
data to be destroyed) use language that indicates the action that it is
going to take. This makes destructive/unsafe and/or irreversible operations
more clear to the user.

Address feedback on PR #2376

* Refactor MessageBox class to allow for custom buttons

Replaces arguments and return values of type QMessageBox::StandardButton(s)
with MessageBox::Button(s), which reimplements the entire set of
QMessageBox::StandardButton and allows for custom KeePassXC buttons,
such as "Skip". Modifies all calls to MessageBox functions to use
MessageBox::Button(s).

Addresses feedback on #2376

* Remove MessageBox::addButton in favor of map lookup

Replaced the switch statement mechanism in MessageBox::addButton with
a map lookup to address CodeFactor Complex Method issue. This has a
side-effect of a small performance/cleanliness increase, as an
extra QPushButton is no longer created/destroyed (to obtain it's label
text) everytime a MessageBox button based on QMessageBox::StandardButton
is created; now the text is obtained once, at application start up.
This commit is contained in:
Kyle Kneitinger 2018-12-19 20:14:11 -08:00 committed by Jonathan White
parent 8ac9d0a131
commit 4d4c839afa
15 changed files with 400 additions and 232 deletions

View file

@ -821,9 +821,9 @@ bool EditEntryWidget::commitEntry()
auto answer = MessageBox::question(this,
tr("Apply generated password?"),
tr("Do you want to apply the generated password to this entry?"),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes);
if (answer == QMessageBox::Yes) {
MessageBox::Yes | MessageBox::No,
MessageBox::Yes);
if (answer == MessageBox::Yes) {
m_mainUi->passwordGenerator->applyPassword();
}
}
@ -947,13 +947,13 @@ void EditEntryWidget::cancel()
auto result = MessageBox::question(this,
QString(),
tr("Entry has unsaved changes"),
QMessageBox::Cancel | QMessageBox::Save | QMessageBox::Discard,
QMessageBox::Cancel);
if (result == QMessageBox::Cancel) {
MessageBox::Cancel | MessageBox::Save | MessageBox::Discard,
MessageBox::Cancel);
if (result == MessageBox::Cancel) {
m_mainUi->passwordGenerator->reset();
return;
}
if (result == QMessageBox::Save) {
if (result == MessageBox::Save) {
commitEntry();
m_saved = true;
}
@ -1058,11 +1058,14 @@ void EditEntryWidget::removeCurrentAttribute()
QModelIndex index = m_advancedUi->attributesView->currentIndex();
if (index.isValid()) {
if (MessageBox::question(this,
tr("Confirm Remove"),
tr("Are you sure you want to remove this attribute?"),
QMessageBox::Yes | QMessageBox::No)
== QMessageBox::Yes) {
auto result = MessageBox::question(this,
tr("Confirm Removal"),
tr("Are you sure you want to remove this attribute?"),
MessageBox::Remove | MessageBox::Cancel,
MessageBox::Cancel);
if (result == MessageBox::Remove) {
m_entryAttributes->remove(m_attributesModel->keyByIndex(index));
setUnsavedChanges(true);
}