[Option][JSON] Custom auto-replaces
This commit is contained in:
parent
04f0eef958
commit
f17d10cedb
1 changed files with 30 additions and 0 deletions
|
|
@ -154,6 +154,33 @@ CheckHandler IntLimitMin(int min) {
|
|||
};
|
||||
}
|
||||
|
||||
CheckHandler ReplacesLimit() {
|
||||
return [=] (QVariant value) -> QVariant {
|
||||
auto newArrayValue = QJsonArray();
|
||||
if (value.canConvert<QJsonArray>()) {
|
||||
auto arrayValue = value.toJsonArray();
|
||||
for (auto i = arrayValue.begin(); i != arrayValue.end(); ++i) {
|
||||
if (!(*i).isArray()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto a = (*i).toArray();
|
||||
if (a.size() != 2 || !a.at(0).isString() || !a.at(1).isString()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto from = a.at(0).toString();
|
||||
const auto to = a.at(1).toString();
|
||||
Ui::AddCustomReplacement(from, to);
|
||||
|
||||
newArrayValue.append(a);
|
||||
}
|
||||
}
|
||||
|
||||
return newArrayValue;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
struct Definition {
|
||||
SettingScope scope = SettingScope::Global;
|
||||
|
|
@ -252,6 +279,9 @@ const std::map<QString, Definition, std::greater<QString>> DefinitionMap {
|
|||
{ "disable_up_edit", {
|
||||
.type = SettingType::BoolSetting,
|
||||
.defaultValue = false, }},
|
||||
{ "replaces", {
|
||||
.type = SettingType::QJsonArraySetting,
|
||||
.limitHandler = ReplacesLimit(), }},
|
||||
};
|
||||
|
||||
using OldOptionKey = QString;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue