From e9e9ea2d6920aa97809f49964ebc1f8d1aef9beb Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 8 Feb 2020 14:50:20 +0300 Subject: [PATCH] Added filter for removed dictionaries when dictionary box is closed. --- Telegram/SourceFiles/boxes/dictionaries_manager.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Telegram/SourceFiles/boxes/dictionaries_manager.cpp b/Telegram/SourceFiles/boxes/dictionaries_manager.cpp index 23e6e19570..98ba77e1a0 100644 --- a/Telegram/SourceFiles/boxes/dictionaries_manager.cpp +++ b/Telegram/SourceFiles/boxes/dictionaries_manager.cpp @@ -122,6 +122,7 @@ auto AddButtonWithLoader( const Spellchecker::Dict &dict, bool buttonEnabled) { const auto id = dict.id; + buttonEnabled &= DictExists(id); const auto button = content->add( object_ptr>( @@ -272,6 +273,11 @@ void ManageDictionariesBox::prepare() { this, _session->settings().dictionariesEnabled())); + // The initial list of enabled rows may differ from the list of languages + // in settings, so we should store it when box opens + // and save it when box closes (don't do it when "Save" was pressed). + const auto initialEnabledRows = inner->enabledRows(); + setTitle(tr::lng_settings_manage_dictionaries()); addButton(tr::lng_settings_save(), [=] { @@ -281,10 +287,17 @@ void ManageDictionariesBox::prepare() { DictExists ) | ranges::to_vector); _session->saveSettingsDelayed(); + // Ignore boxClosing() when the Save button was pressed. + lifetime().destroy(); closeBox(); }); addButton(tr::lng_close(), [=] { closeBox(); }); + boxClosing() | rpl::start_with_next([=] { + _session->settings().setDictionariesEnabled(initialEnabledRows); + _session->saveSettingsDelayed(); + }, lifetime()); + setDimensionsToContent(st::boxWidth, inner); inner->heightValue(