From 1ccfcc824c244ff084896c0b20b6a5ebbc3aac8f Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 13 Jan 2021 04:10:25 +0300 Subject: [PATCH] Updated code to be consistent with lib_ui. --- .../chat_helpers/field_autocomplete.cpp | 2 +- .../SourceFiles/chat_helpers/tabbed_selector.cpp | 4 ++-- .../SourceFiles/dialogs/dialogs_inner_widget.cpp | 2 +- .../admin_log/history_admin_log_inner.cpp | 2 +- .../SourceFiles/history/history_inner_widget.cpp | 2 +- .../history/view/history_view_list_widget.cpp | 2 +- .../history/view/history_view_top_bar_widget.cpp | 2 +- .../inline_bots/inline_results_inner.cpp | 2 +- Telegram/SourceFiles/window/window_main_menu.cpp | 16 ++++++++++++++-- 9 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp index 3b939b3d7..36eddd08e 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp @@ -1138,7 +1138,7 @@ void FieldAutocomplete::Inner::contextMenuEvent(QContextMenuEvent *e) { SendMenu::DefaultSilentCallback(send), SendMenu::DefaultScheduleCallback(this, type, send)); - if (!_menu->actions().empty()) { + if (!_menu->empty()) { _menu->popup(QCursor::pos()); } } diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp index cc0330d84..9b9a92910 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp @@ -594,7 +594,7 @@ bool TabbedSelector::preventAutoHide() const { } bool TabbedSelector::hasMenu() const { - return (_menu && !_menu->actions().empty()); + return (_menu && !_menu->empty()); } QImage TabbedSelector::grabForAnimation() { @@ -881,7 +881,7 @@ void TabbedSelector::showMenuWithType(SendMenu::Type type) { _menu = base::make_unique_q(this); currentTab()->widget()->fillContextMenu(_menu, type); - if (!_menu->actions().empty()) { + if (!_menu->empty()) { _menu->popup(QCursor::pos()); } } diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 67adfa4f3..90da5d83f 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -1841,7 +1841,7 @@ void InnerWidget::contextMenuEvent(QContextMenuEvent *e) { selectByMouse(globalPosition); } }); - if (_menu->actions().empty()) { + if (_menu->empty()) { _menu = nullptr; } else { _menu->popup(e->globalPos()); diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index 923b8d316..f96a4e476 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -1177,7 +1177,7 @@ void InnerWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { } } - if (_menu->actions().empty()) { + if (_menu->empty()) { _menu = nullptr; } else { _menu->popup(e->globalPos()); diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index e70464ef0..755dd3387 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -1851,7 +1851,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { } } - if (_menu->actions().empty()) { + if (_menu->empty()) { _menu = nullptr; } else { _menu->popup(e->globalPos()); diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index dc07f3a48..e75789e2a 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -1832,7 +1832,7 @@ void ListWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { _overState)); _menu = FillContextMenu(this, request); - if (_menu && !_menu->actions().empty()) { + if (_menu && !_menu->empty()) { _menu->popup(e->globalPos()); e->accept(); } else if (_menu) { diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index a681768bf..1a654ee20 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -256,7 +256,7 @@ void TopBarWidget::showMenu() { _controller, _activeChat, addAction); - if (_menu->actions().empty()) { + if (_menu->empty()) { _menu.destroy(); } else { _menu->moveToRight((parentWidget()->width() - width()) + st::topBarMenuPosition.x(), st::topBarMenuPosition.y()); diff --git a/Telegram/SourceFiles/inline_bots/inline_results_inner.cpp b/Telegram/SourceFiles/inline_bots/inline_results_inner.cpp index 4507e698a..e44caf6fe 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_inner.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_results_inner.cpp @@ -305,7 +305,7 @@ void Inner::contextMenuEvent(QContextMenuEvent *e) { SendMenu::DefaultSilentCallback(send), SendMenu::DefaultScheduleCallback(this, type, send)); - if (!_menu->actions().empty()) { + if (!_menu->empty()) { _menu->popup(QCursor::pos()); } } diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index 0c36684e6..a59bd0342 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/labels.h" #include "ui/widgets/menu/menu.h" #include "ui/widgets/menu/menu_common.h" +#include "ui/widgets/menu/menu_toggle.h" #include "ui/widgets/popup_menu.h" #include "ui/widgets/scroll_area.h" #include "ui/widgets/shadow.h" @@ -905,7 +906,8 @@ void MainMenu::refreshMenu() { }, &st::mainMenuSettings, &st::mainMenuSettingsOver); _nightThemeAction = std::make_shared>(); - auto action = _menu->addAction(tr::lng_menu_night_mode(tr::now), [=] { + + auto nightCallback = [=] { if (Window::Theme::Background()->editingTheme()) { Ui::show(Box( tr::lng_theme_editor_cant_change_theme(tr::now))); @@ -924,7 +926,17 @@ void MainMenu::refreshMenu() { Window::Theme::ToggleNightModeWithConfirmation( &_controller->window(), toggle); - }, &st::mainMenuNightMode, &st::mainMenuNightModeOver); + }; + + auto item = base::make_unique_q( + _menu, + st::mainMenu, + tr::lng_menu_night_mode(tr::now), + std::move(nightCallback), + &st::mainMenuNightMode, + &st::mainMenuNightModeOver); + + auto action = _menu->addAction(std::move(item)); *_nightThemeAction = action; action->setCheckable(true); action->setChecked(Window::Theme::IsNightMode());