2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-09-05 08:55:59 +00:00

Detach ComposeControls from SessionController.

This commit is contained in:
John Preston
2023-05-02 13:33:19 +04:00
parent 665467b02d
commit 65afa2c402
178 changed files with 2080 additions and 1869 deletions

View File

@@ -125,8 +125,7 @@ QString FieldTagMimeProcessor::operator()(QStringView mimeTag) {
void EditLinkBox(
not_null<Ui::GenericBox*> box,
std::shared_ptr<Ui::Show> show,
not_null<Main::Session*> session,
std::shared_ptr<Main::SessionShow> show,
const QString &startText,
const QString &startLink,
Fn<void(QString, QString)> callback,
@@ -149,8 +148,8 @@ void EditLinkBox(
Ui::Emoji::SuggestionsController::Init(
box->getDelegate()->outerContainer(),
text,
session);
InitSpellchecker(std::move(show), session, text, fieldStyle != nullptr);
&show->session());
InitSpellchecker(show, text, fieldStyle != nullptr);
const auto placeholder = content->add(
object_ptr<Ui::RpWidget>(content),
@@ -284,8 +283,7 @@ Fn<bool(
QString text,
QString link,
EditLinkAction action)> DefaultEditLinkCallback(
std::shared_ptr<Ui::Show> show,
not_null<Main::Session*> session,
std::shared_ptr<Main::SessionShow> show,
not_null<Ui::InputField*> field,
const style::InputField *fieldStyle) {
const auto weak = Ui::MakeWeak(field);
@@ -303,23 +301,20 @@ Fn<bool(
strong->commitMarkdownLinkEdit(selection, text, link);
}
};
show->showBox(
Box(
EditLinkBox,
show,
session,
text,
link,
std::move(callback),
fieldStyle),
Ui::LayerOption::KeepOther);
show->showBox(Box(
EditLinkBox,
show,
text,
link,
std::move(callback),
fieldStyle));
return true;
};
}
void InitMessageFieldHandlers(
not_null<Main::Session*> session,
std::shared_ptr<Ui::Show> show,
std::shared_ptr<Main::SessionShow> show,
not_null<Ui::InputField*> field,
Fn<bool()> customEmojiPaused,
Fn<bool(not_null<DocumentData*>)> allowPremiumEmoji,
@@ -338,19 +333,19 @@ void InitMessageFieldHandlers(
field->setMarkdownReplacesEnabled(rpl::single(true));
if (show) {
field->setEditLinkCallback(
DefaultEditLinkCallback(show, session, field, fieldStyle));
InitSpellchecker(show, session, field, fieldStyle != nullptr);
DefaultEditLinkCallback(show, field, fieldStyle));
InitSpellchecker(show, field, fieldStyle != nullptr);
}
}
void InitMessageFieldHandlers(
not_null<Window::SessionController*> controller,
not_null<Ui::InputField*> field,
Window::GifPauseReason pauseReasonLevel,
ChatHelpers::PauseReason pauseReasonLevel,
Fn<bool(not_null<DocumentData*>)> allowPremiumEmoji) {
InitMessageFieldHandlers(
&controller->session(),
std::make_shared<Window::Show>(controller),
controller->uiShow(),
field,
[=] { return controller->isGifPausedAtLeastFor(pauseReasonLevel); },
allowPremiumEmoji);
@@ -366,25 +361,36 @@ void InitMessageFieldGeometry(not_null<Ui::InputField*> field) {
}
void InitMessageField(
not_null<Window::SessionController*> controller,
std::shared_ptr<ChatHelpers::Show> show,
not_null<Ui::InputField*> field,
Fn<bool(not_null<DocumentData*>)> allowPremiumEmoji) {
InitMessageFieldHandlers(
controller,
&show->session(),
show,
field,
Window::GifPauseReason::Any,
allowPremiumEmoji);
[=] { return show->paused(ChatHelpers::PauseReason::Any); },
std::move(allowPremiumEmoji));
InitMessageFieldGeometry(field);
field->customTab(true);
}
void InitMessageField(
not_null<Window::SessionController*> controller,
not_null<Ui::InputField*> field,
Fn<bool(not_null<DocumentData*>)> allowPremiumEmoji) {
return InitMessageField(
controller->uiShow(),
field,
std::move(allowPremiumEmoji));
}
void InitSpellchecker(
std::shared_ptr<Ui::Show> show,
not_null<Main::Session*> session,
std::shared_ptr<Main::SessionShow> show,
not_null<Ui::InputField*> field,
bool skipDictionariesManager) {
#ifndef TDESKTOP_DISABLE_SPELLCHECK
using namespace Spellchecker;
const auto session = &show->session();
const auto menuItem = skipDictionariesManager
? std::nullopt
: std::make_optional(SpellingHighlighter::CustomContextMenuItem{
@@ -856,7 +862,7 @@ base::unique_qptr<Ui::RpWidget> CreateDisabledFieldView(
*toast = Ui::Toast::Show(parent, {
.text = { tr::lng_send_text_no_about(tr::now, lt_types, types) },
.st = &st::defaultMultilineToast,
.durationMs = kTypesDuration,
.duration = kTypesDuration,
.multiline = true,
.slideSide = RectPart::Bottom,
});