mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-29 19:03:03 +00:00
Moved spellchecker work from message_field to Spellchecker::Start.
This commit is contained in:
parent
9dee4e2d25
commit
9d1b93fe50
@ -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
|
||||
}
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user