mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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_regex.h"
|
||||||
#include "base/qthelp_url.h"
|
#include "base/qthelp_url.h"
|
||||||
#include "base/event_filter.h"
|
#include "base/event_filter.h"
|
||||||
#include "boxes/abstract_box.h"
|
#include "ui/layers/generic_box.h"
|
||||||
#include "core/shortcuts.h"
|
#include "core/shortcuts.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "core/core_settings.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(
|
FieldTagMimeProcessor::FieldTagMimeProcessor(
|
||||||
not_null<Window::SessionController*> controller)
|
not_null<Window::SessionController*> controller)
|
||||||
: _controller(controller) {
|
: _controller(controller) {
|
||||||
|
@ -112,44 +89,32 @@ QString FieldTagMimeProcessor::tagFromMimeTag(const QString &mimeTag) {
|
||||||
// && IsGoodProtocol(protocolMatch.captured(1));
|
// && IsGoodProtocol(protocolMatch.captured(1));
|
||||||
//}
|
//}
|
||||||
|
|
||||||
EditLinkBox::EditLinkBox(
|
void EditLinkBox(
|
||||||
QWidget*,
|
not_null<Ui::GenericBox*> box,
|
||||||
not_null<Window::SessionController*> controller,
|
std::shared_ptr<Ui::Show> show,
|
||||||
const QString &text,
|
not_null<Main::Session*> session,
|
||||||
const QString &link,
|
const QString &startText,
|
||||||
Fn<void(QString, QString)> callback)
|
const QString &startLink,
|
||||||
: _controller(controller)
|
Fn<void(QString, QString)> callback) {
|
||||||
, _startText(text)
|
Expects(callback != nullptr);
|
||||||
, _startLink(link)
|
|
||||||
, _callback(std::move(callback)) {
|
|
||||||
Expects(_callback != nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void EditLinkBox::setInnerFocus() {
|
const auto content = box->verticalLayout();
|
||||||
Expects(_setInnerFocus != nullptr);
|
|
||||||
|
|
||||||
_setInnerFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
void EditLinkBox::prepare() {
|
|
||||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
|
||||||
|
|
||||||
const auto session = &_controller->session();
|
|
||||||
const auto text = content->add(
|
const auto text = content->add(
|
||||||
object_ptr<Ui::InputField>(
|
object_ptr<Ui::InputField>(
|
||||||
content,
|
content,
|
||||||
st::defaultInputField,
|
st::defaultInputField,
|
||||||
tr::lng_formatting_link_text(),
|
tr::lng_formatting_link_text(),
|
||||||
_startText),
|
startText),
|
||||||
st::markdownLinkFieldPadding);
|
st::markdownLinkFieldPadding);
|
||||||
text->setInstantReplaces(Ui::InstantReplaces::Default());
|
text->setInstantReplaces(Ui::InstantReplaces::Default());
|
||||||
text->setInstantReplacesEnabled(
|
text->setInstantReplacesEnabled(
|
||||||
Core::App().settings().replaceEmojiValue());
|
Core::App().settings().replaceEmojiValue());
|
||||||
Ui::Emoji::SuggestionsController::Init(
|
Ui::Emoji::SuggestionsController::Init(
|
||||||
getDelegate()->outerContainer(),
|
box->getDelegate()->outerContainer(),
|
||||||
text,
|
text,
|
||||||
session);
|
session);
|
||||||
InitSpellchecker(_controller, text);
|
InitSpellchecker(std::move(show), session, text);
|
||||||
|
|
||||||
const auto placeholder = content->add(
|
const auto placeholder = content->add(
|
||||||
object_ptr<Ui::RpWidget>(content),
|
object_ptr<Ui::RpWidget>(content),
|
||||||
|
@ -157,11 +122,11 @@ void EditLinkBox::prepare() {
|
||||||
placeholder->setAttribute(Qt::WA_TransparentForMouseEvents);
|
placeholder->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
const auto url = Ui::AttachParentChild(
|
const auto url = Ui::AttachParentChild(
|
||||||
content,
|
content,
|
||||||
object_ptr<Ui::MaskedInputField>(
|
object_ptr<Ui::InputField>(
|
||||||
content,
|
content,
|
||||||
st::defaultInputField,
|
st::defaultInputField,
|
||||||
tr::lng_formatting_link_url(),
|
tr::lng_formatting_link_url(),
|
||||||
_startLink.trimmed()));
|
startLink.trimmed()));
|
||||||
url->heightValue(
|
url->heightValue(
|
||||||
) | rpl::start_with_next([placeholder](int height) {
|
) | rpl::start_with_next([placeholder](int height) {
|
||||||
placeholder->resize(placeholder->width(), height);
|
placeholder->resize(placeholder->width(), height);
|
||||||
|
@ -182,17 +147,17 @@ void EditLinkBox::prepare() {
|
||||||
url->showError();
|
url->showError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto weak = Ui::MakeWeak(this);
|
const auto weak = Ui::MakeWeak(box);
|
||||||
_callback(linkText, linkUrl);
|
callback(linkText, linkUrl);
|
||||||
if (weak) {
|
if (weak) {
|
||||||
closeBox();
|
box->closeBox();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
connect(text, &Ui::InputField::submitted, [=] {
|
QObject::connect(text, &Ui::InputField::submitted, [=] {
|
||||||
url->setFocusFast();
|
url->setFocusFast();
|
||||||
});
|
});
|
||||||
connect(url, &Ui::MaskedInputField::submitted, [=] {
|
QObject::connect(url, &Ui::InputField::submitted, [=] {
|
||||||
if (text->getLastText().isEmpty()) {
|
if (text->getLastText().isEmpty()) {
|
||||||
text->setFocusFast();
|
text->setFocusFast();
|
||||||
} else {
|
} 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_create_title()
|
||||||
: tr::lng_formatting_link_edit_title());
|
: tr::lng_formatting_link_edit_title());
|
||||||
|
|
||||||
addButton(tr::lng_formatting_link_create(), submit);
|
box->addButton(tr::lng_formatting_link_create(), submit);
|
||||||
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
||||||
|
|
||||||
content->resizeToWidth(st::boxWidth);
|
content->resizeToWidth(st::boxWidth);
|
||||||
content->moveToLeft(0, 0);
|
content->moveToLeft(0, 0);
|
||||||
setDimensions(st::boxWidth, content->height());
|
box->setWidth(st::boxWidth);
|
||||||
|
|
||||||
_setInnerFocus = [=] {
|
box->setFocusCallback([=] {
|
||||||
if (_startText.isEmpty()) {
|
if (startText.isEmpty()) {
|
||||||
text->setFocusFast();
|
text->setFocusFast();
|
||||||
} else {
|
} else {
|
||||||
url->setFocusFast();
|
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) {
|
TextWithEntities StripSupportHashtag(TextWithEntities &&text) {
|
||||||
|
@ -282,13 +253,20 @@ Fn<bool(
|
||||||
return Ui::InputField::IsValidMarkdownLink(link)
|
return Ui::InputField::IsValidMarkdownLink(link)
|
||||||
&& !TextUtilities::IsMentionLink(link);
|
&& !TextUtilities::IsMentionLink(link);
|
||||||
}
|
}
|
||||||
controller->show(Box<EditLinkBox>(controller, text, link, [=](
|
auto callback = [=](const QString &text, const QString &link) {
|
||||||
const QString &text,
|
|
||||||
const QString &link) {
|
|
||||||
if (const auto strong = weak.data()) {
|
if (const auto strong = weak.data()) {
|
||||||
strong->commitMarkdownLinkEdit(selection, text, link);
|
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;
|
return true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue