From 43056107fdf0c90c21fa512fb13e3d9b874231f8 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 25 Jul 2020 19:50:19 +0300 Subject: [PATCH] Added ability to pass SendMenuType to TabbedSelector. --- .../SourceFiles/chat_helpers/gifs_list_widget.cpp | 8 +++++--- Telegram/SourceFiles/chat_helpers/gifs_list_widget.h | 6 +++++- .../chat_helpers/stickers_list_widget.cpp | 8 +++++--- .../SourceFiles/chat_helpers/stickers_list_widget.h | 4 +++- .../SourceFiles/chat_helpers/tabbed_selector.cpp | 6 +++++- Telegram/SourceFiles/chat_helpers/tabbed_selector.h | 12 +++++++++++- Telegram/SourceFiles/history/history_widget.cpp | 2 ++ 7 files changed, 36 insertions(+), 10 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp index ded6f8b6f..10544a6ab 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp @@ -347,7 +347,9 @@ void GifsListWidget::mousePressEvent(QMouseEvent *e) { _previewTimer.callOnce(QApplication::startDragTime()); } -void GifsListWidget::fillContextMenu(not_null menu) { +void GifsListWidget::fillContextMenu( + not_null menu, + SendMenuType type) { if (_selected < 0 || _pressed >= 0) { return; } @@ -362,13 +364,13 @@ void GifsListWidget::fillContextMenu(not_null menu) { Ui::show( HistoryView::PrepareScheduleBox( this, - SendMenuType::Scheduled, + type, [=](Api::SendOptions options) { send(options); }), Ui::LayerOption::KeepOther); }; FillSendMenu( menu, - [] { return SendMenuType::Scheduled; }, + [&] { return type; }, silent, schedule); } diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h index 366e1279c..8772cf2a0 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h @@ -34,6 +34,8 @@ namespace Window { class SessionController; } // namespace Window +enum class SendMenuType; + namespace ChatHelpers { class GifsListWidget @@ -71,7 +73,9 @@ public: void cancelled(); rpl::producer<> cancelRequests() const; - void fillContextMenu(not_null menu) override; + void fillContextMenu( + not_null menu, + SendMenuType type) override; ~GifsListWidget(); diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index 896949164..62ebe98d9 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -2046,7 +2046,9 @@ QPoint StickersListWidget::buttonRippleTopLeft(int section) const { return myrtlrect(removeButtonRect(section)).topLeft() + st::stickerPanRemoveSet.rippleAreaPosition; } -void StickersListWidget::fillContextMenu(not_null menu) { +void StickersListWidget::fillContextMenu( + not_null menu, + SendMenuType type) { auto selected = _selected; auto &sets = shownSets(); if (!selected || _pressed) { @@ -2068,13 +2070,13 @@ void StickersListWidget::fillContextMenu(not_null menu) { checkHideWithBox(Ui::show( HistoryView::PrepareScheduleBox( this, - SendMenuType::Scheduled, + type, [=](Api::SendOptions options) { send(options); }), Ui::LayerOption::KeepOther).data()); }; FillSendMenu( menu, - [] { return SendMenuType::Scheduled; }, + [&] { return type; }, silent, schedule); } diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h index 2e7adc729..e2c46a6a6 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h @@ -83,7 +83,9 @@ public: std::shared_ptr getLottieRenderer(); - void fillContextMenu(not_null menu) override; + void fillContextMenu( + not_null menu, + SendMenuType type) override; ~StickersListWidget(); diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp index 03daa863f..fbb46532b 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "chat_helpers/tabbed_selector.h" +#include "chat_helpers/message_field.h" #include "chat_helpers/emoji_list_widget.h" #include "chat_helpers/stickers_list_widget.h" #include "chat_helpers/gifs_list_widget.h" @@ -876,7 +877,10 @@ void TabbedSelector::scrollToY(int y) { void TabbedSelector::contextMenuEvent(QContextMenuEvent *e) { _menu = base::make_unique_q(this); - currentTab()->widget()->fillContextMenu(_menu); + const auto type = _sendMenuType + ? _sendMenuType() + : SendMenuType::Disabled; + currentTab()->widget()->fillContextMenu(_menu, type); if (!_menu->actions().empty()) { _menu->popup(QCursor::pos()); diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h index eb719b6f2..1ec902e27 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h @@ -34,6 +34,8 @@ namespace Window { class SessionController; } // namespace Window +enum class SendMenuType; + namespace ChatHelpers { enum class SelectorTab { @@ -104,6 +106,10 @@ public: _beforeHidingCallback = std::move(callback); } + void setSendMenuType(Fn callback) { + _sendMenuType = std::move(callback); + } + // Float player interface. bool floatPlayerHandleWheelEvent(QEvent *e); QRect floatPlayerAvailableRect() const; @@ -219,6 +225,8 @@ private: Fn _afterShownCallback; Fn _beforeHidingCallback; + Fn _sendMenuType; + rpl::event_stream<> _showRequests; rpl::event_stream<> _slideFinished; @@ -251,7 +259,9 @@ public: } virtual void beforeHiding() { } - virtual void fillContextMenu(not_null menu) { + virtual void fillContextMenu( + not_null menu, + SendMenuType type) { } rpl::producer scrollToRequests() const; diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 2e7a67e91..b7137c620 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -835,6 +835,8 @@ void HistoryWidget::initTabbedSelector() { }) | rpl::start_with_next([=](TabbedSelector::InlineChosen data) { sendInlineResult(data.result, data.bot); }, lifetime()); + + selector->setSendMenuType([=] { return sendMenuType(); }); } void HistoryWidget::supportInitAutocomplete() {