mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Add mention/hashtag autocomplete to GIF caption.
This commit is contained in:
parent
632639d581
commit
86c04424f6
3 changed files with 74 additions and 4 deletions
|
@ -7,7 +7,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "boxes/send_gif_with_caption_box.h"
|
#include "boxes/send_gif_with_caption_box.h"
|
||||||
|
|
||||||
|
#include "base/event_filter.h"
|
||||||
#include "boxes/premium_preview_box.h"
|
#include "boxes/premium_preview_box.h"
|
||||||
|
#include "chat_helpers/field_autocomplete.h"
|
||||||
#include "chat_helpers/message_field.h"
|
#include "chat_helpers/message_field.h"
|
||||||
#include "chat_helpers/tabbed_panel.h"
|
#include "chat_helpers/tabbed_panel.h"
|
||||||
#include "chat_helpers/tabbed_selector.h"
|
#include "chat_helpers/tabbed_selector.h"
|
||||||
|
@ -30,9 +32,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/controls/emoji_button.h"
|
#include "ui/controls/emoji_button.h"
|
||||||
#include "ui/controls/emoji_button_factory.h"
|
#include "ui/controls/emoji_button_factory.h"
|
||||||
#include "ui/layers/generic_box.h"
|
#include "ui/layers/generic_box.h"
|
||||||
#include "ui/rect.h"
|
|
||||||
#include "ui/vertical_list.h"
|
|
||||||
#include "ui/widgets/fields/input_field.h"
|
#include "ui/widgets/fields/input_field.h"
|
||||||
|
#include "ui/rect.h"
|
||||||
|
#include "ui/ui_utility.h"
|
||||||
|
#include "ui/vertical_list.h"
|
||||||
#include "window/window_controller.h"
|
#include "window/window_controller.h"
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
#include "styles/style_boxes.h"
|
#include "styles/style_boxes.h"
|
||||||
|
@ -226,6 +229,7 @@ namespace {
|
||||||
void SendGifWithCaptionBox(
|
void SendGifWithCaptionBox(
|
||||||
not_null<Ui::GenericBox*> box,
|
not_null<Ui::GenericBox*> box,
|
||||||
not_null<DocumentData*> document,
|
not_null<DocumentData*> document,
|
||||||
|
not_null<PeerData*> peer,
|
||||||
const SendMenu::Details &details,
|
const SendMenu::Details &details,
|
||||||
Fn<void(Api::SendOptions, TextWithTags)> done) {
|
Fn<void(Api::SendOptions, TextWithTags)> done) {
|
||||||
const auto window = Core::App().findWindow(box);
|
const auto window = Core::App().findWindow(box);
|
||||||
|
@ -255,6 +259,61 @@ void SendGifWithCaptionBox(
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const auto sendMenuDetails = [=] { return details; };
|
||||||
|
struct Autocomplete {
|
||||||
|
std::unique_ptr<ChatHelpers::FieldAutocomplete> dropdown;
|
||||||
|
bool geometryUpdateScheduled = false;
|
||||||
|
};
|
||||||
|
const auto autocomplete = box->lifetime().make_state<Autocomplete>();
|
||||||
|
const auto outer = box->getDelegate()->outerContainer();
|
||||||
|
ChatHelpers::InitFieldAutocomplete(autocomplete->dropdown, {
|
||||||
|
.parent = outer,
|
||||||
|
.show = controller->uiShow(),
|
||||||
|
.field = input,
|
||||||
|
.peer = peer,
|
||||||
|
.features = [=] {
|
||||||
|
auto result = ChatHelpers::ComposeFeatures();
|
||||||
|
result.autocompleteCommands = false;
|
||||||
|
result.suggestStickersByEmoji = false;
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
.sendMenuDetails = sendMenuDetails,
|
||||||
|
});
|
||||||
|
const auto raw = autocomplete->dropdown.get();
|
||||||
|
const auto recountPostponed = [=] {
|
||||||
|
if (autocomplete->geometryUpdateScheduled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
autocomplete->geometryUpdateScheduled = true;
|
||||||
|
Ui::PostponeCall(raw, [=] {
|
||||||
|
autocomplete->geometryUpdateScheduled = false;
|
||||||
|
|
||||||
|
const auto from = input->parentWidget();
|
||||||
|
auto field = Ui::MapFrom(outer, from, input->geometry());
|
||||||
|
const auto &st = st::defaultComposeFiles;
|
||||||
|
autocomplete->dropdown->setBoundings(QRect(
|
||||||
|
field.x() - input->x(),
|
||||||
|
st::defaultBox.margin.top(),
|
||||||
|
input->width(),
|
||||||
|
(field.y()
|
||||||
|
+ st.caption.textMargins.top()
|
||||||
|
+ st.caption.placeholderShift
|
||||||
|
+ st.caption.placeholderFont->height
|
||||||
|
- st::defaultBox.margin.top())));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
for (auto w = (QWidget*)input; w; w = w->parentWidget()) {
|
||||||
|
base::install_event_filter(raw, w, [=](not_null<QEvent*> e) {
|
||||||
|
if (e->type() == QEvent::Move || e->type() == QEvent::Resize) {
|
||||||
|
recountPostponed();
|
||||||
|
}
|
||||||
|
return base::EventFilterResult::Continue;
|
||||||
|
});
|
||||||
|
if (w == outer) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const auto send = [=](Api::SendOptions options) {
|
const auto send = [=](Api::SendOptions options) {
|
||||||
done(std::move(options), input->getTextWithTags());
|
done(std::move(options), input->getTextWithTags());
|
||||||
};
|
};
|
||||||
|
@ -264,8 +323,15 @@ void SendGifWithCaptionBox(
|
||||||
SendMenu::SetupMenuAndShortcuts(
|
SendMenu::SetupMenuAndShortcuts(
|
||||||
confirm,
|
confirm,
|
||||||
controller->uiShow(),
|
controller->uiShow(),
|
||||||
[=] { return details; },
|
sendMenuDetails,
|
||||||
SendMenu::DefaultCallback(controller->uiShow(), send));
|
SendMenu::DefaultCallback(controller->uiShow(), send));
|
||||||
|
box->setShowFinishedCallback([=] {
|
||||||
|
if (const auto raw = autocomplete->dropdown.get()) {
|
||||||
|
InvokeQueued(raw, [=] {
|
||||||
|
raw->raise();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
box->addButton(tr::lng_cancel(), [=] {
|
box->addButton(tr::lng_cancel(), [=] {
|
||||||
box->closeBox();
|
box->closeBox();
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
class PeerData;
|
||||||
class DocumentData;
|
class DocumentData;
|
||||||
|
|
||||||
namespace Api {
|
namespace Api {
|
||||||
|
@ -24,6 +25,7 @@ class GenericBox;
|
||||||
void SendGifWithCaptionBox(
|
void SendGifWithCaptionBox(
|
||||||
not_null<Ui::GenericBox*> box,
|
not_null<Ui::GenericBox*> box,
|
||||||
not_null<DocumentData*> document,
|
not_null<DocumentData*> document,
|
||||||
|
not_null<PeerData*> peer,
|
||||||
const SendMenu::Details &details,
|
const SendMenu::Details &details,
|
||||||
Fn<void(Api::SendOptions, TextWithTags)> done);
|
Fn<void(Api::SendOptions, TextWithTags)> done);
|
||||||
|
|
||||||
|
|
|
@ -409,17 +409,19 @@ base::unique_qptr<Ui::PopupMenu> GifsListWidget::fillContextMenu(
|
||||||
SendMenu::DefaultCallback(_show, send),
|
SendMenu::DefaultCallback(_show, send),
|
||||||
icons);
|
icons);
|
||||||
|
|
||||||
if (!isInlineResult) {
|
if (!isInlineResult && _inlineQueryPeer) {
|
||||||
auto done = crl::guard(this, [=](
|
auto done = crl::guard(this, [=](
|
||||||
Api::SendOptions options,
|
Api::SendOptions options,
|
||||||
TextWithTags text) {
|
TextWithTags text) {
|
||||||
selectInlineResult(selected, options, true, std::move(text));
|
selectInlineResult(selected, options, true, std::move(text));
|
||||||
});
|
});
|
||||||
const auto show = _show;
|
const auto show = _show;
|
||||||
|
const auto peer = _inlineQueryPeer;
|
||||||
menu->addAction(tr::lng_send_gif_with_caption(tr::now), [=] {
|
menu->addAction(tr::lng_send_gif_with_caption(tr::now), [=] {
|
||||||
show->show(Box(
|
show->show(Box(
|
||||||
Ui::SendGifWithCaptionBox,
|
Ui::SendGifWithCaptionBox,
|
||||||
item->getDocument(),
|
item->getDocument(),
|
||||||
|
peer,
|
||||||
copyDetails,
|
copyDetails,
|
||||||
std::move(done)));
|
std::move(done)));
|
||||||
}, &st::menuIconEdit);
|
}, &st::menuIconEdit);
|
||||||
|
|
Loading…
Add table
Reference in a new issue