mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Separated send menu filling to another method.
This commit is contained in:
parent
759e802eba
commit
a95a324401
2 changed files with 41 additions and 17 deletions
|
@ -686,6 +686,33 @@ void MessageLinksParser::apply(
|
||||||
_list = std::move(parsed);
|
_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(
|
void SetupSendMenuAndShortcuts(
|
||||||
not_null<Ui::RpWidget*> button,
|
not_null<Ui::RpWidget*> button,
|
||||||
Fn<SendMenuType()> type,
|
Fn<SendMenuType()> type,
|
||||||
|
@ -696,25 +723,12 @@ void SetupSendMenuAndShortcuts(
|
||||||
}
|
}
|
||||||
const auto menu = std::make_shared<base::unique_qptr<Ui::PopupMenu>>();
|
const auto menu = std::make_shared<base::unique_qptr<Ui::PopupMenu>>();
|
||||||
const auto showMenu = [=] {
|
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);
|
*menu = base::make_unique_q<Ui::PopupMenu>(button);
|
||||||
if (silent && now != SendMenuType::Reminder) {
|
const auto success = FillSendMenu(*menu, type, silent, schedule);
|
||||||
(*menu)->addAction(tr::lng_send_silent_message(tr::now), silent);
|
if (success) {
|
||||||
|
(*menu)->popup(QCursor::pos());
|
||||||
}
|
}
|
||||||
if (schedule && now != SendMenuType::SilentOnly) {
|
return success;
|
||||||
(*menu)->addAction(
|
|
||||||
(now == SendMenuType::Reminder
|
|
||||||
? tr::lng_reminder_message(tr::now)
|
|
||||||
: tr::lng_schedule_message(tr::now)),
|
|
||||||
schedule);
|
|
||||||
}
|
|
||||||
(*menu)->popup(QCursor::pos());
|
|
||||||
return true;
|
|
||||||
};
|
};
|
||||||
base::install_event_filter(button, [=](not_null<QEvent*> e) {
|
base::install_event_filter(button, [=](not_null<QEvent*> e) {
|
||||||
if (e->type() == QEvent::ContextMenu && showMenu()) {
|
if (e->type() == QEvent::ContextMenu && showMenu()) {
|
||||||
|
|
|
@ -26,6 +26,10 @@ namespace Window {
|
||||||
class SessionController;
|
class SessionController;
|
||||||
} // namespace Window
|
} // namespace Window
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class PopupMenu;
|
||||||
|
} // namespace Ui
|
||||||
|
|
||||||
QString PrepareMentionTag(not_null<UserData*> user);
|
QString PrepareMentionTag(not_null<UserData*> user);
|
||||||
TextWithTags PrepareEditText(not_null<HistoryItem*> item);
|
TextWithTags PrepareEditText(not_null<HistoryItem*> item);
|
||||||
|
|
||||||
|
@ -106,6 +110,12 @@ enum class SendMenuType {
|
||||||
Reminder,
|
Reminder,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool FillSendMenu(
|
||||||
|
not_null<Ui::PopupMenu*> menu,
|
||||||
|
Fn<SendMenuType()> type,
|
||||||
|
Fn<void()> silent,
|
||||||
|
Fn<void()> schedule);
|
||||||
|
|
||||||
void SetupSendMenuAndShortcuts(
|
void SetupSendMenuAndShortcuts(
|
||||||
not_null<Ui::RpWidget*> button,
|
not_null<Ui::RpWidget*> button,
|
||||||
Fn<SendMenuType()> type,
|
Fn<SendMenuType()> type,
|
||||||
|
|
Loading…
Add table
Reference in a new issue