From a030911ad549c3747e50c8225eafbcd3a85bc736 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 8 Jan 2021 01:38:09 +0300 Subject: [PATCH] Fixed filling context menu in TabbedPanel between sections. Fixed #10082. --- .../chat_helpers/tabbed_selector.cpp | 12 ++++++---- .../chat_helpers/tabbed_selector.h | 8 ++----- .../SourceFiles/history/history_widget.cpp | 22 ++++++++++--------- .../history_view_compose_controls.cpp | 5 ++++- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp index a3ccef428..cc0330d84 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp @@ -877,11 +877,8 @@ void TabbedSelector::scrollToY(int y) { } } -void TabbedSelector::contextMenuEvent(QContextMenuEvent *e) { +void TabbedSelector::showMenuWithType(SendMenu::Type type) { _menu = base::make_unique_q(this); - const auto type = _sendMenuType - ? _sendMenuType() - : SendMenu::Type::Disabled; currentTab()->widget()->fillContextMenu(_menu, type); if (!_menu->actions().empty()) { @@ -889,6 +886,13 @@ void TabbedSelector::contextMenuEvent(QContextMenuEvent *e) { } } +rpl::producer<> TabbedSelector::contextMenuRequested() const { + return events( + ) | rpl::filter([=](not_null e) { + return e->type() == QEvent::ContextMenu; + }) | rpl::to_empty; +} + TabbedSelector::Inner::Inner( QWidget *parent, not_null controller) diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h index a73e97e67..0011fecb9 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h @@ -82,6 +82,7 @@ public: rpl::producer<> cancelled() const; rpl::producer<> checkForHide() const; rpl::producer<> slideFinished() const; + rpl::producer<> contextMenuRequested() const; void setRoundRadius(int radius); void refreshStickers(); @@ -109,9 +110,7 @@ public: _beforeHidingCallback = std::move(callback); } - void setSendMenuType(Fn &&callback) { - _sendMenuType = std::move(callback); - } + void showMenuWithType(SendMenu::Type type); // Float player interface. bool floatPlayerHandleWheelEvent(QEvent *e); @@ -127,7 +126,6 @@ public: protected: void paintEvent(QPaintEvent *e) override; void resizeEvent(QResizeEvent *e) override; - void contextMenuEvent(QContextMenuEvent *e) override; private: class Tab { @@ -228,8 +226,6 @@ private: Fn _afterShownCallback; Fn _beforeHidingCallback; - Fn _sendMenuType; - rpl::event_stream<> _showRequests; rpl::event_stream<> _slideFinished; diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index b59ec772a..47f89ecd1 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -846,6 +846,11 @@ void HistoryWidget::initTabbedSelector() { return base::EventFilterResult::Continue; }); + auto filter = rpl::filter([=] { + return !isHidden(); + }); + using Selector = TabbedSelector; + selector->emojiChosen( ) | rpl::filter([=] { return !isHidden() && !_field->isHidden(); @@ -854,27 +859,24 @@ void HistoryWidget::initTabbedSelector() { }, lifetime()); selector->fileChosen( - ) | rpl::filter([=] { - return !isHidden(); - }) | rpl::start_with_next([=](TabbedSelector::FileChosen data) { + ) | filter | rpl::start_with_next([=](Selector::FileChosen data) { sendExistingDocument(data.document, data.options); }, lifetime()); selector->photoChosen( - ) | rpl::filter([=] { - return !isHidden(); - }) | rpl::start_with_next([=](TabbedSelector::PhotoChosen data) { + ) | filter | rpl::start_with_next([=](Selector::PhotoChosen data) { sendExistingPhoto(data.photo, data.options); }, lifetime()); selector->inlineResultChosen( - ) | rpl::filter([=] { - return !isHidden(); - }) | rpl::start_with_next([=](TabbedSelector::InlineChosen data) { + ) | filter | rpl::start_with_next([=](Selector::InlineChosen data) { sendInlineResult(data); }, lifetime()); - selector->setSendMenuType([=] { return sendMenuType(); }); + selector->contextMenuRequested( + ) | filter | rpl::start_with_next([=] { + selector->showMenuWithType(sendMenuType()); + }, lifetime()); } void HistoryWidget::supportInitAutocomplete() { diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index 54f972d45..da991c175 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -1410,7 +1410,10 @@ void ComposeControls::initTabbedSelector() { selector->inlineResultChosen( ) | rpl::start_to_stream(_inlineResultChosen, wrap->lifetime()); - selector->setSendMenuType([=] { return sendMenuType(); }); + selector->contextMenuRequested( + ) | rpl::start_with_next([=] { + selector->showMenuWithType(sendMenuType()); + }, wrap->lifetime()); } void ComposeControls::initSendButton() {