Added Enter shortcut to box for adding or removing of shared filter.

This commit is contained in:
23rd 2024-12-03 00:49:54 +03:00 committed by John Preston
parent b6fb3bbf1d
commit fe7c06bc84

View file

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "api/api_chat_filters.h"
#include "apiwrap.h"
#include "base/event_filter.h"
#include "boxes/peer_list_box.h"
#include "boxes/premium_limits_box.h"
#include "boxes/filters/edit_filter_links.h" // FilterChatStatusText
@ -548,6 +549,26 @@ void ShowImportToast(
strong->showToast(std::move(text));
}
void HandleEnterInBox(not_null<Ui::BoxContent*> box) {
const auto isEnter = [=](not_null<QEvent*> event) {
if (event->type() == QEvent::KeyPress) {
if (const auto k = static_cast<QKeyEvent*>(event.get())) {
return (k->key() == Qt::Key_Enter)
|| (k->key() == Qt::Key_Return);
}
}
return false;
};
base::install_event_filter(box, [=](not_null<QEvent*> event) {
if (isEnter(event)) {
box->triggerButton(0);
return base::EventFilterResult::Cancel;
}
return base::EventFilterResult::Continue;
});
}
void ProcessFilterInvite(
base::weak_ptr<Window::SessionController> weak,
const QString &slug,
@ -610,6 +631,8 @@ void ProcessFilterInvite(
box->addButton(std::move(owned));
HandleEnterInBox(box);
struct State {
bool importing = false;
};
@ -829,6 +852,8 @@ void ProcessFilterRemove(
box->addButton(std::move(owned));
HandleEnterInBox(box);
raw->selectedValue(
) | rpl::start_with_next([=](
base::flat_set<not_null<PeerData*>> &&peers) {