Returned Enter shortcut to confirm box.

This commit is contained in:
23rd 2022-03-08 12:12:34 +03:00
parent ffc0e04a1e
commit 2b8eefccca

View file

@ -42,13 +42,23 @@ void ConfirmBox(not_null<Ui::GenericBox*> box, ConfirmBoxArgs &&args) {
const auto &defaultButtonStyle = box->getDelegate()->style().button;
box->addButton(
const auto confirmButton = box->addButton(
v::text::take_plain(std::move(args.confirmText), tr::lng_box_ok()),
[=, c = prepareCallback(args.confirmed)]() {
lifetime->destroy();
c();
},
args.confirmStyle ? *args.confirmStyle : defaultButtonStyle);
box->events(
) | rpl::start_with_next([=](not_null<QEvent*> e) {
if ((e->type() != QEvent::KeyPress) || !confirmButton) {
return;
}
const auto k = static_cast<QKeyEvent*>(e.get());
if (k->key() == Qt::Key_Enter || k->key() == Qt::Key_Return) {
confirmButton->clicked(Qt::KeyboardModifiers(), Qt::LeftButton);
}
}, box->lifetime());
if (!args.inform) {
const auto cancelButton = box->addButton(