Follow show-panel-on-click for attach menu.

This commit is contained in:
John Preston 2024-11-06 17:52:54 +04:00
parent da8a4ba8ab
commit 53abd2fe38
4 changed files with 27 additions and 8 deletions

View file

@ -33,6 +33,10 @@ base::options::toggle TabbedPanelShowOnClick({
const char kOptionTabbedPanelShowOnClick[] = "tabbed-panel-show-on-click"; const char kOptionTabbedPanelShowOnClick[] = "tabbed-panel-show-on-click";
bool ShowPanelOnClick() {
return TabbedPanelShowOnClick.value();
}
TabbedPanel::TabbedPanel( TabbedPanel::TabbedPanel(
QWidget *parent, QWidget *parent,
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,

View file

@ -25,6 +25,7 @@ namespace ChatHelpers {
class TabbedSelector; class TabbedSelector;
extern const char kOptionTabbedPanelShowOnClick[]; extern const char kOptionTabbedPanelShowOnClick[];
[[nodiscard]] bool ShowPanelOnClick();
struct TabbedPanelDescriptor { struct TabbedPanelDescriptor {
Window::SessionController *regularWindow = nullptr; Window::SessionController *regularWindow = nullptr;

View file

@ -421,8 +421,16 @@ HistoryWidget::HistoryWidget(
initTabbedSelector(); initTabbedSelector();
_attachToggle->setClickedCallback([=] { _attachToggle->setClickedCallback([=] {
const auto toggle = _attachBotsMenu && _attachBotsMenu->isHidden();
base::call_delayed(st::historyAttach.ripple.hideDuration, this, [=] { 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) { if (was && !now) {
_attachToggle->removeEventFilter(_attachBotsMenu.get()); _attachToggle->removeEventFilter(_attachBotsMenu.get());
_attachBotsMenu->hideFast(); _attachBotsMenu->hideFast();
} else if (now && !was) { } else if (now && !was && !ChatHelpers::ShowPanelOnClick()) {
_attachToggle->installEventFilter(_attachBotsMenu.get()); _attachToggle->installEventFilter(_attachBotsMenu.get());
} }
@ -2699,7 +2707,9 @@ void HistoryWidget::refreshAttachBotsMenu() {
} }
_attachBotsMenu->setOrigin( _attachBotsMenu->setOrigin(
Ui::PanelAnimation::Origin::BottomLeft); Ui::PanelAnimation::Origin::BottomLeft);
_attachToggle->installEventFilter(_attachBotsMenu.get()); if (!ChatHelpers::ShowPanelOnClick()) {
_attachToggle->installEventFilter(_attachBotsMenu.get());
}
_attachBotsMenu->heightValue( _attachBotsMenu->heightValue(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
moveFieldControls(); moveFieldControls();

View file

@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/timer_rpl.h" #include "base/timer_rpl.h"
#include "boxes/peer_list_controllers.h" #include "boxes/peer_list_controllers.h"
#include "boxes/share_box.h" #include "boxes/share_box.h"
#include "chat_helpers/tabbed_panel.h"
#include "core/application.h" #include "core/application.h"
#include "core/click_handler_types.h" #include "core/click_handler_types.h"
#include "core/local_url_handlers.h" #include "core/local_url_handlers.h"
@ -2039,9 +2040,6 @@ std::unique_ptr<Ui::DropdownMenu> MakeAttachBotsMenu(
not_null<PeerData*> peer, not_null<PeerData*> peer,
Fn<Api::SendAction()> actionFactory, Fn<Api::SendAction()> actionFactory,
Fn<void(bool)> attach) { Fn<void(bool)> attach) {
if (!Data::CanSend(peer, ChatRestriction::SendInline)) {
return nullptr;
}
auto result = std::make_unique<Ui::DropdownMenu>( auto result = std::make_unique<Ui::DropdownMenu>(
parent, parent,
st::dropdownMenuWithIcons); st::dropdownMenuWithIcons);
@ -2096,8 +2094,10 @@ std::unique_ptr<Ui::DropdownMenu> MakeAttachBotsMenu(
ChooseAndSendLocation(controller, config, actionFactory()); ChooseAndSendLocation(controller, config, actionFactory());
}, &st::menuIconAddress); }, &st::menuIconAddress);
} }
const auto addBots = Data::CanSend(peer, ChatRestriction::SendInline);
for (const auto &bot : bots->attachBots()) { for (const auto &bot : bots->attachBots()) {
if (!bot.inAttachMenu if (!addBots
|| !bot.inAttachMenu
|| !PeerMatchesTypes(peer, bot.user, bot.types)) { || !PeerMatchesTypes(peer, bot.user, bot.types)) {
continue; continue;
} }
@ -2128,7 +2128,11 @@ std::unique_ptr<Ui::DropdownMenu> MakeAttachBotsMenu(
}, action->lifetime()); }, action->lifetime());
raw->addAction(std::move(action)); 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 nullptr;
} }
return result; return result;