mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-07-26 07:23:02 +02:00
Added submenu support to Window::PeerMenuCallback.
This commit is contained in:
parent
77659c64e0
commit
4bcd9de2b0
3 changed files with 29 additions and 3 deletions
|
@ -1773,6 +1773,18 @@ void InnerWidget::contextMenuEvent(QContextMenuEvent *e) {
|
||||||
} else {
|
} else {
|
||||||
const auto addAction = Window::PeerMenuCallback([&](
|
const auto addAction = Window::PeerMenuCallback([&](
|
||||||
Window::PeerMenuCallback::Args &&a) {
|
Window::PeerMenuCallback::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();
|
||||||
|
}
|
||||||
return _menu->addAction(a.text, std::move(a.handler), a.icon);
|
return _menu->addAction(a.text, std::move(a.handler), a.icon);
|
||||||
});
|
});
|
||||||
Window::FillDialogsEntryMenu(
|
Window::FillDialogsEntryMenu(
|
||||||
|
|
|
@ -283,7 +283,7 @@ bool TopBarWidget::createMenu(not_null<Ui::IconButton*> button) {
|
||||||
if (!_activeChat.key || _menu) {
|
if (!_activeChat.key || _menu) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_menu.create(this, st::popupMenuWithIcons);
|
_menu.create(this, st::popupMenuExpandedSeparator);
|
||||||
_menu->setDestroyedCallback([
|
_menu->setDestroyedCallback([
|
||||||
weak = Ui::MakeWeak(this),
|
weak = Ui::MakeWeak(this),
|
||||||
weakButton = Ui::MakeWeak(button),
|
weakButton = Ui::MakeWeak(button),
|
||||||
|
@ -307,6 +307,18 @@ void TopBarWidget::showPeerMenu() {
|
||||||
}
|
}
|
||||||
const auto addAction = Window::PeerMenuCallback([&](
|
const auto addAction = Window::PeerMenuCallback([&](
|
||||||
Window::PeerMenuCallback::Args a) {
|
Window::PeerMenuCallback::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();
|
||||||
|
}
|
||||||
return _menu->addAction(a.text, std::move(a.handler), a.icon);
|
return _menu->addAction(a.text, std::move(a.handler), a.icon);
|
||||||
});
|
});
|
||||||
Window::FillDialogsEntryMenu(_controller, _activeChat, addAction);
|
Window::FillDialogsEntryMenu(_controller, _activeChat, addAction);
|
||||||
|
|
|
@ -41,9 +41,11 @@ extern const char kOptionViewProfileInChatsListContextMenu[];
|
||||||
struct PeerMenuCallback {
|
struct PeerMenuCallback {
|
||||||
public:
|
public:
|
||||||
struct Args {
|
struct Args {
|
||||||
const QString &text;
|
QString text;
|
||||||
Fn<void()> handler;
|
Fn<void()> handler;
|
||||||
const style::icon *icon;
|
const style::icon *icon;
|
||||||
|
Fn<void(not_null<Ui::PopupMenu*>)> fillSubmenu;
|
||||||
|
bool isSeparator = false;
|
||||||
};
|
};
|
||||||
using Callback = Fn<QAction*(Args&&)>;
|
using Callback = Fn<QAction*(Args&&)>;
|
||||||
|
|
||||||
|
@ -58,7 +60,7 @@ public:
|
||||||
const QString &text,
|
const QString &text,
|
||||||
Fn<void()> handler,
|
Fn<void()> handler,
|
||||||
const style::icon *icon) const {
|
const style::icon *icon) const {
|
||||||
return callback({ text, std::move(handler), icon });
|
return callback({ text, std::move(handler), icon, nullptr });
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
Callback callback;
|
Callback callback;
|
||||||
|
|
Loading…
Add table
Reference in a new issue