2022-03-31 10:37:17 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "menu/add_action_callback_factory.h"
|
|
|
|
|
|
|
|
#include "menu/add_action_callback.h"
|
2022-04-04 14:15:45 +00:00
|
|
|
#include "ui/widgets/menu/menu_action.h"
|
2022-03-31 10:37:17 +00:00
|
|
|
#include "ui/widgets/popup_menu.h"
|
2022-04-04 14:15:45 +00:00
|
|
|
#include "styles/style_menu_icons.h"
|
2022-03-31 10:37:17 +00:00
|
|
|
|
|
|
|
namespace Menu {
|
|
|
|
|
|
|
|
MenuCallback CreateAddActionCallback(
|
|
|
|
const base::unique_qptr<Ui::PopupMenu> &menu) {
|
|
|
|
return MenuCallback([&](MenuCallback::Args a) {
|
|
|
|
if (a.fillSubmenu) {
|
|
|
|
const auto action = menu->addAction(
|
|
|
|
a.text,
|
|
|
|
std::move(a.handler),
|
|
|
|
a.icon);
|
|
|
|
// Dummy menu.
|
|
|
|
action->setMenu(Ui::CreateChild<QMenu>(menu->menu().get()));
|
|
|
|
a.fillSubmenu(menu->ensureSubmenu(action));
|
|
|
|
return action;
|
|
|
|
} else if (a.isSeparator) {
|
|
|
|
return menu->addSeparator();
|
2022-04-04 14:15:45 +00:00
|
|
|
} else if (a.isAttention) {
|
|
|
|
return menu->addAction(base::make_unique_q<Ui::Menu::Action>(
|
|
|
|
menu,
|
|
|
|
st::menuWithIconsAttention,
|
|
|
|
Ui::Menu::CreateAction(
|
|
|
|
menu->menu().get(),
|
|
|
|
a.text,
|
|
|
|
std::move(a.handler)),
|
|
|
|
a.icon,
|
|
|
|
a.icon));
|
2022-03-31 10:37:17 +00:00
|
|
|
}
|
|
|
|
return menu->addAction(a.text, std::move(a.handler), a.icon);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Menu
|