mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-02-23 08:46:55 +00:00
Separated send menu filling to another method.
This commit is contained in:
parent
759e802eba
commit
a95a324401
@ -686,6 +686,33 @@ void MessageLinksParser::apply(
|
||||
_list = std::move(parsed);
|
||||
}
|
||||
|
||||
bool FillSendMenu(
|
||||
not_null<Ui::PopupMenu*> menu,
|
||||
Fn<SendMenuType()> type,
|
||||
Fn<void()> silent,
|
||||
Fn<void()> schedule) {
|
||||
if (!silent && !schedule) {
|
||||
return false;
|
||||
}
|
||||
const auto now = type();
|
||||
if (now == SendMenuType::Disabled
|
||||
|| (!silent && now == SendMenuType::SilentOnly)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (silent && now != SendMenuType::Reminder) {
|
||||
menu->addAction(tr::lng_send_silent_message(tr::now), silent);
|
||||
}
|
||||
if (schedule && now != SendMenuType::SilentOnly) {
|
||||
menu->addAction(
|
||||
(now == SendMenuType::Reminder
|
||||
? tr::lng_reminder_message(tr::now)
|
||||
: tr::lng_schedule_message(tr::now)),
|
||||
schedule);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void SetupSendMenuAndShortcuts(
|
||||
not_null<Ui::RpWidget*> button,
|
||||
Fn<SendMenuType()> type,
|
||||
@ -696,25 +723,12 @@ void SetupSendMenuAndShortcuts(
|
||||
}
|
||||
const auto menu = std::make_shared<base::unique_qptr<Ui::PopupMenu>>();
|
||||
const auto showMenu = [=] {
|
||||
const auto now = type();
|
||||
if (now == SendMenuType::Disabled
|
||||
|| (!silent && now == SendMenuType::SilentOnly)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*menu = base::make_unique_q<Ui::PopupMenu>(button);
|
||||
if (silent && now != SendMenuType::Reminder) {
|
||||
(*menu)->addAction(tr::lng_send_silent_message(tr::now), silent);
|
||||
const auto success = FillSendMenu(*menu, type, silent, schedule);
|
||||
if (success) {
|
||||
(*menu)->popup(QCursor::pos());
|
||||
}
|
||||
if (schedule && now != SendMenuType::SilentOnly) {
|
||||
(*menu)->addAction(
|
||||
(now == SendMenuType::Reminder
|
||||
? tr::lng_reminder_message(tr::now)
|
||||
: tr::lng_schedule_message(tr::now)),
|
||||
schedule);
|
||||
}
|
||||
(*menu)->popup(QCursor::pos());
|
||||
return true;
|
||||
return success;
|
||||
};
|
||||
base::install_event_filter(button, [=](not_null<QEvent*> e) {
|
||||
if (e->type() == QEvent::ContextMenu && showMenu()) {
|
||||
|
@ -26,6 +26,10 @@ namespace Window {
|
||||
class SessionController;
|
||||
} // namespace Window
|
||||
|
||||
namespace Ui {
|
||||
class PopupMenu;
|
||||
} // namespace Ui
|
||||
|
||||
QString PrepareMentionTag(not_null<UserData*> user);
|
||||
TextWithTags PrepareEditText(not_null<HistoryItem*> item);
|
||||
|
||||
@ -106,6 +110,12 @@ enum class SendMenuType {
|
||||
Reminder,
|
||||
};
|
||||
|
||||
bool FillSendMenu(
|
||||
not_null<Ui::PopupMenu*> menu,
|
||||
Fn<SendMenuType()> type,
|
||||
Fn<void()> silent,
|
||||
Fn<void()> schedule);
|
||||
|
||||
void SetupSendMenuAndShortcuts(
|
||||
not_null<Ui::RpWidget*> button,
|
||||
Fn<SendMenuType()> type,
|
||||
|
Loading…
Reference in New Issue
Block a user