Moved spellchecker work from message_field to Spellchecker::Start.

This commit is contained in:
23rd 2020-02-08 01:42:01 +03:00
parent 9dee4e2d25
commit 9d1b93fe50
5 changed files with 48 additions and 30 deletions

View File

@ -280,37 +280,10 @@ void InitSpellchecker(
not_null<Main::Session*> session,
not_null<Ui::InputField*> field) {
#ifndef TDESKTOP_DISABLE_SPELLCHECK
if (!Platform::Spellchecker::IsAvailable()) {
return;
}
Spellchecker::SetWorkingDirPath(Spellchecker::DictionariesPath());
const auto s = Ui::CreateChild<Spellchecker::SpellingHighlighter>(
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
}

View File

@ -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 <QtGui/QClipboard>

View File

@ -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<Main::Session*> 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<int>());
}, session->lifetime());
}
if (session->settings().spellcheckerEnabled()) {
Platform::Spellchecker::UpdateLanguages(
session->settings().dictionariesEnabled());
}
}
} // namespace Spellchecker
#endif // !TDESKTOP_DISABLE_SPELLCHECK

View File

@ -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<Dict> Dictionaries();
void Start(not_null<Main::Session*> session);
} // namespace Spellchecker
#endif // !TDESKTOP_DISABLE_SPELLCHECK

View File

@ -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() {