mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Moved code for send context menu to separate file.
This commit is contained in:
parent
1fee7d1a41
commit
edceed28d7
16 changed files with 163 additions and 121 deletions
|
@ -340,6 +340,8 @@ PRIVATE
|
|||
chat_helpers/gifs_list_widget.h
|
||||
chat_helpers/message_field.cpp
|
||||
chat_helpers/message_field.h
|
||||
chat_helpers/send_context_menu.cpp
|
||||
chat_helpers/send_context_menu.h
|
||||
chat_helpers/spellchecker_common.cpp
|
||||
chat_helpers/spellchecker_common.h
|
||||
chat_helpers/stickers_emoji_image_loader.cpp
|
||||
|
|
|
@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "core/core_settings.h"
|
||||
#include "chat_helpers/emoji_suggestions_widget.h"
|
||||
#include "chat_helpers/message_field.h"
|
||||
#include "chat_helpers/send_context_menu.h"
|
||||
#include "history/view/history_view_schedule_box.h"
|
||||
#include "settings/settings_common.h"
|
||||
#include "base/unique_qptr.h"
|
||||
|
|
|
@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "main/main_session.h"
|
||||
#include "mtproto/mtproto_config.h"
|
||||
#include "chat_helpers/message_field.h"
|
||||
#include "chat_helpers/send_context_menu.h"
|
||||
#include "chat_helpers/emoji_suggestions_widget.h"
|
||||
#include "chat_helpers/tabbed_panel.h"
|
||||
#include "chat_helpers/tabbed_selector.h"
|
||||
|
|
|
@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/wrap/slide_wrap.h"
|
||||
#include "ui/text_options.h"
|
||||
#include "chat_helpers/message_field.h"
|
||||
#include "chat_helpers/send_context_menu.h"
|
||||
#include "history/history.h"
|
||||
#include "history/history_message.h"
|
||||
#include "history/view/history_view_schedule_box.h"
|
||||
|
|
|
@ -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/message_field.h" // FillSendMenu
|
||||
#include "chat_helpers/send_context_menu.h" // FillSendMenu
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/input_fields.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
|
|
|
@ -685,97 +685,3 @@ void MessageLinksParser::apply(
|
|||
}
|
||||
_list = std::move(parsed);
|
||||
}
|
||||
|
||||
bool FillSendMenu(
|
||||
not_null<Ui::PopupMenu*> menu,
|
||||
Fn<SendMenuType()> type,
|
||||
Fn<void()> silent,
|
||||
Fn<void()> schedule) {
|
||||
if (!silent && !schedule) {
|
||||
return false;
|
||||
}
|
||||
const auto now = type();
|
||||
if (now == SendMenuType::Disabled
|
||||
|| (!silent && now == SendMenuType::SilentOnly)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (silent && now != SendMenuType::Reminder) {
|
||||
menu->addAction(tr::lng_send_silent_message(tr::now), silent);
|
||||
}
|
||||
if (schedule && now != SendMenuType::SilentOnly) {
|
||||
menu->addAction(
|
||||
(now == SendMenuType::Reminder
|
||||
? tr::lng_reminder_message(tr::now)
|
||||
: tr::lng_schedule_message(tr::now)),
|
||||
schedule);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void SetupSendMenuAndShortcuts(
|
||||
not_null<Ui::RpWidget*> button,
|
||||
Fn<SendMenuType()> type,
|
||||
Fn<void()> silent,
|
||||
Fn<void()> schedule) {
|
||||
if (!silent && !schedule) {
|
||||
return;
|
||||
}
|
||||
const auto menu = std::make_shared<base::unique_qptr<Ui::PopupMenu>>();
|
||||
const auto showMenu = [=] {
|
||||
*menu = base::make_unique_q<Ui::PopupMenu>(button);
|
||||
const auto success = FillSendMenu(*menu, type, silent, schedule);
|
||||
if (success) {
|
||||
(*menu)->popup(QCursor::pos());
|
||||
}
|
||||
return success;
|
||||
};
|
||||
base::install_event_filter(button, [=](not_null<QEvent*> e) {
|
||||
if (e->type() == QEvent::ContextMenu && showMenu()) {
|
||||
return base::EventFilterResult::Cancel;
|
||||
}
|
||||
return base::EventFilterResult::Continue;
|
||||
});
|
||||
|
||||
Shortcuts::Requests(
|
||||
) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
|
||||
using Command = Shortcuts::Command;
|
||||
|
||||
const auto now = type();
|
||||
if (now == SendMenuType::Disabled
|
||||
|| (!silent && now == SendMenuType::SilentOnly)) {
|
||||
return;
|
||||
}
|
||||
(silent
|
||||
&& (now != SendMenuType::Reminder)
|
||||
&& request->check(Command::SendSilentMessage)
|
||||
&& request->handle([=] {
|
||||
silent();
|
||||
return true;
|
||||
}))
|
||||
||
|
||||
(schedule
|
||||
&& (now != SendMenuType::SilentOnly)
|
||||
&& request->check(Command::ScheduleMessage)
|
||||
&& request->handle([=] {
|
||||
schedule();
|
||||
return true;
|
||||
}))
|
||||
||
|
||||
(request->check(Command::JustSendMessage) && request->handle([=] {
|
||||
const auto post = [&](QEvent::Type type) {
|
||||
QApplication::postEvent(
|
||||
button,
|
||||
new QMouseEvent(
|
||||
type,
|
||||
QPointF(0, 0),
|
||||
Qt::LeftButton,
|
||||
Qt::LeftButton,
|
||||
Qt::NoModifier));
|
||||
};
|
||||
post(QEvent::MouseButtonPress);
|
||||
post(QEvent::MouseButtonRelease);
|
||||
return true;
|
||||
}));
|
||||
}, button->lifetime());
|
||||
}
|
||||
|
|
|
@ -101,23 +101,3 @@ private:
|
|||
base::qt_connection _connection;
|
||||
|
||||
};
|
||||
|
||||
enum class SendMenuType {
|
||||
Disabled,
|
||||
SilentOnly,
|
||||
Scheduled,
|
||||
ScheduledToUser, // For "Send when online".
|
||||
Reminder,
|
||||
};
|
||||
|
||||
bool FillSendMenu(
|
||||
not_null<Ui::PopupMenu*> menu,
|
||||
Fn<SendMenuType()> type,
|
||||
Fn<void()> silent,
|
||||
Fn<void()> schedule);
|
||||
|
||||
void SetupSendMenuAndShortcuts(
|
||||
not_null<Ui::RpWidget*> button,
|
||||
Fn<SendMenuType()> type,
|
||||
Fn<void()> silent,
|
||||
Fn<void()> schedule);
|
||||
|
|
111
Telegram/SourceFiles/chat_helpers/send_context_menu.cpp
Normal file
111
Telegram/SourceFiles/chat_helpers/send_context_menu.cpp
Normal file
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "chat_helpers/send_context_menu.h"
|
||||
|
||||
#include "api/api_common.h"
|
||||
#include "base/event_filter.h"
|
||||
#include "core/shortcuts.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
|
||||
#include <QtWidgets/QApplication>
|
||||
|
||||
FillMenuResult FillSendMenu(
|
||||
not_null<Ui::PopupMenu*> menu,
|
||||
Fn<SendMenuType()> 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)) {
|
||||
return FillMenuResult::None;
|
||||
}
|
||||
|
||||
if (silent && now != SendMenuType::Reminder) {
|
||||
menu->addAction(tr::lng_send_silent_message(tr::now), silent);
|
||||
}
|
||||
if (schedule && now != SendMenuType::SilentOnly) {
|
||||
menu->addAction(
|
||||
(now == SendMenuType::Reminder
|
||||
? tr::lng_reminder_message(tr::now)
|
||||
: tr::lng_schedule_message(tr::now)),
|
||||
schedule);
|
||||
}
|
||||
return FillMenuResult::Success;
|
||||
}
|
||||
|
||||
void SetupSendMenuAndShortcuts(
|
||||
not_null<Ui::RpWidget*> button,
|
||||
Fn<SendMenuType()> type,
|
||||
Fn<void()> silent,
|
||||
Fn<void()> schedule) {
|
||||
if (!silent && !schedule) {
|
||||
return;
|
||||
}
|
||||
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 success = (result == FillMenuResult::Success);
|
||||
if (success) {
|
||||
(*menu)->popup(QCursor::pos());
|
||||
}
|
||||
return success;
|
||||
};
|
||||
base::install_event_filter(button, [=](not_null<QEvent*> e) {
|
||||
if (e->type() == QEvent::ContextMenu && showMenu()) {
|
||||
return base::EventFilterResult::Cancel;
|
||||
}
|
||||
return base::EventFilterResult::Continue;
|
||||
});
|
||||
|
||||
Shortcuts::Requests(
|
||||
) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
|
||||
using Command = Shortcuts::Command;
|
||||
|
||||
const auto now = type();
|
||||
if (now == SendMenuType::Disabled
|
||||
|| (!silent && now == SendMenuType::SilentOnly)) {
|
||||
return;
|
||||
}
|
||||
(silent
|
||||
&& (now != SendMenuType::Reminder)
|
||||
&& request->check(Command::SendSilentMessage)
|
||||
&& request->handle([=] {
|
||||
silent();
|
||||
return true;
|
||||
}))
|
||||
||
|
||||
(schedule
|
||||
&& (now != SendMenuType::SilentOnly)
|
||||
&& request->check(Command::ScheduleMessage)
|
||||
&& request->handle([=] {
|
||||
schedule();
|
||||
return true;
|
||||
}))
|
||||
||
|
||||
(request->check(Command::JustSendMessage) && request->handle([=] {
|
||||
const auto post = [&](QEvent::Type type) {
|
||||
QApplication::postEvent(
|
||||
button,
|
||||
new QMouseEvent(
|
||||
type,
|
||||
QPointF(0, 0),
|
||||
Qt::LeftButton,
|
||||
Qt::LeftButton,
|
||||
Qt::NoModifier));
|
||||
};
|
||||
post(QEvent::MouseButtonPress);
|
||||
post(QEvent::MouseButtonRelease);
|
||||
return true;
|
||||
}));
|
||||
}, button->lifetime());
|
||||
}
|
39
Telegram/SourceFiles/chat_helpers/send_context_menu.h
Normal file
39
Telegram/SourceFiles/chat_helpers/send_context_menu.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "ui/rp_widget.h"
|
||||
|
||||
namespace Ui {
|
||||
class PopupMenu;
|
||||
} // namespace Ui
|
||||
|
||||
enum class SendMenuType {
|
||||
Disabled,
|
||||
SilentOnly,
|
||||
Scheduled,
|
||||
ScheduledToUser, // For "Send when online".
|
||||
Reminder,
|
||||
};
|
||||
|
||||
enum class FillMenuResult {
|
||||
Success,
|
||||
None,
|
||||
};
|
||||
|
||||
FillMenuResult FillSendMenu(
|
||||
not_null<Ui::PopupMenu*> menu,
|
||||
Fn<SendMenuType()> type,
|
||||
Fn<void()> silent,
|
||||
Fn<void()> schedule);
|
||||
|
||||
void SetupSendMenuAndShortcuts(
|
||||
not_null<Ui::RpWidget*> button,
|
||||
Fn<SendMenuType()> type,
|
||||
Fn<void()> silent,
|
||||
Fn<void()> schedule);
|
|
@ -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/message_field.h" // FillSendMenu
|
||||
#include "chat_helpers/send_context_menu.h" // FillSendMenu
|
||||
#include "chat_helpers/stickers_lottie.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
|
|
|
@ -7,10 +7,10 @@ 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"
|
||||
#include "chat_helpers/send_context_menu.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
#include "ui/widgets/shadow.h"
|
||||
|
|
|
@ -69,6 +69,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "chat_helpers/tabbed_section.h"
|
||||
#include "chat_helpers/bot_keyboard.h"
|
||||
#include "chat_helpers/message_field.h"
|
||||
#include "chat_helpers/send_context_menu.h"
|
||||
#include "platform/platform_specific.h"
|
||||
#include "mtproto/mtproto_config.h"
|
||||
#include "lang/lang_keys.h"
|
||||
|
|
|
@ -22,7 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/image/image.h"
|
||||
#include "ui/toast/toast.h"
|
||||
#include "ui/ui_utility.h"
|
||||
#include "chat_helpers/message_field.h"
|
||||
#include "chat_helpers/send_context_menu.h"
|
||||
#include "boxes/confirm_box.h"
|
||||
#include "boxes/sticker_set_box.h"
|
||||
#include "data/data_photo.h"
|
||||
|
|
|
@ -20,7 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
#include "ui/wrap/padding_wrap.h"
|
||||
#include "chat_helpers/message_field.h"
|
||||
#include "chat_helpers/send_context_menu.h"
|
||||
#include "styles/style_info.h"
|
||||
#include "styles/style_layers.h"
|
||||
#include "styles/style_history.h"
|
||||
|
|
|
@ -14,7 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "history/history.h"
|
||||
#include "history/history_drag_area.h"
|
||||
#include "history/history_item.h"
|
||||
#include "chat_helpers/message_field.h" // SendMenuType.
|
||||
#include "chat_helpers/send_context_menu.h" // SendMenuType.
|
||||
#include "ui/widgets/scroll_area.h"
|
||||
#include "ui/widgets/shadow.h"
|
||||
#include "ui/layers/generic_box.h"
|
||||
|
|
|
@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "inline_bots/inline_results_widget.h"
|
||||
|
||||
#include "api/api_common.h"
|
||||
#include "chat_helpers/message_field.h" // FillSendMenu
|
||||
#include "chat_helpers/send_context_menu.h" // FillSendMenu
|
||||
#include "data/data_photo.h"
|
||||
#include "data/data_document.h"
|
||||
#include "data/data_channel.h"
|
||||
|
|
Loading…
Add table
Reference in a new issue