Refactored adding of sensitive menu items.

This commit is contained in:
23rd 2022-04-04 17:15:45 +03:00
parent 4754a513aa
commit 55864edb67
9 changed files with 60 additions and 36 deletions

View file

@ -21,6 +21,7 @@ public:
const style::icon *icon; const style::icon *icon;
Fn<void(not_null<Ui::PopupMenu*>)> fillSubmenu; Fn<void(not_null<Ui::PopupMenu*>)> fillSubmenu;
bool isSeparator = false; bool isSeparator = false;
bool isAttention = false;
}; };
using Callback = Fn<QAction*(Args&&)>; using Callback = Fn<QAction*(Args&&)>;

View file

@ -8,7 +8,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "menu/add_action_callback_factory.h" #include "menu/add_action_callback_factory.h"
#include "menu/add_action_callback.h" #include "menu/add_action_callback.h"
#include "ui/widgets/menu/menu_action.h"
#include "ui/widgets/popup_menu.h" #include "ui/widgets/popup_menu.h"
#include "styles/style_menu_icons.h"
namespace Menu { namespace Menu {
@ -26,6 +28,16 @@ MenuCallback CreateAddActionCallback(
return action; return action;
} else if (a.isSeparator) { } else if (a.isSeparator) {
return menu->addSeparator(); return menu->addSeparator();
} 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));
} }
return menu->addAction(a.text, std::move(a.handler), a.icon); return menu->addAction(a.text, std::move(a.handler), a.icon);
}); });

View file

@ -230,11 +230,12 @@ void FillTTLMenu(not_null<Ui::PopupMenu*> menu, Args args) {
&st::menuIconCustomize); &st::menuIconCustomize);
if (args.startTtl) { if (args.startTtl) {
const auto disable = menu->addAction( menu->addAction({
tr::lng_manage_messages_ttl_disable(tr::now), .text = tr::lng_manage_messages_ttl_disable(tr::now),
[=] { args.callback(0); }, .handler = [=] { args.callback(0); },
&st::menuIconDisableAttention); .icon = &st::menuIconDisableAttention,
disable->setData(st::menuIconAttentionColor->c); .isAttention = true,
});
} }
menu->addSeparator(); menu->addSeparator();

View file

@ -249,7 +249,7 @@ void FillMenu(
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
Type type, Type type,
Fn<void(Type)> showOther, Fn<void(Type)> showOther,
MenuCallback addAction) { Menu::MenuCallback addAction) {
const auto window = &controller->window(); const auto window = &controller->window();
if (type == Chat::Id()) { if (type == Chat::Id()) {
addAction( addAction(
@ -269,11 +269,12 @@ void FillMenu(
[=] { showOther(Information::Id()); }, [=] { showOther(Information::Id()); },
&st::menuIconInfo); &st::menuIconInfo);
} }
const auto logout = addAction( addAction({
tr::lng_settings_logout(tr::now), .text = tr::lng_settings_logout(tr::now),
[=] { window->showLogoutConfirmation(); }, .handler = [=] { window->showLogoutConfirmation(); },
&st::menuIconLeaveAttention); .icon = &st::menuIconLeaveAttention,
logout->setData(st::menuIconAttentionColor->c); .isAttention = true,
});
} }
} }

View file

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "menu/add_action_callback.h"
#include "ui/rp_widget.h" #include "ui/rp_widget.h"
#include "ui/round_rect.h" #include "ui/round_rect.h"
#include "base/object_ptr.h" #include "base/object_ptr.h"
@ -170,15 +171,10 @@ not_null<Ui::FlatLabel*> AddSubsectionTitle(
style::margins addPadding = {}, style::margins addPadding = {},
const style::FlatLabel *st = nullptr); const style::FlatLabel *st = nullptr);
using MenuCallback = Fn<QAction*(
const QString &text,
Fn<void()> handler,
const style::icon *icon)>;
void FillMenu( void FillMenu(
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
Type type, Type type,
Fn<void(Type)> showOther, Fn<void(Type)> showOther,
MenuCallback addAction); Menu::MenuCallback addAction);
} // namespace Settings } // namespace Settings

View file

@ -571,7 +571,8 @@ void SetupAccountsWrap(
addAction(tr::lng_menu_activate(tr::now), [=] { addAction(tr::lng_menu_activate(tr::now), [=] {
Core::App().domain().activate(&session->account()); Core::App().domain().activate(&session->account());
}, &st::menuIconProfile); }, &st::menuIconProfile);
const auto logout = addAction(tr::lng_settings_logout(tr::now), [=] {
auto logoutCallback = [=] {
const auto callback = [=](Fn<void()> &&close) { const auto callback = [=](Fn<void()> &&close) {
close(); close();
Core::App().logoutWithChecks(&session->account()); Core::App().logoutWithChecks(&session->account());
@ -584,8 +585,13 @@ void SetupAccountsWrap(
.confirmStyle = &st::attentionBoxButton, .confirmStyle = &st::attentionBoxButton,
}), }),
Ui::LayerOption::CloseOther); Ui::LayerOption::CloseOther);
}, &st::menuIconLeaveAttention); };
logout->setData(st::menuIconAttentionColor->c); addAction({
.text = tr::lng_settings_logout(tr::now),
.handler = std::move(logoutCallback),
.icon = &st::menuIconLeaveAttention,
.isAttention = true,
});
state->menu->popup(QCursor::pos()); state->menu->popup(QCursor::pos());
}, raw->lifetime()); }, raw->lifetime());

View file

@ -19,6 +19,10 @@ menuWithIcons: Menu(defaultMenu) {
arrow: menuIconSubmenuArrow; arrow: menuIconSubmenuArrow;
} }
menuWithIconsAttention: Menu(menuWithIcons) {
itemFg: attentionButtonFg;
itemFgOver: attentionButtonFgOver;
}
popupMenuWithIcons: PopupMenu(defaultPopupMenu) { popupMenuWithIcons: PopupMenu(defaultPopupMenu) {
scrollPadding: margins(0px, 5px, 0px, 5px); scrollPadding: margins(0px, 5px, 0px, 5px);
menu: menuWithIcons; menu: menuWithIcons;

View file

@ -510,13 +510,14 @@ void Filler::addDeleteChat() {
if (_peer->isChannel()) { if (_peer->isChannel()) {
return; return;
} }
const auto action = _addAction( _addAction({
(_peer->isUser() .text = (_peer->isUser()
? tr::lng_profile_delete_conversation(tr::now) ? tr::lng_profile_delete_conversation(tr::now)
: tr::lng_profile_clear_and_exit(tr::now)), : tr::lng_profile_clear_and_exit(tr::now)),
DeleteAndLeaveHandler(_controller, _peer), .handler = DeleteAndLeaveHandler(_controller, _peer),
&st::menuIconDeleteAttention); .icon = &st::menuIconDeleteAttention,
action->setData(st::menuIconAttentionColor->c); .isAttention = true,
});
} }
void Filler::addLeaveChat() { void Filler::addLeaveChat() {
@ -524,13 +525,14 @@ void Filler::addLeaveChat() {
if (!channel || !channel->amIn()) { if (!channel || !channel->amIn()) {
return; return;
} }
const auto leave = _addAction( _addAction({
(_peer->isMegagroup() .text = (_peer->isMegagroup()
? tr::lng_profile_leave_group(tr::now) ? tr::lng_profile_leave_group(tr::now)
: tr::lng_profile_leave_channel(tr::now)), : tr::lng_profile_leave_channel(tr::now)),
DeleteAndLeaveHandler(_controller, _peer), .handler = DeleteAndLeaveHandler(_controller, _peer),
&st::menuIconLeaveAttention); .icon = &st::menuIconLeaveAttention,
leave->setData(st::menuIconAttentionColor->c); .isAttention = true,
});
} }
void Filler::addBlockUser() { void Filler::addBlockUser() {
@ -706,11 +708,12 @@ void Filler::addDeleteContact() {
return; return;
} }
const auto controller = _controller; const auto controller = _controller;
const auto action = _addAction( _addAction({
tr::lng_info_delete_contact(tr::now), .text = tr::lng_info_delete_contact(tr::now),
[=] { PeerMenuDeleteContact(controller, user); }, .handler = [=] { PeerMenuDeleteContact(controller, user); },
&st::menuIconDeleteAttention); .icon = &st::menuIconDeleteAttention,
action->setData(st::menuIconAttentionColor->c); .isAttention = true,
});
} }
void Filler::addManageChat() { void Filler::addManageChat() {

@ -1 +1 @@
Subproject commit 8d181e53c573639d8a4a7e66e89bc01791b0572b Subproject commit 1c14306abab06a8c66ce25ac1fbe783f745eff39