2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Moved code for send context menu to namespace.

This commit is contained in:
23rd
2020-08-10 15:22:54 +03:00
committed by John Preston
parent af9440db38
commit 14cda49db2
22 changed files with 119 additions and 93 deletions

View File

@@ -16,7 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_file_origin.h"
#include "data/data_session.h"
#include "data/stickers/data_stickers.h"
#include "chat_helpers/send_context_menu.h" // FillSendMenu
#include "chat_helpers/send_context_menu.h" // SendMenu::FillSendMenu
#include "chat_helpers/stickers_lottie.h"
#include "mainwindow.h"
#include "apiwrap.h"
@@ -1022,18 +1022,18 @@ void FieldAutocompleteInner::contextMenuEvent(QContextMenuEvent *e) {
return;
}
const auto index = _sel;
const auto type = SendMenuType::Scheduled;
const auto type = SendMenu::Type::Scheduled;
const auto method = FieldAutocomplete::ChooseMethod::ByClick;
_menu = base::make_unique_q<Ui::PopupMenu>(this);
const auto send = [=](Api::SendOptions options) {
chooseAtIndex(method, index, options);
};
FillSendMenu(
SendMenu::FillSendMenu(
_menu,
[&] { return type; },
DefaultSilentCallback(send),
DefaultScheduleCallback(this, type, send));
SendMenu::DefaultSilentCallback(send),
SendMenu::DefaultScheduleCallback(this, type, send));
if (!_menu->actions().empty()) {
_menu->popup(QCursor::pos());

View File

@@ -17,7 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_photo_media.h"
#include "data/data_document_media.h"
#include "data/stickers/data_stickers.h"
#include "chat_helpers/send_context_menu.h" // FillSendMenu
#include "chat_helpers/send_context_menu.h" // SendMenu::FillSendMenu
#include "ui/widgets/buttons.h"
#include "ui/widgets/input_fields.h"
#include "ui/widgets/popup_menu.h"
@@ -365,7 +365,7 @@ void GifsListWidget::mousePressEvent(QMouseEvent *e) {
void GifsListWidget::fillContextMenu(
not_null<Ui::PopupMenu*> menu,
SendMenuType type) {
SendMenu::Type type) {
if (_selected < 0 || _pressed >= 0) {
return;
}
@@ -375,11 +375,11 @@ void GifsListWidget::fillContextMenu(
const auto send = [=](Api::SendOptions options) {
selectInlineResult(row, column, options, true);
};
FillSendMenu(
SendMenu::FillSendMenu(
menu,
[&] { return type; },
DefaultSilentCallback(send),
DefaultScheduleCallback(this, type, send));
SendMenu::DefaultSilentCallback(send),
SendMenu::DefaultScheduleCallback(this, type, send));
[&] {
const auto row = _selected / MatrixRowShift;

View File

@@ -34,7 +34,9 @@ namespace Window {
class SessionController;
} // namespace Window
enum class SendMenuType;
namespace SendMenu {
enum class Type;
} // namespace SendMenu
namespace ChatHelpers {
@@ -77,7 +79,7 @@ public:
void fillContextMenu(
not_null<Ui::PopupMenu*> menu,
SendMenuType type) override;
SendMenu::Type type) override;
~GifsListWidget();

View File

@@ -17,13 +17,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtWidgets/QApplication>
namespace SendMenu {
Fn<void()> DefaultSilentCallback(Fn<void(Api::SendOptions)> send) {
return [=] { send({ .silent = true }); };
}
Fn<void()> DefaultScheduleCallback(
not_null<Ui::RpWidget*> parent,
SendMenuType type,
Type type,
Fn<void(Api::SendOptions)> send) {
const auto weak = Ui::MakeWeak(parent);
return [=] {
@@ -38,24 +40,24 @@ Fn<void()> DefaultScheduleCallback(
FillMenuResult FillSendMenu(
not_null<Ui::PopupMenu*> menu,
Fn<SendMenuType()> type,
Fn<Type()> type,
Fn<void()> silent,
Fn<void()> schedule) {
if (!silent && !schedule) {
return FillMenuResult::None;
}
const auto now = type();
if (now == SendMenuType::Disabled
|| (!silent && now == SendMenuType::SilentOnly)) {
if (now == Type::Disabled
|| (!silent && now == Type::SilentOnly)) {
return FillMenuResult::None;
}
if (silent && now != SendMenuType::Reminder) {
if (silent && now != Type::Reminder) {
menu->addAction(tr::lng_send_silent_message(tr::now), silent);
}
if (schedule && now != SendMenuType::SilentOnly) {
if (schedule && now != Type::SilentOnly) {
menu->addAction(
(now == SendMenuType::Reminder
(now == Type::Reminder
? tr::lng_reminder_message(tr::now)
: tr::lng_schedule_message(tr::now)),
schedule);
@@ -63,9 +65,9 @@ FillMenuResult FillSendMenu(
return FillMenuResult::Success;
}
void SetupSendMenuAndShortcuts(
void SetupMenuAndShortcuts(
not_null<Ui::RpWidget*> button,
Fn<SendMenuType()> type,
Fn<Type()> type,
Fn<void()> silent,
Fn<void()> schedule) {
if (!silent && !schedule) {
@@ -93,12 +95,12 @@ void SetupSendMenuAndShortcuts(
using Command = Shortcuts::Command;
const auto now = type();
if (now == SendMenuType::Disabled
|| (!silent && now == SendMenuType::SilentOnly)) {
if (now == Type::Disabled
|| (!silent && now == Type::SilentOnly)) {
return;
}
(silent
&& (now != SendMenuType::Reminder)
&& (now != Type::Reminder)
&& request->check(Command::SendSilentMessage)
&& request->handle([=] {
silent();
@@ -106,7 +108,7 @@ void SetupSendMenuAndShortcuts(
}))
||
(schedule
&& (now != SendMenuType::SilentOnly)
&& (now != Type::SilentOnly)
&& request->check(Command::ScheduleMessage)
&& request->handle([=] {
schedule();
@@ -130,3 +132,5 @@ void SetupSendMenuAndShortcuts(
}));
}, button->lifetime());
}
} // namespace SendMenu

View File

@@ -17,7 +17,9 @@ namespace Ui {
class PopupMenu;
} // namespace Ui
enum class SendMenuType {
namespace SendMenu {
enum class Type {
Disabled,
SilentOnly,
Scheduled,
@@ -33,17 +35,19 @@ enum class FillMenuResult {
Fn<void()> DefaultSilentCallback(Fn<void(Api::SendOptions)> send);
Fn<void()> DefaultScheduleCallback(
not_null<Ui::RpWidget*> parent,
SendMenuType type,
Type type,
Fn<void(Api::SendOptions)> send);
FillMenuResult FillSendMenu(
not_null<Ui::PopupMenu*> menu,
Fn<SendMenuType()> type,
Fn<Type()> type,
Fn<void()> silent,
Fn<void()> schedule);
void SetupSendMenuAndShortcuts(
void SetupMenuAndShortcuts(
not_null<Ui::RpWidget*> button,
Fn<SendMenuType()> type,
Fn<Type()> type,
Fn<void()> silent,
Fn<void()> schedule);
} // namespace SendMenu

View File

@@ -14,7 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_file_origin.h"
#include "data/data_cloud_file.h"
#include "data/data_changes.h"
#include "chat_helpers/send_context_menu.h" // FillSendMenu
#include "chat_helpers/send_context_menu.h" // SendMenu::FillSendMenu
#include "chat_helpers/stickers_lottie.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/popup_menu.h"
@@ -2055,7 +2055,7 @@ void StickersListWidget::showStickerSetBox(not_null<DocumentData*> document) {
void StickersListWidget::fillContextMenu(
not_null<Ui::PopupMenu*> menu,
SendMenuType type) {
SendMenu::Type type) {
auto selected = _selected;
auto &sets = shownSets();
if (!selected || _pressed) {
@@ -2072,11 +2072,11 @@ void StickersListWidget::fillContextMenu(
.document = document,
.options = options });
};
FillSendMenu(
SendMenu::FillSendMenu(
menu,
[&] { return type; },
DefaultSilentCallback(send),
DefaultScheduleCallback(this, type, send));
SendMenu::DefaultSilentCallback(send),
SendMenu::DefaultScheduleCallback(this, type, send));
const auto toggleFavedSticker = [=] {
document->session().api().toggleFavedSticker(

View File

@@ -85,7 +85,7 @@ public:
void fillContextMenu(
not_null<Ui::PopupMenu*> menu,
SendMenuType type) override;
SendMenu::Type type) override;
~StickersListWidget();

View File

@@ -880,7 +880,7 @@ void TabbedSelector::contextMenuEvent(QContextMenuEvent *e) {
_menu = base::make_unique_q<Ui::PopupMenu>(this);
const auto type = _sendMenuType
? _sendMenuType()
: SendMenuType::Disabled;
: SendMenu::Type::Disabled;
currentTab()->widget()->fillContextMenu(_menu, type);
if (!_menu->actions().empty()) {

View File

@@ -34,7 +34,9 @@ namespace Window {
class SessionController;
} // namespace Window
enum class SendMenuType;
namespace SendMenu {
enum class Type;
} // namespace SendMenu
namespace ChatHelpers {
@@ -111,7 +113,7 @@ public:
_beforeHidingCallback = std::move(callback);
}
void setSendMenuType(Fn<SendMenuType()> callback) {
void setSendMenuType(Fn<SendMenu::Type()> callback) {
_sendMenuType = std::move(callback);
}
@@ -230,7 +232,7 @@ private:
Fn<void(SelectorTab)> _afterShownCallback;
Fn<void(SelectorTab)> _beforeHidingCallback;
Fn<SendMenuType()> _sendMenuType;
Fn<SendMenu::Type()> _sendMenuType;
rpl::event_stream<> _showRequests;
rpl::event_stream<> _slideFinished;
@@ -266,7 +268,7 @@ public:
}
virtual void fillContextMenu(
not_null<Ui::PopupMenu*> menu,
SendMenuType type) {
SendMenu::Type type) {
}
rpl::producer<int> scrollToRequests() const;