Moved contacts box preparing to single place.

This commit is contained in:
23rd 2020-10-07 20:08:50 +03:00 committed by John Preston
parent 8b27aa5331
commit 367b028094
5 changed files with 22 additions and 20 deletions

View File

@ -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<UserData*> bot, not_null<PeerData*> chat) {
// return mapFromGlobal(QCursor::pos()) - _st.rippleAreaPosition;
//}
object_ptr<Ui::BoxContent> PrepareContactsBox(
not_null<Window::SessionController*> sessionController) {
const auto controller = sessionController;
auto delegate = [=](not_null<PeerListBox*> box) {
box->addButton(tr::lng_close(), [=] { box->closeBox(); });
box->addLeftButton(
tr::lng_profile_add_contact(),
[=] { controller->widget()->onShowAddContact(); });
};
return Box<PeerListBox>(
std::make_unique<ContactsBoxController>(controller),
std::move(delegate));
}
void PeerListRowWithLink::setActionLink(const QString &action) {
_action = action;
refreshActionLink();

View File

@ -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<Ui::BoxContent> PrepareContactsBox(
not_null<Window::SessionController*> sessionController);
class PeerListRowWithLink : public PeerListRow {
public:
using PeerListRow::PeerListRow;

View File

@ -950,18 +950,7 @@ void MainWindow::createGlobalMenu() {
return;
}
Ui::show(
Box<PeerListBox>(std::make_unique<ContactsBoxController>(
sessionController()),
[](not_null<PeerListBox*> 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(

View File

@ -721,10 +721,7 @@ void MainWindow::createGlobalMenu() {
if (!sessionController()) {
return;
}
Ui::show(Box<PeerListBox>(std::make_unique<ContactsBoxController>(sessionController()), [](not_null<PeerListBox*> 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();

View File

@ -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<PeerListBox>(std::make_unique<ContactsBoxController>(controller), [](not_null<PeerListBox*> 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), [=] {