mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Replaced EditLinkBox with generic box.
This commit is contained in:
parent
5e13949eda
commit
b5aafa521a
1 changed files with 44 additions and 66 deletions
|
@ -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<Window::SessionController*> controller,
|
||||
const QString &text,
|
||||
const QString &link,
|
||||
Fn<void(QString, QString)> callback);
|
||||
|
||||
void setInnerFocus() override;
|
||||
|
||||
protected:
|
||||
void prepare() override;
|
||||
|
||||
private:
|
||||
const not_null<Window::SessionController*> _controller;
|
||||
QString _startText;
|
||||
QString _startLink;
|
||||
Fn<void(QString, QString)> _callback;
|
||||
Fn<void()> _setInnerFocus;
|
||||
|
||||
};
|
||||
|
||||
FieldTagMimeProcessor::FieldTagMimeProcessor(
|
||||
not_null<Window::SessionController*> controller)
|
||||
: _controller(controller) {
|
||||
|
@ -112,44 +89,32 @@ QString FieldTagMimeProcessor::tagFromMimeTag(const QString &mimeTag) {
|
|||
// && IsGoodProtocol(protocolMatch.captured(1));
|
||||
//}
|
||||
|
||||
EditLinkBox::EditLinkBox(
|
||||
QWidget*,
|
||||
not_null<Window::SessionController*> controller,
|
||||
const QString &text,
|
||||
const QString &link,
|
||||
Fn<void(QString, QString)> callback)
|
||||
: _controller(controller)
|
||||
, _startText(text)
|
||||
, _startLink(link)
|
||||
, _callback(std::move(callback)) {
|
||||
Expects(_callback != nullptr);
|
||||
}
|
||||
void EditLinkBox(
|
||||
not_null<Ui::GenericBox*> box,
|
||||
std::shared_ptr<Ui::Show> show,
|
||||
not_null<Main::Session*> session,
|
||||
const QString &startText,
|
||||
const QString &startLink,
|
||||
Fn<void(QString, QString)> callback) {
|
||||
Expects(callback != nullptr);
|
||||
|
||||
void EditLinkBox::setInnerFocus() {
|
||||
Expects(_setInnerFocus != nullptr);
|
||||
const auto content = box->verticalLayout();
|
||||
|
||||
_setInnerFocus();
|
||||
}
|
||||
|
||||
void EditLinkBox::prepare() {
|
||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
||||
|
||||
const auto session = &_controller->session();
|
||||
const auto text = content->add(
|
||||
object_ptr<Ui::InputField>(
|
||||
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<Ui::RpWidget>(content),
|
||||
|
@ -157,11 +122,11 @@ void EditLinkBox::prepare() {
|
|||
placeholder->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
const auto url = Ui::AttachParentChild(
|
||||
content,
|
||||
object_ptr<Ui::MaskedInputField>(
|
||||
object_ptr<Ui::InputField>(
|
||||
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 @@ Fn<bool(
|
|||
return Ui::InputField::IsValidMarkdownLink(link)
|
||||
&& !TextUtilities::IsMentionLink(link);
|
||||
}
|
||||
controller->show(Box<EditLinkBox>(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<Window::Show>(controller),
|
||||
&controller->session(),
|
||||
text,
|
||||
link,
|
||||
std::move(callback)),
|
||||
Ui::LayerOption::KeepOther);
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue