mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Moved out peer menu callback and its creation to separated files.
This commit is contained in:
parent
36e334ecf2
commit
67d8a7e106
10 changed files with 140 additions and 82 deletions
|
@ -37,6 +37,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "mainwidget.h"
|
#include "mainwidget.h"
|
||||||
|
#include "menu/add_action_callback_factory.h"
|
||||||
#include "storage/storage_account.h"
|
#include "storage/storage_account.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
@ -1771,22 +1772,7 @@ void InnerWidget::contextMenuEvent(QContextMenuEvent *e) {
|
||||||
fillArchiveSearchMenu(_menu.get());
|
fillArchiveSearchMenu(_menu.get());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const auto addAction = Window::PeerMenuCallback([&](
|
const auto addAction = Menu::CreateAddActionCallback(_menu);
|
||||||
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);
|
|
||||||
});
|
|
||||||
Window::FillDialogsEntryMenu(
|
Window::FillDialogsEntryMenu(
|
||||||
_controller,
|
_controller,
|
||||||
Dialogs::EntryState{
|
Dialogs::EntryState{
|
||||||
|
|
|
@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "mainwidget.h"
|
#include "mainwidget.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
#include "menu/add_action_callback_factory.h"
|
||||||
#include "mtproto/mtproto_config.h"
|
#include "mtproto/mtproto_config.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "core/shortcuts.h"
|
#include "core/shortcuts.h"
|
||||||
|
@ -283,14 +284,14 @@ bool TopBarWidget::createMenu(not_null<Ui::IconButton*> button) {
|
||||||
if (!_activeChat.key || _menu) {
|
if (!_activeChat.key || _menu) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_menu.create(this, st::popupMenuExpandedSeparator);
|
_menu = base::make_unique_q<Ui::PopupMenu>(
|
||||||
|
this,
|
||||||
|
st::popupMenuExpandedSeparator);
|
||||||
_menu->setDestroyedCallback([
|
_menu->setDestroyedCallback([
|
||||||
weak = Ui::MakeWeak(this),
|
weak = Ui::MakeWeak(this),
|
||||||
weakButton = Ui::MakeWeak(button),
|
weakButton = Ui::MakeWeak(button),
|
||||||
menu = _menu.data()] {
|
menu = _menu.get()] {
|
||||||
menu->deleteLater();
|
|
||||||
if (weak && weak->_menu == menu) {
|
if (weak && weak->_menu == menu) {
|
||||||
weak->_menu = nullptr;
|
|
||||||
if (weakButton) {
|
if (weakButton) {
|
||||||
weakButton->setForceRippled(false);
|
weakButton->setForceRippled(false);
|
||||||
}
|
}
|
||||||
|
@ -305,25 +306,10 @@ void TopBarWidget::showPeerMenu() {
|
||||||
if (!created) {
|
if (!created) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto addAction = Window::PeerMenuCallback([&](
|
const auto addAction = Menu::CreateAddActionCallback(_menu);
|
||||||
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);
|
|
||||||
});
|
|
||||||
Window::FillDialogsEntryMenu(_controller, _activeChat, addAction);
|
Window::FillDialogsEntryMenu(_controller, _activeChat, addAction);
|
||||||
if (_menu->empty()) {
|
if (_menu->empty()) {
|
||||||
_menu.destroy();
|
_menu = nullptr;
|
||||||
} else {
|
} else {
|
||||||
_menu->setForcedOrigin(Ui::PanelAnimation::Origin::TopRight);
|
_menu->setForcedOrigin(Ui::PanelAnimation::Origin::TopRight);
|
||||||
_menu->popup(mapToGlobal(QPoint(
|
_menu->popup(mapToGlobal(QPoint(
|
||||||
|
|
|
@ -179,7 +179,7 @@ private:
|
||||||
object_ptr<Ui::IconButton> _search;
|
object_ptr<Ui::IconButton> _search;
|
||||||
object_ptr<Ui::IconButton> _infoToggle;
|
object_ptr<Ui::IconButton> _infoToggle;
|
||||||
object_ptr<Ui::IconButton> _menuToggle;
|
object_ptr<Ui::IconButton> _menuToggle;
|
||||||
object_ptr<Ui::PopupMenu> _menu = { nullptr };
|
base::unique_qptr<Ui::PopupMenu> _menu;
|
||||||
|
|
||||||
object_ptr<TWidget> _membersShowArea = { nullptr };
|
object_ptr<TWidget> _membersShowArea = { nullptr };
|
||||||
rpl::event_stream<bool> _membersShowAreaActive;
|
rpl::event_stream<bool> _membersShowAreaActive;
|
||||||
|
|
|
@ -31,6 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "boxes/peer_list_box.h"
|
#include "boxes/peer_list_box.h"
|
||||||
#include "ui/boxes/confirm_box.h"
|
#include "ui/boxes/confirm_box.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
#include "menu/add_action_callback_factory.h"
|
||||||
#include "mtproto/mtproto_config.h"
|
#include "mtproto/mtproto_config.h"
|
||||||
#include "data/data_download_manager.h"
|
#include "data/data_download_manager.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
|
@ -505,23 +506,7 @@ void WrapWidget::showTopBarMenu() {
|
||||||
});
|
});
|
||||||
_topBarMenuToggle->setForceRippled(true);
|
_topBarMenuToggle->setForceRippled(true);
|
||||||
|
|
||||||
const auto addAction = Window::PeerMenuCallback([=](
|
const auto addAction = Menu::CreateAddActionCallback(_topBarMenu);
|
||||||
Window::PeerMenuCallback::Args a) {
|
|
||||||
if (a.isSeparator) {
|
|
||||||
return _topBarMenu->addSeparator();
|
|
||||||
} else if (a.fillSubmenu) {
|
|
||||||
const auto action = _topBarMenu->addAction(
|
|
||||||
a.text,
|
|
||||||
std::move(a.handler),
|
|
||||||
a.icon);
|
|
||||||
// Dummy menu.
|
|
||||||
action->setMenu(
|
|
||||||
Ui::CreateChild<QMenu>(_topBarMenu->menu().get()));
|
|
||||||
a.fillSubmenu(_topBarMenu->ensureSubmenu(action));
|
|
||||||
return action;
|
|
||||||
}
|
|
||||||
return _topBarMenu->addAction(a.text, std::move(a.handler), a.icon);
|
|
||||||
});
|
|
||||||
if (key().isDownloads()) {
|
if (key().isDownloads()) {
|
||||||
addAction(
|
addAction(
|
||||||
tr::lng_context_delete_all_files(tr::now),
|
tr::lng_context_delete_all_files(tr::now),
|
||||||
|
|
27
Telegram/SourceFiles/menu/add_action_callback.cpp
Normal file
27
Telegram/SourceFiles/menu/add_action_callback.cpp
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
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.h"
|
||||||
|
|
||||||
|
namespace Menu {
|
||||||
|
|
||||||
|
MenuCallback::MenuCallback(MenuCallback::Callback callback)
|
||||||
|
: _callback(std::move(callback)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
QAction *MenuCallback::operator()(Args &&args) const {
|
||||||
|
return _callback(std::move(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
QAction *MenuCallback::operator()(
|
||||||
|
const QString &text,
|
||||||
|
Fn<void()> handler,
|
||||||
|
const style::icon *icon) const {
|
||||||
|
return _callback({ text, std::move(handler), icon, nullptr });
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Menu
|
38
Telegram/SourceFiles/menu/add_action_callback.h
Normal file
38
Telegram/SourceFiles/menu/add_action_callback.h
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class PopupMenu;
|
||||||
|
} // namespace Ui
|
||||||
|
|
||||||
|
namespace Menu {
|
||||||
|
|
||||||
|
struct MenuCallback final {
|
||||||
|
public:
|
||||||
|
struct Args {
|
||||||
|
QString text;
|
||||||
|
Fn<void()> handler;
|
||||||
|
const style::icon *icon;
|
||||||
|
Fn<void(not_null<Ui::PopupMenu*>)> fillSubmenu;
|
||||||
|
bool isSeparator = false;
|
||||||
|
};
|
||||||
|
using Callback = Fn<QAction*(Args&&)>;
|
||||||
|
|
||||||
|
explicit MenuCallback(Callback callback);
|
||||||
|
|
||||||
|
QAction *operator()(Args &&args) const;
|
||||||
|
QAction *operator()(
|
||||||
|
const QString &text,
|
||||||
|
Fn<void()> handler,
|
||||||
|
const style::icon *icon) const;
|
||||||
|
private:
|
||||||
|
Callback _callback;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Menu
|
34
Telegram/SourceFiles/menu/add_action_callback_factory.cpp
Normal file
34
Telegram/SourceFiles/menu/add_action_callback_factory.cpp
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
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"
|
||||||
|
#include "ui/widgets/popup_menu.h"
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
return menu->addAction(a.text, std::move(a.handler), a.icon);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Menu
|
23
Telegram/SourceFiles/menu/add_action_callback_factory.h
Normal file
23
Telegram/SourceFiles/menu/add_action_callback_factory.h
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "base/unique_qptr.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class PopupMenu;
|
||||||
|
} // namespace Ui
|
||||||
|
|
||||||
|
namespace Menu {
|
||||||
|
|
||||||
|
struct MenuCallback;
|
||||||
|
|
||||||
|
[[nodiscard]] MenuCallback CreateAddActionCallback(
|
||||||
|
const base::unique_qptr<Ui::PopupMenu> &menu);
|
||||||
|
|
||||||
|
} // namespace Menu
|
|
@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "api/api_common.h"
|
#include "api/api_common.h"
|
||||||
#include "menu/menu_send.h"
|
#include "menu/menu_send.h"
|
||||||
#include "data/data_poll.h"
|
#include "data/data_poll.h"
|
||||||
|
#include "menu/add_action_callback.h"
|
||||||
|
|
||||||
class History;
|
class History;
|
||||||
|
|
||||||
|
@ -38,33 +39,7 @@ class SessionNavigation;
|
||||||
|
|
||||||
extern const char kOptionViewProfileInChatsListContextMenu[];
|
extern const char kOptionViewProfileInChatsListContextMenu[];
|
||||||
|
|
||||||
struct PeerMenuCallback {
|
using PeerMenuCallback = Menu::MenuCallback;
|
||||||
public:
|
|
||||||
struct Args {
|
|
||||||
QString text;
|
|
||||||
Fn<void()> handler;
|
|
||||||
const style::icon *icon;
|
|
||||||
Fn<void(not_null<Ui::PopupMenu*>)> fillSubmenu;
|
|
||||||
bool isSeparator = false;
|
|
||||||
};
|
|
||||||
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, nullptr });
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
Callback callback;
|
|
||||||
};
|
|
||||||
|
|
||||||
void FillDialogsEntryMenu(
|
void FillDialogsEntryMenu(
|
||||||
not_null<SessionController*> controller,
|
not_null<SessionController*> controller,
|
||||||
|
|
|
@ -102,6 +102,10 @@ PRIVATE
|
||||||
media/player/media_player_dropdown.cpp
|
media/player/media_player_dropdown.cpp
|
||||||
media/player/media_player_dropdown.h
|
media/player/media_player_dropdown.h
|
||||||
|
|
||||||
|
menu/add_action_callback.cpp
|
||||||
|
menu/add_action_callback.h
|
||||||
|
menu/add_action_callback_factory.cpp
|
||||||
|
menu/add_action_callback_factory.h
|
||||||
menu/menu_check_item.cpp
|
menu/menu_check_item.cpp
|
||||||
menu/menu_check_item.h
|
menu/menu_check_item.h
|
||||||
menu/menu_ttl.cpp
|
menu/menu_ttl.cpp
|
||||||
|
|
Loading…
Add table
Reference in a new issue