From 53abd2fe38484433f0394ea3c811457a0cb4306c Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 6 Nov 2024 17:52:54 +0400 Subject: [PATCH] Follow show-panel-on-click for attach menu. --- .../SourceFiles/chat_helpers/tabbed_panel.cpp | 4 ++++ Telegram/SourceFiles/chat_helpers/tabbed_panel.h | 1 + Telegram/SourceFiles/history/history_widget.cpp | 16 +++++++++++++--- .../inline_bots/bot_attach_web_view.cpp | 14 +++++++++----- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp index 7d399a596..da083896f 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp @@ -33,6 +33,10 @@ base::options::toggle TabbedPanelShowOnClick({ const char kOptionTabbedPanelShowOnClick[] = "tabbed-panel-show-on-click"; +bool ShowPanelOnClick() { + return TabbedPanelShowOnClick.value(); +} + TabbedPanel::TabbedPanel( QWidget *parent, not_null controller, diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_panel.h b/Telegram/SourceFiles/chat_helpers/tabbed_panel.h index fcedb5efc..97d66e2c7 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_panel.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_panel.h @@ -25,6 +25,7 @@ namespace ChatHelpers { class TabbedSelector; extern const char kOptionTabbedPanelShowOnClick[]; +[[nodiscard]] bool ShowPanelOnClick(); struct TabbedPanelDescriptor { Window::SessionController *regularWindow = nullptr; diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 3d067da29..53d3db9fd 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -421,8 +421,16 @@ HistoryWidget::HistoryWidget( initTabbedSelector(); _attachToggle->setClickedCallback([=] { + const auto toggle = _attachBotsMenu && _attachBotsMenu->isHidden(); base::call_delayed(st::historyAttach.ripple.hideDuration, this, [=] { - chooseAttach(); + if (_attachBotsMenu && toggle) { + _attachBotsMenu->showAnimated(); + } else { + chooseAttach(); + if (_attachBotsMenu) { + _attachBotsMenu->hideAnimated(); + } + } }); }); @@ -2611,7 +2619,7 @@ void HistoryWidget::setHistory(History *history) { if (was && !now) { _attachToggle->removeEventFilter(_attachBotsMenu.get()); _attachBotsMenu->hideFast(); - } else if (now && !was) { + } else if (now && !was && !ChatHelpers::ShowPanelOnClick()) { _attachToggle->installEventFilter(_attachBotsMenu.get()); } @@ -2699,7 +2707,9 @@ void HistoryWidget::refreshAttachBotsMenu() { } _attachBotsMenu->setOrigin( Ui::PanelAnimation::Origin::BottomLeft); - _attachToggle->installEventFilter(_attachBotsMenu.get()); + if (!ChatHelpers::ShowPanelOnClick()) { + _attachToggle->installEventFilter(_attachBotsMenu.get()); + } _attachBotsMenu->heightValue( ) | rpl::start_with_next([=] { moveFieldControls(); diff --git a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp index be215bc50..c3290ea24 100644 --- a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp +++ b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp @@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/timer_rpl.h" #include "boxes/peer_list_controllers.h" #include "boxes/share_box.h" +#include "chat_helpers/tabbed_panel.h" #include "core/application.h" #include "core/click_handler_types.h" #include "core/local_url_handlers.h" @@ -2039,9 +2040,6 @@ std::unique_ptr MakeAttachBotsMenu( not_null peer, Fn actionFactory, Fn attach) { - if (!Data::CanSend(peer, ChatRestriction::SendInline)) { - return nullptr; - } auto result = std::make_unique( parent, st::dropdownMenuWithIcons); @@ -2096,8 +2094,10 @@ std::unique_ptr MakeAttachBotsMenu( ChooseAndSendLocation(controller, config, actionFactory()); }, &st::menuIconAddress); } + const auto addBots = Data::CanSend(peer, ChatRestriction::SendInline); for (const auto &bot : bots->attachBots()) { - if (!bot.inAttachMenu + if (!addBots + || !bot.inAttachMenu || !PeerMatchesTypes(peer, bot.user, bot.types)) { continue; } @@ -2128,7 +2128,11 @@ std::unique_ptr MakeAttachBotsMenu( }, action->lifetime()); raw->addAction(std::move(action)); } - if (raw->actions().size() <= minimal) { + const auto actions = raw->actions().size(); + const auto onclick = ChatHelpers::ShowPanelOnClick(); + if (!actions) { + return nullptr; + } else if (actions <= minimal && !onclick) { return nullptr; } return result;