2020-02-04 23:50:29 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "boxes/dictionaries_manager.h"
|
|
|
|
|
|
|
|
#ifndef TDESKTOP_DISABLE_SPELLCHECK
|
|
|
|
|
2020-02-08 13:57:43 +00:00
|
|
|
#include "base/event_filter.h"
|
2020-02-05 14:54:52 +00:00
|
|
|
#include "chat_helpers/spellchecker_common.h"
|
2020-02-04 23:50:29 +00:00
|
|
|
#include "core/application.h"
|
|
|
|
#include "main/main_account.h"
|
2022-03-03 08:35:21 +00:00
|
|
|
#include "main/main_session.h"
|
2020-02-04 23:50:29 +00:00
|
|
|
#include "mainwidget.h"
|
2020-02-05 14:54:52 +00:00
|
|
|
#include "mtproto/dedicated_file_loader.h"
|
2020-02-08 23:22:39 +00:00
|
|
|
#include "spellcheck/spellcheck_utils.h"
|
2020-02-05 14:54:52 +00:00
|
|
|
#include "ui/wrap/vertical_layout.h"
|
|
|
|
#include "ui/widgets/buttons.h"
|
|
|
|
#include "ui/widgets/labels.h"
|
2020-02-08 23:22:39 +00:00
|
|
|
#include "ui/widgets/multi_select.h"
|
2020-02-08 13:57:43 +00:00
|
|
|
#include "ui/widgets/popup_menu.h"
|
2020-02-05 14:54:52 +00:00
|
|
|
#include "ui/wrap/slide_wrap.h"
|
|
|
|
#include "ui/effects/animations.h"
|
2021-12-09 17:56:24 +00:00
|
|
|
#include "styles/style_layers.h"
|
|
|
|
#include "styles/style_settings.h"
|
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
#include "styles/style_menu_icons.h"
|
2020-02-04 23:50:29 +00:00
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
using Dictionaries = std::vector<int>;
|
2020-02-05 13:06:38 +00:00
|
|
|
using namespace Storage::CloudBlob;
|
2020-02-04 23:50:29 +00:00
|
|
|
|
|
|
|
using Loading = MTP::DedicatedLoader::Progress;
|
2020-02-05 14:13:12 +00:00
|
|
|
using DictState = BlobState;
|
2020-02-08 23:22:39 +00:00
|
|
|
using QueryCallback = Fn<void(const QString &)>;
|
|
|
|
constexpr auto kMaxQueryLength = 15;
|
|
|
|
|
2020-02-04 23:50:29 +00:00
|
|
|
class Inner : public Ui::RpWidget {
|
|
|
|
public:
|
2020-06-10 10:49:10 +00:00
|
|
|
Inner(
|
|
|
|
QWidget *parent,
|
2022-03-03 08:35:21 +00:00
|
|
|
not_null<Main::Session*> session,
|
2020-06-10 10:49:10 +00:00
|
|
|
Dictionaries enabledDictionaries);
|
2020-02-04 23:50:29 +00:00
|
|
|
|
|
|
|
Dictionaries enabledRows() const;
|
2020-02-08 23:22:39 +00:00
|
|
|
QueryCallback queryCallback() const;
|
2020-02-04 23:50:29 +00:00
|
|
|
|
|
|
|
private:
|
2020-06-10 10:49:10 +00:00
|
|
|
void setupContent(
|
2022-03-03 08:35:21 +00:00
|
|
|
not_null<Main::Session*> session,
|
2020-06-10 10:49:10 +00:00
|
|
|
Dictionaries enabledDictionaries);
|
2020-02-04 23:50:29 +00:00
|
|
|
|
|
|
|
Dictionaries _enabledRows;
|
2020-02-08 23:22:39 +00:00
|
|
|
QueryCallback _queryCallback;
|
2020-02-04 23:50:29 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-02-05 21:39:58 +00:00
|
|
|
inline auto DictExists(int langId) {
|
|
|
|
return Spellchecker::DictionaryExists(langId);
|
|
|
|
}
|
|
|
|
|
2020-02-08 13:57:43 +00:00
|
|
|
inline auto FilterEnabledDict(Dictionaries dicts) {
|
|
|
|
return dicts | ranges::views::filter(
|
|
|
|
DictExists
|
|
|
|
) | ranges::to_vector;
|
|
|
|
}
|
|
|
|
|
2020-02-05 21:39:58 +00:00
|
|
|
DictState ComputeState(int id, bool enabled) {
|
|
|
|
const auto result = enabled ? DictState(Active()) : DictState(Ready());
|
|
|
|
if (DictExists(id)) {
|
|
|
|
return result;
|
2020-02-04 23:50:29 +00:00
|
|
|
}
|
2020-02-06 15:27:35 +00:00
|
|
|
return Available{ Spellchecker::GetDownloadSize(id) };
|
2020-02-04 23:50:29 +00:00
|
|
|
}
|
|
|
|
|
2020-02-05 13:06:38 +00:00
|
|
|
QString StateDescription(const DictState &state) {
|
2020-02-05 14:28:22 +00:00
|
|
|
return StateDescription(
|
|
|
|
state,
|
|
|
|
tr::lng_settings_manage_enabled_dictionary);
|
2020-02-04 23:50:29 +00:00
|
|
|
}
|
|
|
|
|
2020-02-08 23:22:39 +00:00
|
|
|
auto CreateMultiSelect(QWidget *parent) {
|
|
|
|
const auto result = Ui::CreateChild<Ui::MultiSelect>(
|
|
|
|
parent,
|
2020-11-29 18:26:49 +00:00
|
|
|
st::defaultMultiSelect,
|
2020-02-08 23:22:39 +00:00
|
|
|
tr::lng_participant_filter());
|
|
|
|
|
|
|
|
result->resizeToWidth(st::boxWidth);
|
|
|
|
result->moveToLeft(0, 0);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-02-04 23:50:29 +00:00
|
|
|
Inner::Inner(
|
|
|
|
QWidget *parent,
|
2022-03-03 08:35:21 +00:00
|
|
|
not_null<Main::Session*> session,
|
2020-06-10 10:49:10 +00:00
|
|
|
Dictionaries enabledDictionaries)
|
|
|
|
: RpWidget(parent) {
|
2022-03-03 08:35:21 +00:00
|
|
|
setupContent(session, std::move(enabledDictionaries));
|
2020-02-04 23:50:29 +00:00
|
|
|
}
|
|
|
|
|
2020-02-08 23:22:39 +00:00
|
|
|
QueryCallback Inner::queryCallback() const {
|
|
|
|
return _queryCallback;
|
|
|
|
}
|
|
|
|
|
2020-02-04 23:50:29 +00:00
|
|
|
Dictionaries Inner::enabledRows() const {
|
|
|
|
return _enabledRows;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto AddButtonWithLoader(
|
|
|
|
not_null<Ui::VerticalLayout*> content,
|
2022-03-03 08:35:21 +00:00
|
|
|
not_null<Main::Session*> session,
|
2020-02-06 15:27:35 +00:00
|
|
|
const Spellchecker::Dict &dict,
|
2020-02-08 23:22:39 +00:00
|
|
|
bool buttonEnabled,
|
|
|
|
rpl::producer<QStringView> query) {
|
2020-02-06 15:27:35 +00:00
|
|
|
const auto id = dict.id;
|
2020-02-08 11:50:20 +00:00
|
|
|
buttonEnabled &= DictExists(id);
|
2020-02-04 23:50:29 +00:00
|
|
|
|
2020-02-08 23:22:39 +00:00
|
|
|
const auto locale = Spellchecker::LocaleFromLangId(id);
|
|
|
|
const std::vector<QString> indexList = {
|
|
|
|
dict.name,
|
|
|
|
QLocale::languageToString(locale.language()),
|
|
|
|
QLocale::countryToString(locale.country())
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto wrap = content->add(
|
2020-02-04 23:50:29 +00:00
|
|
|
object_ptr<Ui::SlideWrap<Ui::SettingsButton>>(
|
|
|
|
content,
|
|
|
|
object_ptr<Ui::SettingsButton>(
|
|
|
|
content,
|
2020-02-06 15:27:35 +00:00
|
|
|
rpl::single(dict.name),
|
2020-02-04 23:50:29 +00:00
|
|
|
st::dictionariesSectionButton
|
|
|
|
)
|
|
|
|
)
|
2020-02-08 23:22:39 +00:00
|
|
|
);
|
|
|
|
const auto button = wrap->entity();
|
|
|
|
|
|
|
|
std::move(
|
|
|
|
query
|
|
|
|
) | rpl::start_with_next([=](auto string) {
|
|
|
|
wrap->toggle(
|
|
|
|
ranges::any_of(indexList, [&](const QString &s) {
|
|
|
|
return s.startsWith(string, Qt::CaseInsensitive);
|
|
|
|
}),
|
|
|
|
anim::type::instant);
|
|
|
|
}, button->lifetime());
|
2020-02-07 18:13:06 +00:00
|
|
|
|
2020-02-21 18:55:11 +00:00
|
|
|
using Loader = Spellchecker::DictLoader;
|
|
|
|
using GlobalLoaderPtr = std::shared_ptr<base::unique_qptr<Loader>>;
|
|
|
|
|
2020-02-07 18:13:06 +00:00
|
|
|
const auto localLoader = button->lifetime()
|
|
|
|
.make_state<base::unique_qptr<Loader>>();
|
|
|
|
const auto localLoaderValues = button->lifetime()
|
|
|
|
.make_state<rpl::event_stream<Loader*>>();
|
|
|
|
const auto setLocalLoader = [=](base::unique_qptr<Loader> loader) {
|
|
|
|
*localLoader = std::move(loader);
|
|
|
|
localLoaderValues->fire(localLoader->get());
|
|
|
|
};
|
|
|
|
const auto destroyLocalLoader = [=] {
|
|
|
|
setLocalLoader(nullptr);
|
|
|
|
};
|
|
|
|
|
2020-02-04 23:50:29 +00:00
|
|
|
const auto buttonState = button->lifetime()
|
2020-02-05 13:06:38 +00:00
|
|
|
.make_state<rpl::variable<DictState>>();
|
2020-02-08 13:57:43 +00:00
|
|
|
const auto dictionaryRemoved = button->lifetime()
|
|
|
|
.make_state<rpl::event_stream<>>();
|
2020-02-21 18:55:11 +00:00
|
|
|
const auto dictionaryFromGlobalLoader = button->lifetime()
|
|
|
|
.make_state<rpl::event_stream<>>();
|
|
|
|
|
|
|
|
const auto globalLoader = button->lifetime()
|
|
|
|
.make_state<GlobalLoaderPtr>();
|
|
|
|
|
|
|
|
const auto rawGlobalLoaderPtr = [=]() -> Loader* {
|
|
|
|
if (!globalLoader || !*globalLoader || !*globalLoader->get()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return globalLoader->get()->get();
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto setGlobalLoaderPtr = [=](GlobalLoaderPtr loader) {
|
|
|
|
if (localLoader->get()) {
|
|
|
|
if (loader && loader->get()) {
|
|
|
|
loader->get()->destroy();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*globalLoader = std::move(loader);
|
|
|
|
localLoaderValues->fire(rawGlobalLoaderPtr());
|
|
|
|
if (rawGlobalLoaderPtr()) {
|
|
|
|
dictionaryFromGlobalLoader->fire({});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Spellchecker::GlobalLoaderChanged(
|
|
|
|
) | rpl::start_with_next([=](int langId) {
|
|
|
|
if (!langId && rawGlobalLoaderPtr()) {
|
|
|
|
setGlobalLoaderPtr(nullptr);
|
|
|
|
} else if (langId == id) {
|
|
|
|
setGlobalLoaderPtr(Spellchecker::GlobalLoader());
|
|
|
|
}
|
|
|
|
}, button->lifetime());
|
2020-02-04 23:50:29 +00:00
|
|
|
|
|
|
|
const auto label = Ui::CreateChild<Ui::FlatLabel>(
|
|
|
|
button,
|
|
|
|
buttonState->value() | rpl::map(StateDescription),
|
|
|
|
st::settingsUpdateState);
|
|
|
|
label->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
|
|
|
|
rpl::combine(
|
|
|
|
button->widthValue(),
|
|
|
|
label->widthValue()
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
label->moveToLeft(
|
|
|
|
st::settingsUpdateStatePosition.x(),
|
|
|
|
st::settingsUpdateStatePosition.y());
|
|
|
|
}, label->lifetime());
|
|
|
|
|
|
|
|
buttonState->value(
|
2020-02-05 13:06:38 +00:00
|
|
|
) | rpl::start_with_next([=](const DictState &state) {
|
2020-08-31 08:14:53 +00:00
|
|
|
const auto isToggledSet = v::is<Active>(state);
|
2020-02-04 23:50:29 +00:00
|
|
|
const auto toggled = isToggledSet ? 1. : 0.;
|
|
|
|
const auto over = !button->isDisabled()
|
|
|
|
&& (button->isDown() || button->isOver());
|
|
|
|
|
|
|
|
if (toggled == 0. && !over) {
|
|
|
|
label->setTextColorOverride(std::nullopt);
|
|
|
|
} else {
|
|
|
|
label->setTextColorOverride(anim::color(
|
|
|
|
over ? st::contactsStatusFgOver : st::contactsStatusFg,
|
|
|
|
st::contactsStatusFgOnline,
|
|
|
|
toggled));
|
|
|
|
}
|
|
|
|
}, label->lifetime());
|
|
|
|
|
|
|
|
button->toggleOn(
|
|
|
|
rpl::single(
|
|
|
|
buttonEnabled
|
|
|
|
) | rpl::then(
|
2020-02-08 13:57:43 +00:00
|
|
|
rpl::merge(
|
2020-02-21 18:55:11 +00:00
|
|
|
// Events to toggle on.
|
2020-06-21 16:25:29 +00:00
|
|
|
dictionaryFromGlobalLoader->events() | rpl::map_to(true),
|
2020-02-21 18:55:11 +00:00
|
|
|
// Events to toggle off.
|
|
|
|
rpl::merge(
|
|
|
|
dictionaryRemoved->events(),
|
|
|
|
buttonState->value(
|
|
|
|
) | rpl::filter([](const DictState &state) {
|
2020-08-31 08:14:53 +00:00
|
|
|
return v::is<Failed>(state);
|
2020-06-21 16:25:29 +00:00
|
|
|
}) | rpl::to_empty
|
|
|
|
) | rpl::map_to(false)
|
2020-02-21 18:55:11 +00:00
|
|
|
)
|
2020-02-04 23:50:29 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2020-07-01 09:03:29 +00:00
|
|
|
*buttonState = localLoaderValues->events_starting_with(
|
|
|
|
rawGlobalLoaderPtr() ? rawGlobalLoaderPtr() : localLoader->get()
|
|
|
|
) | rpl::map([=](Loader *loader) {
|
2020-02-04 23:50:29 +00:00
|
|
|
return (loader && loader->id() == id)
|
|
|
|
? loader->state()
|
|
|
|
: rpl::single(
|
|
|
|
buttonEnabled
|
|
|
|
) | rpl::then(
|
2020-02-08 13:57:43 +00:00
|
|
|
rpl::merge(
|
2020-06-21 16:25:29 +00:00
|
|
|
dictionaryRemoved->events() | rpl::map_to(false),
|
2020-02-08 13:57:43 +00:00
|
|
|
button->toggledValue()
|
|
|
|
)
|
2020-02-04 23:50:29 +00:00
|
|
|
) | rpl::map([=](auto enabled) {
|
2020-02-05 21:39:58 +00:00
|
|
|
return ComputeState(id, enabled);
|
2020-02-04 23:50:29 +00:00
|
|
|
});
|
|
|
|
}) | rpl::flatten_latest(
|
2020-02-05 13:06:38 +00:00
|
|
|
) | rpl::filter([=](const DictState &state) {
|
2020-08-31 08:14:53 +00:00
|
|
|
return !v::is<Failed>(buttonState->current())
|
|
|
|
|| !v::is<Available>(state);
|
2020-02-04 23:50:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
button->toggledValue(
|
|
|
|
) | rpl::start_with_next([=](bool toggled) {
|
|
|
|
const auto &state = buttonState->current();
|
2020-08-31 08:14:53 +00:00
|
|
|
if (toggled && (v::is<Available>(state) || v::is<Failed>(state))) {
|
2020-02-07 18:13:06 +00:00
|
|
|
const auto weak = Ui::MakeWeak(button);
|
|
|
|
setLocalLoader(base::make_unique_q<Loader>(
|
2020-06-12 14:09:04 +00:00
|
|
|
QCoreApplication::instance(),
|
2022-03-03 08:35:21 +00:00
|
|
|
session,
|
2020-02-05 14:13:12 +00:00
|
|
|
id,
|
2020-02-06 15:27:35 +00:00
|
|
|
Spellchecker::GetDownloadLocation(id),
|
2020-02-05 14:13:12 +00:00
|
|
|
Spellchecker::DictPathByLangId(id),
|
2020-02-07 18:13:06 +00:00
|
|
|
Spellchecker::GetDownloadSize(id),
|
|
|
|
crl::guard(weak, destroyLocalLoader)));
|
2020-08-31 08:14:53 +00:00
|
|
|
} else if (!toggled && v::is<Loading>(state)) {
|
2020-02-21 18:55:11 +00:00
|
|
|
if (const auto g = rawGlobalLoaderPtr()) {
|
|
|
|
g->destroy();
|
|
|
|
return;
|
|
|
|
}
|
2020-02-07 18:13:06 +00:00
|
|
|
if (localLoader && localLoader->get()->id() == id) {
|
|
|
|
destroyLocalLoader();
|
2020-02-04 23:50:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}, button->lifetime());
|
|
|
|
|
2020-02-08 13:57:43 +00:00
|
|
|
const auto contextMenu = button->lifetime()
|
|
|
|
.make_state<base::unique_qptr<Ui::PopupMenu>>();
|
|
|
|
const auto showMenu = [=] {
|
|
|
|
if (!DictExists(id)) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-12-09 17:56:24 +00:00
|
|
|
*contextMenu = base::make_unique_q<Ui::PopupMenu>(
|
|
|
|
button,
|
|
|
|
st::popupMenuWithIcons);
|
2020-02-08 13:57:43 +00:00
|
|
|
contextMenu->get()->addAction(
|
|
|
|
tr::lng_settings_manage_remove_dictionary(tr::now), [=] {
|
2021-12-09 17:56:24 +00:00
|
|
|
Spellchecker::RemoveDictionary(id);
|
|
|
|
dictionaryRemoved->fire({});
|
|
|
|
}, &st::menuIconDelete);
|
2020-02-08 13:57:43 +00:00
|
|
|
contextMenu->get()->popup(QCursor::pos());
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
base::install_event_filter(button, [=](not_null<QEvent*> e) {
|
|
|
|
if (e->type() == QEvent::ContextMenu && showMenu()) {
|
|
|
|
return base::EventFilterResult::Cancel;
|
|
|
|
}
|
|
|
|
return base::EventFilterResult::Continue;
|
|
|
|
});
|
|
|
|
|
2020-02-21 18:55:11 +00:00
|
|
|
if (const auto g = Spellchecker::GlobalLoader()) {
|
|
|
|
if (g.get() && g->get()->id() == id) {
|
|
|
|
setGlobalLoaderPtr(g);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-04 23:50:29 +00:00
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
2020-06-10 10:49:10 +00:00
|
|
|
void Inner::setupContent(
|
2022-03-03 08:35:21 +00:00
|
|
|
not_null<Main::Session*> session,
|
2020-06-10 10:49:10 +00:00
|
|
|
Dictionaries enabledDictionaries) {
|
2020-02-04 23:50:29 +00:00
|
|
|
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
|
|
|
|
2020-02-08 23:22:39 +00:00
|
|
|
const auto queryStream = content->lifetime()
|
|
|
|
.make_state<rpl::event_stream<QStringView>>();
|
|
|
|
|
2020-02-06 15:27:35 +00:00
|
|
|
for (const auto &dict : Spellchecker::Dictionaries()) {
|
|
|
|
const auto id = dict.id;
|
2020-02-04 23:50:29 +00:00
|
|
|
const auto row = AddButtonWithLoader(
|
|
|
|
content,
|
2022-03-03 08:35:21 +00:00
|
|
|
session,
|
2020-02-06 15:27:35 +00:00
|
|
|
dict,
|
2020-02-08 23:22:39 +00:00
|
|
|
ranges::contains(enabledDictionaries, id),
|
|
|
|
queryStream->events());
|
2020-02-04 23:50:29 +00:00
|
|
|
row->toggledValue(
|
|
|
|
) | rpl::start_with_next([=](auto enabled) {
|
2020-02-06 13:58:19 +00:00
|
|
|
if (enabled) {
|
2020-02-06 15:27:35 +00:00
|
|
|
_enabledRows.push_back(id);
|
2020-02-04 23:50:29 +00:00
|
|
|
} else {
|
|
|
|
auto &rows = _enabledRows;
|
2020-02-06 15:27:35 +00:00
|
|
|
rows.erase(ranges::remove(rows, id), end(rows));
|
2020-02-04 23:50:29 +00:00
|
|
|
}
|
|
|
|
}, row->lifetime());
|
|
|
|
}
|
|
|
|
|
2020-02-08 23:22:39 +00:00
|
|
|
_queryCallback = [=](const QString &query) {
|
|
|
|
if (query.size() >= kMaxQueryLength) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
queryStream->fire_copy(query);
|
|
|
|
};
|
|
|
|
|
2020-02-04 23:50:29 +00:00
|
|
|
content->resizeToWidth(st::boxWidth);
|
|
|
|
Ui::ResizeFitChild(this, content);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
ManageDictionariesBox::ManageDictionariesBox(
|
|
|
|
QWidget*,
|
2022-03-03 08:35:21 +00:00
|
|
|
not_null<Main::Session*> session)
|
|
|
|
: _session(session) {
|
2020-02-04 23:50:29 +00:00
|
|
|
}
|
|
|
|
|
2020-02-08 23:22:39 +00:00
|
|
|
void ManageDictionariesBox::setInnerFocus() {
|
|
|
|
_setInnerFocus();
|
|
|
|
}
|
|
|
|
|
2020-02-04 23:50:29 +00:00
|
|
|
void ManageDictionariesBox::prepare() {
|
2020-02-08 23:22:39 +00:00
|
|
|
const auto multiSelect = CreateMultiSelect(this);
|
|
|
|
|
|
|
|
const auto inner = setInnerWidget(
|
|
|
|
object_ptr<Inner>(
|
|
|
|
this,
|
2022-03-03 08:35:21 +00:00
|
|
|
_session,
|
2020-06-18 18:04:16 +00:00
|
|
|
Core::App().settings().dictionariesEnabled()),
|
2020-02-08 23:22:39 +00:00
|
|
|
st::boxScroll,
|
|
|
|
multiSelect->height()
|
|
|
|
);
|
|
|
|
|
|
|
|
multiSelect->setQueryChangedCallback(inner->queryCallback());
|
|
|
|
_setInnerFocus = [=] {
|
|
|
|
multiSelect->setInnerFocus();
|
|
|
|
};
|
2020-02-04 23:50:29 +00:00
|
|
|
|
2020-02-08 11:50:20 +00:00
|
|
|
// 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();
|
|
|
|
|
2020-02-04 23:50:29 +00:00
|
|
|
setTitle(tr::lng_settings_manage_dictionaries());
|
|
|
|
|
|
|
|
addButton(tr::lng_settings_save(), [=] {
|
2020-06-18 18:04:16 +00:00
|
|
|
Core::App().settings().setDictionariesEnabled(
|
2020-02-08 13:57:43 +00:00
|
|
|
FilterEnabledDict(inner->enabledRows()));
|
2020-06-18 18:04:16 +00:00
|
|
|
Core::App().saveSettingsDelayed();
|
2020-02-08 11:50:20 +00:00
|
|
|
// Ignore boxClosing() when the Save button was pressed.
|
|
|
|
lifetime().destroy();
|
2020-02-04 23:50:29 +00:00
|
|
|
closeBox();
|
|
|
|
});
|
|
|
|
addButton(tr::lng_close(), [=] { closeBox(); });
|
|
|
|
|
2020-02-08 11:50:20 +00:00
|
|
|
boxClosing() | rpl::start_with_next([=] {
|
2020-06-18 18:04:16 +00:00
|
|
|
Core::App().settings().setDictionariesEnabled(
|
2020-02-08 13:57:43 +00:00
|
|
|
FilterEnabledDict(initialEnabledRows));
|
2020-06-18 18:04:16 +00:00
|
|
|
Core::App().saveSettingsDelayed();
|
2020-02-08 11:50:20 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
2020-02-04 23:50:29 +00:00
|
|
|
setDimensionsToContent(st::boxWidth, inner);
|
|
|
|
|
2020-02-08 23:22:39 +00:00
|
|
|
using namespace rpl::mappers;
|
|
|
|
const auto max = lifetime().make_state<int>(0);
|
|
|
|
rpl::combine(
|
|
|
|
inner->heightValue(),
|
|
|
|
multiSelect->heightValue(),
|
|
|
|
_1 + _2
|
2020-02-04 23:50:29 +00:00
|
|
|
) | rpl::start_with_next([=](int height) {
|
|
|
|
using std::min;
|
2020-02-08 23:22:39 +00:00
|
|
|
accumulate_max(*max, height);
|
|
|
|
setDimensions(st::boxWidth, min(*max, st::boxMaxListHeight), true);
|
2020-02-04 23:50:29 +00:00
|
|
|
}, inner->lifetime());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Ui
|
|
|
|
|
|
|
|
#endif // !TDESKTOP_DISABLE_SPELLCHECK
|