Skip to content

Commit

Permalink
Follow show-panel-on-click for attach menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Nov 6, 2024
1 parent da8a4ba commit 53abd2f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Window::SessionController*> controller,
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/chat_helpers/tabbed_panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace ChatHelpers {
class TabbedSelector;

extern const char kOptionTabbedPanelShowOnClick[];
[[nodiscard]] bool ShowPanelOnClick();

struct TabbedPanelDescriptor {
Window::SessionController *regularWindow = nullptr;
Expand Down
16 changes: 13 additions & 3 deletions Telegram/SourceFiles/history/history_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
});
});

Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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();
Expand Down
14 changes: 9 additions & 5 deletions Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ For license and copyright information please follow this link:
#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"
Expand Down Expand Up @@ -2039,9 +2040,6 @@ std::unique_ptr<Ui::DropdownMenu> MakeAttachBotsMenu(
not_null<PeerData*> peer,
Fn<Api::SendAction()> actionFactory,
Fn<void(bool)> attach) {
if (!Data::CanSend(peer, ChatRestriction::SendInline)) {
return nullptr;
}
auto result = std::make_unique<Ui::DropdownMenu>(
parent,
st::dropdownMenuWithIcons);
Expand Down Expand Up @@ -2096,8 +2094,10 @@ std::unique_ptr<Ui::DropdownMenu> 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;
}
Expand Down Expand Up @@ -2128,7 +2128,11 @@ std::unique_ptr<Ui::DropdownMenu> 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;
Expand Down

0 comments on commit 53abd2f

Please sign in to comment.