diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 5b6d8f672e..9a338b7e7e 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -410,6 +410,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_enable_animations" = "Enable animations"; "lng_settings_autoplay_gifs" = "Autoplay GIFs"; +"lng_settings_spellchecker" = "Spell checker"; +"lng_settings_system_spellchecker" = "Use system spell checker"; + "lng_backgrounds_header" = "Choose your new chat background"; "lng_theme_sure_keep" = "Keep this theme?"; "lng_theme_reverting#one" = "Reverting to the old theme in {count} second."; diff --git a/Telegram/SourceFiles/main/main_settings.cpp b/Telegram/SourceFiles/main/main_settings.cpp index 52b719711f..6bb4173fba 100644 --- a/Telegram/SourceFiles/main/main_settings.cpp +++ b/Telegram/SourceFiles/main/main_settings.cpp @@ -89,6 +89,7 @@ QByteArray Settings::serialize() const { stream << qint32(_variables.replaceEmoji.current() ? 1 : 0); stream << qint32(_variables.suggestEmoji ? 1 : 0); stream << qint32(_variables.suggestStickersByEmoji ? 1 : 0); + stream << qint32(_variables.spellcheckerEnabled.current() ? 1 : 0); } return result; } @@ -135,6 +136,7 @@ void Settings::constructFromSerialized(const QByteArray &serialized) { qint32 replaceEmoji = _variables.replaceEmoji.current() ? 1 : 0; qint32 suggestEmoji = _variables.suggestEmoji ? 1 : 0; qint32 suggestStickersByEmoji = _variables.suggestStickersByEmoji ? 1 : 0; + qint32 spellcheckerEnabled = _variables.spellcheckerEnabled.current() ? 1 : 0; stream >> selectorTab; stream >> lastSeenWarningSeen; @@ -234,6 +236,9 @@ void Settings::constructFromSerialized(const QByteArray &serialized) { stream >> suggestEmoji; stream >> suggestStickersByEmoji; } + if (!stream.atEnd()) { + stream >> spellcheckerEnabled; + } if (stream.status() != QDataStream::Ok) { LOG(("App Error: " "Bad data for Main::Settings::constructFromSerialized()")); @@ -313,6 +318,7 @@ void Settings::constructFromSerialized(const QByteArray &serialized) { _variables.replaceEmoji = (replaceEmoji == 1); _variables.suggestEmoji = (suggestEmoji == 1); _variables.suggestStickersByEmoji = (suggestStickersByEmoji == 1); + _variables.spellcheckerEnabled = (spellcheckerEnabled == 1); } void Settings::setSupportChatsTimeSlice(int slice) { diff --git a/Telegram/SourceFiles/main/main_settings.h b/Telegram/SourceFiles/main/main_settings.h index c92242c820..a02e6abe54 100644 --- a/Telegram/SourceFiles/main/main_settings.h +++ b/Telegram/SourceFiles/main/main_settings.h @@ -231,6 +231,19 @@ public: _variables.suggestStickersByEmoji = value; } + void setSpellcheckerEnabled(bool value) { + _variables.spellcheckerEnabled = value; + } + bool spellcheckerEnabled() const { + return _variables.spellcheckerEnabled.current(); + } + rpl::producer spellcheckerEnabledValue() const { + return _variables.spellcheckerEnabled.value(); + } + rpl::producer spellcheckerEnabledChanges() const { + return _variables.spellcheckerEnabled.changes(); + } + private: struct Variables { Variables(); @@ -270,6 +283,7 @@ private: rpl::variable replaceEmoji = true; bool suggestEmoji = true; bool suggestStickersByEmoji = true; + rpl::variable spellcheckerEnabled = true; static constexpr auto kDefaultSupportChatsLimitSlice = 7 * 24 * 60 * 60; diff --git a/Telegram/SourceFiles/settings/settings_advanced.cpp b/Telegram/SourceFiles/settings/settings_advanced.cpp index 36720cc6b8..d7db994167 100644 --- a/Telegram/SourceFiles/settings/settings_advanced.cpp +++ b/Telegram/SourceFiles/settings/settings_advanced.cpp @@ -243,6 +243,30 @@ void SetupUpdate(not_null container) { }); } +bool HasSystemSpellchecker() { + return (Platform::IsWindows() && Platform::IsWindows8OrGreater()) + || Platform::IsMac(); +} + +void SetupSpellchecker( + not_null controller, + not_null container) { + const auto session = &controller->session(); + AddButton( + container, + tr::lng_settings_system_spellchecker(), + st::settingsButton + )->toggleOn( + rpl::single(session->settings().spellcheckerEnabled()) + )->toggledValue( + ) | rpl::filter([=](bool enabled) { + return (enabled != session->settings().spellcheckerEnabled()); + }) | rpl::start_with_next([=](bool enabled) { + session->settings().setSpellcheckerEnabled(enabled); + session->saveSettingsDelayed(); + }, container->lifetime()); +} + bool HasTray() { return cSupportTray() || Platform::IsWindows(); } @@ -515,6 +539,14 @@ void Advanced::setupContent(not_null controller) { SetupPerformance(controller, content); AddSkip(content); + if (HasSystemSpellchecker()) { + AddSkip(content); + AddDivider(content); + AddSubsectionTitle(content, tr::lng_settings_spellchecker()); + SetupSpellchecker(controller, content); + AddSkip(content); + } + if (cAutoUpdate()) { addUpdate(); }