Added button to advanced settings for dictionary management box.

This commit is contained in:
23rd 2020-02-08 13:28:13 +03:00
parent 9d1b93fe50
commit 4bd34b35ae
2 changed files with 35 additions and 5 deletions

View File

@ -422,6 +422,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_settings_spellchecker" = "Spell checker";
"lng_settings_system_spellchecker" = "Use system spell checker";
"lng_settings_custom_spellchecker" = "Use spell checker";
"lng_settings_manage_dictionaries" = "Manage dictionaries";
"lng_settings_manage_enabled_dictionary" = "Dictionary is enabled";

View File

@ -33,6 +33,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_settings.h"
#ifndef TDESKTOP_DISABLE_SPELLCHECK
#include "boxes/dictionaries_manager.h"
#include "spellcheck/platform/platform_spellcheck.h"
#endif // !TDESKTOP_DISABLE_SPELLCHECK
@ -250,28 +251,56 @@ void SetupUpdate(not_null<Ui::VerticalLayout*> container) {
bool HasSystemSpellchecker() {
#ifdef TDESKTOP_DISABLE_SPELLCHECK
return false;
#else
return Platform::Spellchecker::IsAvailable();
#endif // TDESKTOP_DISABLE_SPELLCHECK
return true;
}
void SetupSpellchecker(
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container) {
#ifndef TDESKTOP_DISABLE_SPELLCHECK
const auto session = &controller->session();
AddButton(
const auto isSystem = Platform::Spellchecker::IsSystemSpellchecker();
const auto button = AddButton(
container,
tr::lng_settings_system_spellchecker(),
isSystem
? tr::lng_settings_system_spellchecker()
: tr::lng_settings_custom_spellchecker(),
st::settingsButton
)->toggleOn(
rpl::single(session->settings().spellcheckerEnabled())
)->toggledValue(
);
button->toggledValue(
) | rpl::filter([=](bool enabled) {
return (enabled != session->settings().spellcheckerEnabled());
}) | rpl::start_with_next([=](bool enabled) {
session->settings().setSpellcheckerEnabled(enabled);
session->saveSettingsDelayed();
}, container->lifetime());
if (isSystem) {
return;
}
const auto sliding = container->add(
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
container,
object_ptr<Ui::VerticalLayout>(container)));
AddButton(
sliding->entity(),
tr::lng_settings_manage_dictionaries(),
st::settingsButton
)->addClickHandler([=] {
Ui::show(Box<Ui::ManageDictionariesBox>(session));
});
button->toggledValue(
) | rpl::start_with_next([=](bool enabled) {
sliding->toggle(enabled, anim::type::normal);
}, container->lifetime());
#endif // !TDESKTOP_DISABLE_SPELLCHECK
}
bool HasTray() {