mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 22:54:01 +02:00
Refactored adding of sensitive menu items.
This commit is contained in:
parent
4754a513aa
commit
55864edb67
9 changed files with 60 additions and 36 deletions
|
@ -21,6 +21,7 @@ public:
|
|||
const style::icon *icon;
|
||||
Fn<void(not_null<Ui::PopupMenu*>)> fillSubmenu;
|
||||
bool isSeparator = false;
|
||||
bool isAttention = false;
|
||||
};
|
||||
using Callback = Fn<QAction*(Args&&)>;
|
||||
|
||||
|
|
|
@ -8,7 +8,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "menu/add_action_callback_factory.h"
|
||||
|
||||
#include "menu/add_action_callback.h"
|
||||
#include "ui/widgets/menu/menu_action.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
#include "styles/style_menu_icons.h"
|
||||
|
||||
namespace Menu {
|
||||
|
||||
|
@ -26,6 +28,16 @@ MenuCallback CreateAddActionCallback(
|
|||
return action;
|
||||
} else if (a.isSeparator) {
|
||||
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);
|
||||
});
|
||||
|
|
|
@ -230,11 +230,12 @@ void FillTTLMenu(not_null<Ui::PopupMenu*> menu, Args args) {
|
|||
&st::menuIconCustomize);
|
||||
|
||||
if (args.startTtl) {
|
||||
const auto disable = menu->addAction(
|
||||
tr::lng_manage_messages_ttl_disable(tr::now),
|
||||
[=] { args.callback(0); },
|
||||
&st::menuIconDisableAttention);
|
||||
disable->setData(st::menuIconAttentionColor->c);
|
||||
menu->addAction({
|
||||
.text = tr::lng_manage_messages_ttl_disable(tr::now),
|
||||
.handler = [=] { args.callback(0); },
|
||||
.icon = &st::menuIconDisableAttention,
|
||||
.isAttention = true,
|
||||
});
|
||||
}
|
||||
|
||||
menu->addSeparator();
|
||||
|
|
|
@ -249,7 +249,7 @@ void FillMenu(
|
|||
not_null<Window::SessionController*> controller,
|
||||
Type type,
|
||||
Fn<void(Type)> showOther,
|
||||
MenuCallback addAction) {
|
||||
Menu::MenuCallback addAction) {
|
||||
const auto window = &controller->window();
|
||||
if (type == Chat::Id()) {
|
||||
addAction(
|
||||
|
@ -269,11 +269,12 @@ void FillMenu(
|
|||
[=] { showOther(Information::Id()); },
|
||||
&st::menuIconInfo);
|
||||
}
|
||||
const auto logout = addAction(
|
||||
tr::lng_settings_logout(tr::now),
|
||||
[=] { window->showLogoutConfirmation(); },
|
||||
&st::menuIconLeaveAttention);
|
||||
logout->setData(st::menuIconAttentionColor->c);
|
||||
addAction({
|
||||
.text = tr::lng_settings_logout(tr::now),
|
||||
.handler = [=] { window->showLogoutConfirmation(); },
|
||||
.icon = &st::menuIconLeaveAttention,
|
||||
.isAttention = true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
#include "menu/add_action_callback.h"
|
||||
#include "ui/rp_widget.h"
|
||||
#include "ui/round_rect.h"
|
||||
#include "base/object_ptr.h"
|
||||
|
@ -170,15 +171,10 @@ not_null<Ui::FlatLabel*> AddSubsectionTitle(
|
|||
style::margins addPadding = {},
|
||||
const style::FlatLabel *st = nullptr);
|
||||
|
||||
using MenuCallback = Fn<QAction*(
|
||||
const QString &text,
|
||||
Fn<void()> handler,
|
||||
const style::icon *icon)>;
|
||||
|
||||
void FillMenu(
|
||||
not_null<Window::SessionController*> controller,
|
||||
Type type,
|
||||
Fn<void(Type)> showOther,
|
||||
MenuCallback addAction);
|
||||
Menu::MenuCallback addAction);
|
||||
|
||||
} // namespace Settings
|
||||
|
|
|
@ -571,7 +571,8 @@ void SetupAccountsWrap(
|
|||
addAction(tr::lng_menu_activate(tr::now), [=] {
|
||||
Core::App().domain().activate(&session->account());
|
||||
}, &st::menuIconProfile);
|
||||
const auto logout = addAction(tr::lng_settings_logout(tr::now), [=] {
|
||||
|
||||
auto logoutCallback = [=] {
|
||||
const auto callback = [=](Fn<void()> &&close) {
|
||||
close();
|
||||
Core::App().logoutWithChecks(&session->account());
|
||||
|
@ -584,8 +585,13 @@ void SetupAccountsWrap(
|
|||
.confirmStyle = &st::attentionBoxButton,
|
||||
}),
|
||||
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());
|
||||
}, raw->lifetime());
|
||||
|
||||
|
|
|
@ -19,6 +19,10 @@ menuWithIcons: Menu(defaultMenu) {
|
|||
|
||||
arrow: menuIconSubmenuArrow;
|
||||
}
|
||||
menuWithIconsAttention: Menu(menuWithIcons) {
|
||||
itemFg: attentionButtonFg;
|
||||
itemFgOver: attentionButtonFgOver;
|
||||
}
|
||||
popupMenuWithIcons: PopupMenu(defaultPopupMenu) {
|
||||
scrollPadding: margins(0px, 5px, 0px, 5px);
|
||||
menu: menuWithIcons;
|
||||
|
|
|
@ -510,13 +510,14 @@ void Filler::addDeleteChat() {
|
|||
if (_peer->isChannel()) {
|
||||
return;
|
||||
}
|
||||
const auto action = _addAction(
|
||||
(_peer->isUser()
|
||||
_addAction({
|
||||
.text = (_peer->isUser()
|
||||
? tr::lng_profile_delete_conversation(tr::now)
|
||||
: tr::lng_profile_clear_and_exit(tr::now)),
|
||||
DeleteAndLeaveHandler(_controller, _peer),
|
||||
&st::menuIconDeleteAttention);
|
||||
action->setData(st::menuIconAttentionColor->c);
|
||||
.handler = DeleteAndLeaveHandler(_controller, _peer),
|
||||
.icon = &st::menuIconDeleteAttention,
|
||||
.isAttention = true,
|
||||
});
|
||||
}
|
||||
|
||||
void Filler::addLeaveChat() {
|
||||
|
@ -524,13 +525,14 @@ void Filler::addLeaveChat() {
|
|||
if (!channel || !channel->amIn()) {
|
||||
return;
|
||||
}
|
||||
const auto leave = _addAction(
|
||||
(_peer->isMegagroup()
|
||||
_addAction({
|
||||
.text = (_peer->isMegagroup()
|
||||
? tr::lng_profile_leave_group(tr::now)
|
||||
: tr::lng_profile_leave_channel(tr::now)),
|
||||
DeleteAndLeaveHandler(_controller, _peer),
|
||||
&st::menuIconLeaveAttention);
|
||||
leave->setData(st::menuIconAttentionColor->c);
|
||||
.handler = DeleteAndLeaveHandler(_controller, _peer),
|
||||
.icon = &st::menuIconLeaveAttention,
|
||||
.isAttention = true,
|
||||
});
|
||||
}
|
||||
|
||||
void Filler::addBlockUser() {
|
||||
|
@ -706,11 +708,12 @@ void Filler::addDeleteContact() {
|
|||
return;
|
||||
}
|
||||
const auto controller = _controller;
|
||||
const auto action = _addAction(
|
||||
tr::lng_info_delete_contact(tr::now),
|
||||
[=] { PeerMenuDeleteContact(controller, user); },
|
||||
&st::menuIconDeleteAttention);
|
||||
action->setData(st::menuIconAttentionColor->c);
|
||||
_addAction({
|
||||
.text = tr::lng_info_delete_contact(tr::now),
|
||||
.handler = [=] { PeerMenuDeleteContact(controller, user); },
|
||||
.icon = &st::menuIconDeleteAttention,
|
||||
.isAttention = true,
|
||||
});
|
||||
}
|
||||
|
||||
void Filler::addManageChat() {
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 8d181e53c573639d8a4a7e66e89bc01791b0572b
|
||||
Subproject commit 1c14306abab06a8c66ce25ac1fbe783f745eff39
|
Loading…
Add table
Reference in a new issue