diff --git a/Telegram/SourceFiles/boxes/peer_list_controllers.cpp b/Telegram/SourceFiles/boxes/peer_list_controllers.cpp index fb9cd3ad92..4b8041fab9 100644 --- a/Telegram/SourceFiles/boxes/peer_list_controllers.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_controllers.cpp @@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_histories.h" #include "apiwrap.h" #include "mainwidget.h" +#include "mainwindow.h" #include "lang/lang_keys.h" #include "history/history.h" #include "dialogs/dialogs_main_list.h" @@ -104,6 +105,20 @@ void AddBotToGroup(not_null bot, not_null chat) { // return mapFromGlobal(QCursor::pos()) - _st.rippleAreaPosition; //} +object_ptr PrepareContactsBox( + not_null sessionController) { + const auto controller = sessionController; + auto delegate = [=](not_null box) { + box->addButton(tr::lng_close(), [=] { box->closeBox(); }); + box->addLeftButton( + tr::lng_profile_add_contact(), + [=] { controller->widget()->onShowAddContact(); }); + }; + return Box( + std::make_unique(controller), + std::move(delegate)); +} + void PeerListRowWithLink::setActionLink(const QString &action) { _action = action; refreshActionLink(); diff --git a/Telegram/SourceFiles/boxes/peer_list_controllers.h b/Telegram/SourceFiles/boxes/peer_list_controllers.h index 02eb810b4d..17d4952413 100644 --- a/Telegram/SourceFiles/boxes/peer_list_controllers.h +++ b/Telegram/SourceFiles/boxes/peer_list_controllers.h @@ -31,9 +31,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL class History; namespace Window { +class SessionController; class SessionNavigation; } // namespace Window +[[nodiscard]] object_ptr PrepareContactsBox( + not_null sessionController); + class PeerListRowWithLink : public PeerListRow { public: using PeerListRow::PeerListRow; diff --git a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp index 1c3171c571..1c8a1cbb54 100644 --- a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp @@ -950,18 +950,7 @@ void MainWindow::createGlobalMenu() { return; } - Ui::show( - Box(std::make_unique( - sessionController()), - [](not_null box) { - box->addButton(tr::lng_close(), [box] { - box->closeBox(); - }); - - box->addLeftButton(tr::lng_profile_add_contact(), [] { - App::wnd()->onShowAddContact(); - }); - })); + Ui::show(PrepareContactsBox(sessionController())); })); psAddContact = tools->addAction( diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.mm b/Telegram/SourceFiles/platform/mac/main_window_mac.mm index e008f9ba1c..6fbd9ec113 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -721,10 +721,7 @@ void MainWindow::createGlobalMenu() { if (!sessionController()) { return; } - Ui::show(Box(std::make_unique(sessionController()), [](not_null box) { - box->addButton(tr::lng_close(), [box] { box->closeBox(); }); - box->addLeftButton(tr::lng_profile_add_contact(), [] { App::wnd()->onShowAddContact(); }); - })); + Ui::show(PrepareContactsBox(sessionController())); })); psAddContact = window->addAction(tr::lng_mac_menu_add_contact(tr::now), App::wnd(), SLOT(onShowAddContact())); window->addSeparator(); diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index d56d252e2c..c4cfe2a0b1 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -861,10 +861,7 @@ void MainMenu::refreshMenu() { App::wnd()->onShowNewChannel(); }, &st::mainMenuNewChannel, &st::mainMenuNewChannelOver); _menu->addAction(tr::lng_menu_contacts(tr::now), [=] { - Ui::show(Box(std::make_unique(controller), [](not_null box) { - box->addButton(tr::lng_close(), [box] { box->closeBox(); }); - box->addLeftButton(tr::lng_profile_add_contact(), [] { App::wnd()->onShowAddContact(); }); - })); + Ui::show(PrepareContactsBox(controller)); }, &st::mainMenuContacts, &st::mainMenuContactsOver); if (_controller->session().serverConfig().phoneCallsEnabled.current()) { _menu->addAction(tr::lng_menu_calls(tr::now), [=] {