mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Replaced Window::PeerMenuCallback with struct.
This commit is contained in:
parent
d8ee50c6fe
commit
c520cb777c
7 changed files with 56 additions and 46 deletions
|
@ -1771,6 +1771,10 @@ void InnerWidget::contextMenuEvent(QContextMenuEvent *e) {
|
|||
fillArchiveSearchMenu(_menu.get());
|
||||
}
|
||||
} else {
|
||||
const auto addAction = Window::PeerMenuCallback([&](
|
||||
Window::PeerMenuCallback::Args &&a) {
|
||||
return _menu->addAction(a.text, std::move(a.handler), a.icon);
|
||||
});
|
||||
Window::FillDialogsEntryMenu(
|
||||
_controller,
|
||||
Dialogs::EntryState{
|
||||
|
@ -1778,12 +1782,7 @@ void InnerWidget::contextMenuEvent(QContextMenuEvent *e) {
|
|||
.section = Dialogs::EntryState::Section::ChatsList,
|
||||
.filterId = _filterId,
|
||||
},
|
||||
[&](
|
||||
const QString &text,
|
||||
Fn<void()> callback,
|
||||
const style::icon *icon) {
|
||||
return _menu->addAction(text, std::move(callback), icon);
|
||||
});
|
||||
addAction);
|
||||
}
|
||||
QObject::connect(_menu.get(), &QObject::destroyed, [=] {
|
||||
if (_menuRow.key) {
|
||||
|
|
|
@ -315,12 +315,10 @@ void TopBarWidget::showPeerMenu() {
|
|||
if (!created) {
|
||||
return;
|
||||
}
|
||||
const auto addAction = [&](
|
||||
const QString &text,
|
||||
Fn<void()> callback,
|
||||
const style::icon *icon) {
|
||||
return _menu->addAction(text, std::move(callback), icon);
|
||||
};
|
||||
const auto addAction = Window::PeerMenuCallback([&](
|
||||
Window::PeerMenuCallback::Args a) {
|
||||
return _menu->addAction(a.text, std::move(a.handler), a.icon);
|
||||
});
|
||||
Window::FillDialogsEntryMenu(_controller, _activeChat, addAction);
|
||||
if (_menu->empty()) {
|
||||
_menu.destroy();
|
||||
|
|
|
@ -515,12 +515,10 @@ void WrapWidget::showTopBarMenu() {
|
|||
});
|
||||
_topBarMenuToggle->installEventFilter(_topBarMenu.get());
|
||||
|
||||
const auto addAction = [=](
|
||||
const QString &text,
|
||||
Fn<void()> callback,
|
||||
const style::icon *icon) {
|
||||
return _topBarMenu->addAction(text, std::move(callback), icon);
|
||||
};
|
||||
const auto addAction = Window::PeerMenuCallback([=](
|
||||
Window::PeerMenuCallback::Args a) {
|
||||
return _topBarMenu->addAction(a.text, std::move(a.handler), a.icon);
|
||||
});
|
||||
if (key().isDownloads()) {
|
||||
addAction(
|
||||
tr::lng_context_delete_all_files(tr::now),
|
||||
|
|
|
@ -546,15 +546,13 @@ void SetupAccountsWrap(
|
|||
} else if (which != Qt::RightButton) {
|
||||
return;
|
||||
}
|
||||
const auto addAction = [&](
|
||||
const QString &text,
|
||||
Fn<void()> callback,
|
||||
const style::icon *icon) {
|
||||
const auto addAction = Window::PeerMenuCallback([&](
|
||||
Window::PeerMenuCallback::Args args) {
|
||||
return state->menu->addAction(
|
||||
text,
|
||||
crl::guard(raw, std::move(callback)),
|
||||
icon);
|
||||
};
|
||||
args.text,
|
||||
crl::guard(raw, std::move(args.handler)),
|
||||
args.icon);
|
||||
});
|
||||
if (!state->menu && IsAltShift(raw->clickModifiers())) {
|
||||
state->menu = base::make_unique_q<Ui::PopupMenu>(
|
||||
raw,
|
||||
|
|
|
@ -310,15 +310,13 @@ void FiltersMenu::showMenu(QPoint position, FilterId id) {
|
|||
_popupMenu = base::make_unique_q<Ui::PopupMenu>(
|
||||
i->second.get(),
|
||||
st::popupMenuWithIcons);
|
||||
const auto addAction = [&](
|
||||
const QString &text,
|
||||
Fn<void()> callback,
|
||||
const style::icon *icon) {
|
||||
const auto addAction = Window::PeerMenuCallback([&](
|
||||
Window::PeerMenuCallback::Args args) {
|
||||
return _popupMenu->addAction(
|
||||
text,
|
||||
crl::guard(&_outer, std::move(callback)),
|
||||
icon);
|
||||
};
|
||||
args.text,
|
||||
crl::guard(&_outer, std::move(args.handler)),
|
||||
args.icon);
|
||||
});
|
||||
|
||||
addAction(
|
||||
tr::lng_filters_context_edit(tr::now),
|
||||
|
|
|
@ -475,15 +475,13 @@ void MainMenu::setupArchive() {
|
|||
_contextMenu = base::make_unique_q<Ui::PopupMenu>(
|
||||
this,
|
||||
st::popupMenuWithIcons);
|
||||
const auto addAction = [&](
|
||||
const QString &text,
|
||||
Fn<void()> callback,
|
||||
const style::icon *icon) {
|
||||
const auto addAction = PeerMenuCallback([&](
|
||||
PeerMenuCallback::Args a) {
|
||||
return _contextMenu->addAction(
|
||||
text,
|
||||
std::move(callback),
|
||||
icon);
|
||||
};
|
||||
a.text,
|
||||
std::move(a.handler),
|
||||
a.icon);
|
||||
});
|
||||
|
||||
const auto hide = [=] {
|
||||
controller->session().settings().setArchiveInMainMenu(false);
|
||||
|
|
|
@ -38,10 +38,31 @@ class SessionNavigation;
|
|||
|
||||
extern const char kOptionViewProfileInChatsListContextMenu[];
|
||||
|
||||
using PeerMenuCallback = Fn<QAction*(
|
||||
const QString &text,
|
||||
Fn<void()> handler,
|
||||
const style::icon *icon)>;
|
||||
struct PeerMenuCallback {
|
||||
public:
|
||||
struct Args {
|
||||
const QString &text;
|
||||
Fn<void()> handler;
|
||||
const style::icon *icon;
|
||||
};
|
||||
using Callback = Fn<QAction*(Args&&)>;
|
||||
|
||||
explicit PeerMenuCallback(Callback callback)
|
||||
: callback(std::move(callback)) {
|
||||
}
|
||||
|
||||
QAction *operator()(Args &&args) const {
|
||||
return callback(std::move(args));
|
||||
}
|
||||
QAction *operator()(
|
||||
const QString &text,
|
||||
Fn<void()> handler,
|
||||
const style::icon *icon) const {
|
||||
return callback({ text, std::move(handler), icon });
|
||||
}
|
||||
private:
|
||||
Callback callback;
|
||||
};
|
||||
|
||||
void FillDialogsEntryMenu(
|
||||
not_null<SessionController*> controller,
|
||||
|
|
Loading…
Add table
Reference in a new issue