Added ability to pass SendMenuType to TabbedSelector.

This commit is contained in:
23rd 2020-07-25 19:50:19 +03:00 committed by John Preston
parent 7db9843543
commit 43056107fd
7 changed files with 36 additions and 10 deletions

View File

@ -347,7 +347,9 @@ void GifsListWidget::mousePressEvent(QMouseEvent *e) {
_previewTimer.callOnce(QApplication::startDragTime());
}
void GifsListWidget::fillContextMenu(not_null<Ui::PopupMenu*> menu) {
void GifsListWidget::fillContextMenu(
not_null<Ui::PopupMenu*> menu,
SendMenuType type) {
if (_selected < 0 || _pressed >= 0) {
return;
}
@ -362,13 +364,13 @@ void GifsListWidget::fillContextMenu(not_null<Ui::PopupMenu*> 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);
}

View File

@ -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<Ui::PopupMenu*> menu) override;
void fillContextMenu(
not_null<Ui::PopupMenu*> menu,
SendMenuType type) override;
~GifsListWidget();

View File

@ -2046,7 +2046,9 @@ QPoint StickersListWidget::buttonRippleTopLeft(int section) const {
return myrtlrect(removeButtonRect(section)).topLeft() + st::stickerPanRemoveSet.rippleAreaPosition;
}
void StickersListWidget::fillContextMenu(not_null<Ui::PopupMenu*> menu) {
void StickersListWidget::fillContextMenu(
not_null<Ui::PopupMenu*> menu,
SendMenuType type) {
auto selected = _selected;
auto &sets = shownSets();
if (!selected || _pressed) {
@ -2068,13 +2070,13 @@ void StickersListWidget::fillContextMenu(not_null<Ui::PopupMenu*> 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);
}

View File

@ -83,7 +83,9 @@ public:
std::shared_ptr<Lottie::FrameRenderer> getLottieRenderer();
void fillContextMenu(not_null<Ui::PopupMenu*> menu) override;
void fillContextMenu(
not_null<Ui::PopupMenu*> menu,
SendMenuType type) override;
~StickersListWidget();

View File

@ -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<Ui::PopupMenu>(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());

View File

@ -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<SendMenuType()> callback) {
_sendMenuType = std::move(callback);
}
// Float player interface.
bool floatPlayerHandleWheelEvent(QEvent *e);
QRect floatPlayerAvailableRect() const;
@ -219,6 +225,8 @@ private:
Fn<void(SelectorTab)> _afterShownCallback;
Fn<void(SelectorTab)> _beforeHidingCallback;
Fn<SendMenuType()> _sendMenuType;
rpl::event_stream<> _showRequests;
rpl::event_stream<> _slideFinished;
@ -251,7 +259,9 @@ public:
}
virtual void beforeHiding() {
}
virtual void fillContextMenu(not_null<Ui::PopupMenu*> menu) {
virtual void fillContextMenu(
not_null<Ui::PopupMenu*> menu,
SendMenuType type) {
}
rpl::producer<int> scrollToRequests() const;

View File

@ -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() {