Commit 5a884b79 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Improve initial focus in Advanced Settings dialog

By default, the tab has input focus initially. That doesn't appear very
useful, in particular if there is only a single tab as for OpenPGP. So,
instead we focus the first checked (and enabled) key type radio button
or the first enabled check box or, as last resort, the OK button.

GnuPG-bug-id: 5832
parent 8c74a572
Pipeline #137866 passed with stage
in 3 minutes and 7 seconds
......@@ -700,6 +700,7 @@ private:
void loadDefaultGnuPGKeyType();
void loadDefaults();
void updateWidgetVisibility();
void setInitialFocus();
private:
GpgME::Protocol protocol;
......@@ -1894,6 +1895,7 @@ void AdvancedSettingsDialog::loadDefaults()
loadDefaultExpiration();
updateWidgetVisibility();
setInitialFocus();
}
void AdvancedSettingsDialog::updateWidgetVisibility()
......@@ -1983,4 +1985,45 @@ void AdvancedSettingsDialog::updateWidgetVisibility()
slotKeyMaterialSelectionChanged();
}
template<typename UnaryPredicate>
bool focusFirstButtonIf(const std::vector<QAbstractButton *> &buttons, UnaryPredicate p)
{
auto it = std::find_if(std::begin(buttons), std::end(buttons), p);
if (it != std::end(buttons)) {
(*it)->setFocus();
return true;
}
return false;
}
bool focusFirstCheckedButton(const std::vector<QAbstractButton *> &buttons)
{
return focusFirstButtonIf(buttons,
[](auto btn) {
return btn && btn->isEnabled() && btn->isChecked();
});
}
bool focusFirstEnabledButton(const std::vector<QAbstractButton *> &buttons)
{
return focusFirstButtonIf(buttons,
[](auto btn) {
return btn && btn->isEnabled();
});
}
void AdvancedSettingsDialog::setInitialFocus()
{
// first try the key type radio buttons
if (focusFirstCheckedButton({ui.rsaRB, ui.dsaRB, ui.ecdsaRB})) {
return;
}
// then try the usage check boxes and the expiration check box
if (focusFirstEnabledButton({ui.signingCB, ui.certificationCB, ui.encryptionCB, ui.authenticationCB, ui.expiryCB})) {
return;
}
// finally, focus the OK button
ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
}
#include "newcertificatewizard.moc"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment