mirror of https://github.com/procxx/kepka.git
				
				
				
			Added label with state to "Manage dictionaries" button.
This commit is contained in:
		
							parent
							
								
									311678af80
								
							
						
					
					
						commit
						9daf362df6
					
				| 
						 | 
					@ -171,6 +171,44 @@ bool WriteDefaultDictionary() {
 | 
				
			||||||
	return false;
 | 
						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) {
 | 
					void Start(not_null<Main::Session*> session) {
 | 
				
			||||||
	Spellchecker::SetPhrases({ {
 | 
						Spellchecker::SetPhrases({ {
 | 
				
			||||||
		{ &ph::lng_spellchecker_add, tr::lng_spellchecker_add() },
 | 
							{ &ph::lng_spellchecker_add, tr::lng_spellchecker_add() },
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,6 +34,8 @@ bool WriteDefaultDictionary();
 | 
				
			||||||
std::vector<Dict> Dictionaries();
 | 
					std::vector<Dict> Dictionaries();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Start(not_null<Main::Session*> session);
 | 
					void Start(not_null<Main::Session*> session);
 | 
				
			||||||
 | 
					[[nodiscard]] rpl::producer<QString> ButtonManageDictsState(
 | 
				
			||||||
 | 
						not_null<Main::Session*> session);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace Spellchecker
 | 
					} // namespace Spellchecker
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,6 +34,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef TDESKTOP_DISABLE_SPELLCHECK
 | 
					#ifndef TDESKTOP_DISABLE_SPELLCHECK
 | 
				
			||||||
#include "boxes/dictionaries_manager.h"
 | 
					#include "boxes/dictionaries_manager.h"
 | 
				
			||||||
 | 
					#include "chat_helpers/spellchecker_common.h"
 | 
				
			||||||
#include "spellcheck/platform/platform_spellcheck.h"
 | 
					#include "spellcheck/platform/platform_spellcheck.h"
 | 
				
			||||||
#endif // !TDESKTOP_DISABLE_SPELLCHECK
 | 
					#endif // !TDESKTOP_DISABLE_SPELLCHECK
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -288,9 +289,10 @@ void SetupSpellchecker(
 | 
				
			||||||
			container,
 | 
								container,
 | 
				
			||||||
			object_ptr<Ui::VerticalLayout>(container)));
 | 
								object_ptr<Ui::VerticalLayout>(container)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	AddButton(
 | 
						AddButtonWithLabel(
 | 
				
			||||||
		sliding->entity(),
 | 
							sliding->entity(),
 | 
				
			||||||
		tr::lng_settings_manage_dictionaries(),
 | 
							tr::lng_settings_manage_dictionaries(),
 | 
				
			||||||
 | 
							Spellchecker::ButtonManageDictsState(session),
 | 
				
			||||||
		st::settingsButton
 | 
							st::settingsButton
 | 
				
			||||||
	)->addClickHandler([=] {
 | 
						)->addClickHandler([=] {
 | 
				
			||||||
		Ui::show(Box<Ui::ManageDictionariesBox>(session));
 | 
							Ui::show(Box<Ui::ManageDictionariesBox>(session));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue