diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index 5d4badd36..b843c80aa 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -13,7 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/qthelp_regex.h" #include "base/qthelp_url.h" #include "base/event_filter.h" -#include "boxes/abstract_box.h" +#include "ui/layers/generic_box.h" #include "core/shortcuts.h" #include "core/application.h" #include "core/core_settings.h" @@ -61,29 +61,6 @@ private: }; -class EditLinkBox : public Ui::BoxContent { -public: - EditLinkBox( - QWidget*, - not_null controller, - const QString &text, - const QString &link, - Fn callback); - - void setInnerFocus() override; - -protected: - void prepare() override; - -private: - const not_null _controller; - QString _startText; - QString _startLink; - Fn _callback; - Fn _setInnerFocus; - -}; - FieldTagMimeProcessor::FieldTagMimeProcessor( not_null controller) : _controller(controller) { @@ -112,44 +89,32 @@ QString FieldTagMimeProcessor::tagFromMimeTag(const QString &mimeTag) { // && IsGoodProtocol(protocolMatch.captured(1)); //} -EditLinkBox::EditLinkBox( - QWidget*, - not_null controller, - const QString &text, - const QString &link, - Fn callback) -: _controller(controller) -, _startText(text) -, _startLink(link) -, _callback(std::move(callback)) { - Expects(_callback != nullptr); -} +void EditLinkBox( + not_null box, + std::shared_ptr show, + not_null session, + const QString &startText, + const QString &startLink, + Fn callback) { + Expects(callback != nullptr); -void EditLinkBox::setInnerFocus() { - Expects(_setInnerFocus != nullptr); + const auto content = box->verticalLayout(); - _setInnerFocus(); -} - -void EditLinkBox::prepare() { - const auto content = Ui::CreateChild(this); - - const auto session = &_controller->session(); const auto text = content->add( object_ptr( content, st::defaultInputField, tr::lng_formatting_link_text(), - _startText), + startText), st::markdownLinkFieldPadding); text->setInstantReplaces(Ui::InstantReplaces::Default()); text->setInstantReplacesEnabled( Core::App().settings().replaceEmojiValue()); Ui::Emoji::SuggestionsController::Init( - getDelegate()->outerContainer(), + box->getDelegate()->outerContainer(), text, session); - InitSpellchecker(_controller, text); + InitSpellchecker(std::move(show), session, text); const auto placeholder = content->add( object_ptr(content), @@ -157,11 +122,11 @@ void EditLinkBox::prepare() { placeholder->setAttribute(Qt::WA_TransparentForMouseEvents); const auto url = Ui::AttachParentChild( content, - object_ptr( + object_ptr( content, st::defaultInputField, tr::lng_formatting_link_url(), - _startLink.trimmed())); + startLink.trimmed())); url->heightValue( ) | rpl::start_with_next([placeholder](int height) { placeholder->resize(placeholder->width(), height); @@ -182,17 +147,17 @@ void EditLinkBox::prepare() { url->showError(); return; } - const auto weak = Ui::MakeWeak(this); - _callback(linkText, linkUrl); + const auto weak = Ui::MakeWeak(box); + callback(linkText, linkUrl); if (weak) { - closeBox(); + box->closeBox(); } }; - connect(text, &Ui::InputField::submitted, [=] { + QObject::connect(text, &Ui::InputField::submitted, [=] { url->setFocusFast(); }); - connect(url, &Ui::MaskedInputField::submitted, [=] { + QObject::connect(url, &Ui::InputField::submitted, [=] { if (text->getLastText().isEmpty()) { text->setFocusFast(); } else { @@ -200,24 +165,30 @@ void EditLinkBox::prepare() { } }); - setTitle(url->getLastText().isEmpty() + box->setTitle(url->getLastText().isEmpty() ? tr::lng_formatting_link_create_title() : tr::lng_formatting_link_edit_title()); - addButton(tr::lng_formatting_link_create(), submit); - addButton(tr::lng_cancel(), [=] { closeBox(); }); + box->addButton(tr::lng_formatting_link_create(), submit); + box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); content->resizeToWidth(st::boxWidth); content->moveToLeft(0, 0); - setDimensions(st::boxWidth, content->height()); + box->setWidth(st::boxWidth); - _setInnerFocus = [=] { - if (_startText.isEmpty()) { + box->setFocusCallback([=] { + if (startText.isEmpty()) { text->setFocusFast(); } else { url->setFocusFast(); } - }; + }); + + url->customTab(true); + text->customTab(true); + + QObject::connect(url, &Ui::InputField::tabbed, [=] { text->setFocus(); }); + QObject::connect(text, &Ui::InputField::tabbed, [=] { url->setFocus(); }); } TextWithEntities StripSupportHashtag(TextWithEntities &&text) { @@ -282,13 +253,20 @@ Fnshow(Box(controller, text, link, [=]( - const QString &text, - const QString &link) { + auto callback = [=](const QString &text, const QString &link) { if (const auto strong = weak.data()) { strong->commitMarkdownLinkEdit(selection, text, link); } - }), Ui::LayerOption::KeepOther); + }; + controller->show( + Box( + EditLinkBox, + std::make_shared(controller), + &controller->session(), + text, + link, + std::move(callback)), + Ui::LayerOption::KeepOther); return true; }; }