mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-19 09:58:52 +00:00
Added label with state to "Manage dictionaries" button.
This commit is contained in:
parent
311678af80
commit
9daf362df6
Telegram/SourceFiles
@ -171,6 +171,44 @@ bool WriteDefaultDictionary() {
|
||||
return false;
|
||||
}
|
||||
|
||||
rpl::producer<QString> ButtonManageDictsState(
|
||||
not_null<Main::Session*> session) {
|
||||
if (Platform::Spellchecker::IsSystemSpellchecker()) {
|
||||
return rpl::single(QString());
|
||||
}
|
||||
const auto computeString = [=] {
|
||||
if (!session->settings().spellcheckerEnabled()) {
|
||||
return QString();
|
||||
}
|
||||
if (!session->settings().dictionariesEnabled().size()) {
|
||||
return QString();
|
||||
}
|
||||
const auto dicts = session->settings().dictionariesEnabled();
|
||||
const auto filtered = ranges::view::all(
|
||||
dicts
|
||||
) | ranges::views::filter(
|
||||
DictionaryExists
|
||||
) | ranges::to_vector;
|
||||
const auto active = Platform::Spellchecker::ActiveLanguages();
|
||||
|
||||
return (active.size() == filtered.size())
|
||||
? QString::number(filtered.size())
|
||||
: tr::lng_contacts_loading(tr::now);
|
||||
};
|
||||
const auto emptyValue = [] { return rpl::empty_value(); };
|
||||
return rpl::single(
|
||||
computeString()
|
||||
) | rpl::then(
|
||||
rpl::merge(
|
||||
Spellchecker::SupportedScriptsChanged(),
|
||||
session->settings().dictionariesEnabledChanges(
|
||||
) | rpl::map(emptyValue),
|
||||
session->settings().spellcheckerEnabledChanges(
|
||||
) | rpl::map(emptyValue)
|
||||
) | rpl::map(computeString)
|
||||
);
|
||||
}
|
||||
|
||||
void Start(not_null<Main::Session*> session) {
|
||||
Spellchecker::SetPhrases({ {
|
||||
{ &ph::lng_spellchecker_add, tr::lng_spellchecker_add() },
|
||||
|
@ -34,6 +34,8 @@ bool WriteDefaultDictionary();
|
||||
std::vector<Dict> Dictionaries();
|
||||
|
||||
void Start(not_null<Main::Session*> session);
|
||||
[[nodiscard]] rpl::producer<QString> ButtonManageDictsState(
|
||||
not_null<Main::Session*> session);
|
||||
|
||||
} // namespace Spellchecker
|
||||
|
||||
|
@ -34,6 +34,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
|
||||
#ifndef TDESKTOP_DISABLE_SPELLCHECK
|
||||
#include "boxes/dictionaries_manager.h"
|
||||
#include "chat_helpers/spellchecker_common.h"
|
||||
#include "spellcheck/platform/platform_spellcheck.h"
|
||||
#endif // !TDESKTOP_DISABLE_SPELLCHECK
|
||||
|
||||
@ -288,9 +289,10 @@ void SetupSpellchecker(
|
||||
container,
|
||||
object_ptr<Ui::VerticalLayout>(container)));
|
||||
|
||||
AddButton(
|
||||
AddButtonWithLabel(
|
||||
sliding->entity(),
|
||||
tr::lng_settings_manage_dictionaries(),
|
||||
Spellchecker::ButtonManageDictsState(session),
|
||||
st::settingsButton
|
||||
)->addClickHandler([=] {
|
||||
Ui::show(Box<Ui::ManageDictionariesBox>(session));
|
||||
|
Loading…
Reference in New Issue
Block a user