diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index 1425682857..1bd0b447b0 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -280,37 +280,10 @@ void InitSpellchecker( not_null session, not_null field) { #ifndef TDESKTOP_DISABLE_SPELLCHECK - if (!Platform::Spellchecker::IsAvailable()) { - return; - } - - Spellchecker::SetWorkingDirPath(Spellchecker::DictionariesPath()); - const auto s = Ui::CreateChild( field.get(), session->settings().spellcheckerEnabledValue()); - - const auto applyDictionaries = [=] { - crl::async([=] { - Platform::Spellchecker::UpdateLanguages( - session->settings().dictionariesEnabled()); - crl::on_main([=] { - s->checkCurrentText(); - }); - }); - }; - session->settings().dictionariesChanges( - ) | rpl::start_with_next(applyDictionaries, field->lifetime()); - - Spellchecker::SetPhrases({ { - { &ph::lng_spellchecker_add, tr::lng_spellchecker_add() }, - { &ph::lng_spellchecker_remove, tr::lng_spellchecker_remove() }, - { &ph::lng_spellchecker_ignore, tr::lng_spellchecker_ignore() }, - } }); - field->setExtendedContextMenu(s->contextMenuCreated()); - - applyDictionaries(); #endif // TDESKTOP_DISABLE_SPELLCHECK } diff --git a/Telegram/SourceFiles/chat_helpers/message_field.h b/Telegram/SourceFiles/chat_helpers/message_field.h index 102daca00d..8f95a93239 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.h +++ b/Telegram/SourceFiles/chat_helpers/message_field.h @@ -12,9 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/qt_connection.h" #ifndef TDESKTOP_DISABLE_SPELLCHECK -#include "chat_helpers/spellchecker_common.h" #include "spellcheck/spelling_highlighter.h" -#include "spellcheck/spellcheck_value.h" #endif // TDESKTOP_DISABLE_SPELLCHECK #include diff --git a/Telegram/SourceFiles/chat_helpers/spellchecker_common.cpp b/Telegram/SourceFiles/chat_helpers/spellchecker_common.cpp index 07ab7275bb..a589f39c30 100644 --- a/Telegram/SourceFiles/chat_helpers/spellchecker_common.cpp +++ b/Telegram/SourceFiles/chat_helpers/spellchecker_common.cpp @@ -9,8 +9,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #ifndef TDESKTOP_DISABLE_SPELLCHECK -#include "spellcheck/spellcheck_utils.h" +#include "lang/lang_keys.h" +#include "main/main_session.h" #include "base/zlib_help.h" +#include "spellcheck/platform/platform_spellcheck.h" +#include "spellcheck/spellcheck_utils.h" +#include "spellcheck/spellcheck_value.h" namespace Spellchecker { @@ -156,6 +160,35 @@ bool WriteDefaultDictionary() { return false; } +void Start(not_null session) { + Spellchecker::SetPhrases({ { + { &ph::lng_spellchecker_add, tr::lng_spellchecker_add() }, + { &ph::lng_spellchecker_remove, tr::lng_spellchecker_remove() }, + { &ph::lng_spellchecker_ignore, tr::lng_spellchecker_ignore() }, + } }); + + if (!Platform::Spellchecker::IsSystemSpellchecker()) { + Spellchecker::SetWorkingDirPath(DictionariesPath()); + + session->settings().dictionariesEnabledChanges( + ) | rpl::start_with_next([](auto dictionaries) { + Platform::Spellchecker::UpdateLanguages(dictionaries); + }, session->lifetime()); + + session->settings().spellcheckerEnabledChanges( + ) | rpl::start_with_next([=](auto enabled) { + Platform::Spellchecker::UpdateLanguages( + enabled + ? session->settings().dictionariesEnabled() + : std::vector()); + }, session->lifetime()); + } + if (session->settings().spellcheckerEnabled()) { + Platform::Spellchecker::UpdateLanguages( + session->settings().dictionariesEnabled()); + } +} + } // namespace Spellchecker #endif // !TDESKTOP_DISABLE_SPELLCHECK diff --git a/Telegram/SourceFiles/chat_helpers/spellchecker_common.h b/Telegram/SourceFiles/chat_helpers/spellchecker_common.h index dad2be732b..0c3a09c4df 100644 --- a/Telegram/SourceFiles/chat_helpers/spellchecker_common.h +++ b/Telegram/SourceFiles/chat_helpers/spellchecker_common.h @@ -11,6 +11,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/storage_cloud_blob.h" +namespace Main { +class Session; +} // namespace Main + namespace Spellchecker { struct Dict : public Storage::CloudBlob::Blob { @@ -27,6 +31,8 @@ bool UnpackDictionary(const QString &path, int langId); bool WriteDefaultDictionary(); std::vector Dictionaries(); +void Start(not_null session); + } // namespace Spellchecker #endif // !TDESKTOP_DISABLE_SPELLCHECK diff --git a/Telegram/SourceFiles/main/main_session.cpp b/Telegram/SourceFiles/main/main_session.cpp index 39fb807544..90de3897d7 100644 --- a/Telegram/SourceFiles/main/main_session.cpp +++ b/Telegram/SourceFiles/main/main_session.cpp @@ -27,6 +27,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "observer_peer.h" #include "facades.h" +#ifndef TDESKTOP_DISABLE_SPELLCHECK +#include "chat_helpers/spellchecker_common.h" +#endif // TDESKTOP_DISABLE_SPELLCHECK + namespace Main { namespace { @@ -97,6 +101,10 @@ Session::Session( }); Window::Theme::Background()->start(); + +#ifndef TDESKTOP_DISABLE_SPELLCHECK + Spellchecker::Start(this); +#endif // TDESKTOP_DISABLE_SPELLCHECK } Session::~Session() {