From 316d015d23566257a5c2f2f3a6dbb1f43e6cae02 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 6 Sep 2018 18:24:24 +0300 Subject: [PATCH] Add three dot menu to settings. Edit + logout. --- Telegram/Resources/langs/lang.strings | 1 + .../SourceFiles/info/info_wrap_widget.cpp | 23 ++++++++++++------- Telegram/SourceFiles/info/info_wrap_widget.h | 4 ++-- .../SourceFiles/settings/settings_common.cpp | 11 +++++++++ .../SourceFiles/settings/settings_common.h | 8 +++++++ 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 8b742b7ee9..d048e6808e 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -330,6 +330,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_language" = "Language"; "lng_settings_default_scale" = "Default interface scale"; +"lng_settings_edit_info" = "Edit information"; "lng_backgrounds_header" = "Choose your new chat background"; "lng_theme_sure_keep" = "Keep this theme?"; diff --git a/Telegram/SourceFiles/info/info_wrap_widget.cpp b/Telegram/SourceFiles/info/info_wrap_widget.cpp index 424d9f256f..e81066d0f6 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.cpp +++ b/Telegram/SourceFiles/info/info_wrap_widget.cpp @@ -378,11 +378,15 @@ void WrapWidget::createTopBar() { _controller->searchEnabledByContent(), _controller->takeSearchStartsFocused()); } - if (_controller->section().type() == Section::Type::Profile + const auto section = _controller->section(); + if (section.type() == Section::Type::Profile && (wrapValue != Wrap::Side || hasStackHistory())) { - addProfileMenuButton(); + addTopBarMenuButton(); addProfileCallsButton(); // addProfileNotificationsButton(); + } else if (section.type() == Section::Type::Settings + && section.settingsType() == Section::SettingsType::Main) { + addTopBarMenuButton(); } _topBar->lower(); @@ -391,7 +395,7 @@ void WrapWidget::createTopBar() { _topBar->show(); } -void WrapWidget::addProfileMenuButton() { +void WrapWidget::addTopBarMenuButton() { Expects(_topBar != nullptr); _topBarMenuToggle.reset(_topBar->addButton( @@ -401,7 +405,7 @@ void WrapWidget::addProfileMenuButton() { ? st::infoLayerTopBarMenu : st::infoTopBarMenu)))); _topBarMenuToggle->addClickHandler([this] { - showProfileMenu(); + showTopBarMenu(); }); } @@ -471,7 +475,7 @@ void WrapWidget::addProfileNotificationsButton() { }, notifications->lifetime()); } -void WrapWidget::showProfileMenu() { +void WrapWidget::showTopBarMenu() { if (_topBarMenu) { _topBarMenu->hideAnimated( Ui::InnerDropdown::HideOption::IgnoreShow); @@ -515,9 +519,12 @@ void WrapWidget::showProfileMenu() { addAction, Window::PeerMenuSource::Profile); } else if (const auto self = key().settingsSelf()) { - // #TODO settings top menu - _topBarMenu = nullptr; - return; + const auto showOther = [=](::Settings::Type type) { + const auto controller = _controller.get(); + _topBarMenu = nullptr; + controller->showSettings(type); + }; + ::Settings::FillMenu(showOther, addAction); } else { _topBarMenu = nullptr; return; diff --git a/Telegram/SourceFiles/info/info_wrap_widget.h b/Telegram/SourceFiles/info/info_wrap_widget.h index a7d5504a6b..3badfa09c3 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.h +++ b/Telegram/SourceFiles/info/info_wrap_widget.h @@ -191,10 +191,10 @@ private: rpl::producer selectedListValue() const; bool requireTopBarSearch() const; - void addProfileMenuButton(); + void addTopBarMenuButton(); void addProfileCallsButton(); void addProfileNotificationsButton(); - void showProfileMenu(); + void showTopBarMenu(); rpl::variable _wrap; std::unique_ptr _controller; diff --git a/Telegram/SourceFiles/settings/settings_common.cpp b/Telegram/SourceFiles/settings/settings_common.cpp index f41d5d0a69..a683d9096b 100644 --- a/Telegram/SourceFiles/settings/settings_common.cpp +++ b/Telegram/SourceFiles/settings/settings_common.cpp @@ -13,6 +13,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "settings/settings_main.h" #include "settings/settings_notifications.h" #include "settings/settings_privacy_security.h" +#include "lang/lang_keys.h" +#include "mainwindow.h" namespace Settings { @@ -38,4 +40,13 @@ object_ptr
CreateSection( Unexpected("Settings section type in Widget::createInnerWidget."); } +void FillMenu(Fn showOther, MenuCallback addAction) { + addAction( + lang(lng_settings_edit_info), + [=] { showOther(Type::Information); }); + addAction( + lang(lng_settings_logout), + [=] { App::wnd()->onLogout(); }); +} + } // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_common.h b/Telegram/SourceFiles/settings/settings_common.h index c1b453cb11..284c320091 100644 --- a/Telegram/SourceFiles/settings/settings_common.h +++ b/Telegram/SourceFiles/settings/settings_common.h @@ -48,4 +48,12 @@ object_ptr
CreateSection( not_null controller, UserData *self = nullptr); +using MenuCallback = Fn handler)>; + +void FillMenu( + Fn showOther, + MenuCallback addAction); + } // namespace Settings