Slightly refactored code for menu with send options.

This commit is contained in:
23rd 2020-11-19 06:18:45 +03:00 committed by John Preston
parent e1017380ec
commit a2e4403b28
8 changed files with 15 additions and 28 deletions

View file

@ -1134,7 +1134,7 @@ void FieldAutocomplete::Inner::contextMenuEvent(QContextMenuEvent *e) {
};
SendMenu::FillSendMenu(
_menu,
[&] { return type; },
type,
SendMenu::DefaultSilentCallback(send),
SendMenu::DefaultScheduleCallback(this, type, send));

View file

@ -377,7 +377,7 @@ void GifsListWidget::fillContextMenu(
};
SendMenu::FillSendMenu(
menu,
[&] { return type; },
type,
SendMenu::DefaultSilentCallback(send),
SendMenu::DefaultScheduleCallback(this, type, send));

View file

@ -40,13 +40,13 @@ Fn<void()> DefaultScheduleCallback(
FillMenuResult FillSendMenu(
not_null<Ui::PopupMenu*> menu,
Fn<Type()> type,
Type type,
Fn<void()> silent,
Fn<void()> schedule) {
if (!silent && !schedule) {
return FillMenuResult::None;
}
const auto now = type();
const auto now = type;
if (now == Type::Disabled
|| (!silent && now == Type::SilentOnly)) {
return FillMenuResult::None;
@ -76,7 +76,7 @@ void SetupMenuAndShortcuts(
const auto menu = std::make_shared<base::unique_qptr<Ui::PopupMenu>>();
const auto showMenu = [=] {
*menu = base::make_unique_q<Ui::PopupMenu>(button);
const auto result = FillSendMenu(*menu, type, silent, schedule);
const auto result = FillSendMenu(*menu, type(), silent, schedule);
const auto success = (result == FillMenuResult::Success);
if (success) {
(*menu)->popup(QCursor::pos());

View file

@ -40,7 +40,7 @@ Fn<void()> DefaultScheduleCallback(
FillMenuResult FillSendMenu(
not_null<Ui::PopupMenu*> menu,
Fn<Type()> type,
Type type,
Fn<void()> silent,
Fn<void()> schedule);

View file

@ -2077,7 +2077,7 @@ void StickersListWidget::fillContextMenu(
};
SendMenu::FillSendMenu(
menu,
[&] { return type; },
type,
SendMenu::DefaultSilentCallback(send),
SendMenu::DefaultScheduleCallback(this, type, send));

View file

@ -109,7 +109,7 @@ public:
_beforeHidingCallback = std::move(callback);
}
void setSendMenuType(Fn<SendMenu::Type()> callback) {
void setSendMenuType(Fn<SendMenu::Type()> &&callback) {
_sendMenuType = std::move(callback);
}

View file

@ -35,7 +35,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h"
#include "history/history_item.h"
#include "history/view/controls/history_view_voice_record_bar.h"
#include "history/view/history_view_schedule_box.h" // HistoryView::PrepareScheduleBox
#include "history/view/history_view_webpage_preview.h"
#include "inline_bots/inline_results_widget.h"
#include "inline_bots/inline_bot_result.h"
@ -1419,11 +1418,15 @@ void ComposeControls::initSendButton() {
cancelInlineBot();
}, _send->lifetime());
const auto send = [=](Api::SendOptions options) {
_sendCustomRequests.fire(std::move(options));
};
SendMenu::SetupMenuAndShortcuts(
_send.get(),
[=] { return sendButtonMenuType(); },
[=] { sendSilent(); },
[=] { sendScheduled(); });
SendMenu::DefaultSilentCallback(send),
SendMenu::DefaultScheduleCallback(_wrap.get(), sendMenuType(), send));
}
void ComposeControls::inlineBotResolveDone(
@ -2119,22 +2122,6 @@ bool ComposeControls::isRecording() const {
return _voiceRecordBar->isRecording();
}
void ComposeControls::sendSilent() {
_sendCustomRequests.fire({ .silent = true });
}
void ComposeControls::sendScheduled() {
auto callback = [=](Api::SendOptions options) {
_sendCustomRequests.fire(std::move(options));
};
Ui::show(
HistoryView::PrepareScheduleBox(
_wrap.get(),
sendMenuType(),
std::move(callback)),
Ui::LayerOption::KeepOther);
}
void ComposeControls::updateInlineBotQuery() {
if (!_history) {
return;

View file

@ -301,7 +301,7 @@ void Inner::contextMenuEvent(QContextMenuEvent *e) {
};
SendMenu::FillSendMenu(
_menu,
[&] { return type; },
type,
SendMenu::DefaultSilentCallback(send),
SendMenu::DefaultScheduleCallback(this, type, send));