[Option][JSON] Custom auto-replaces
This commit is contained in:
parent
2e540d4d94
commit
e3b0e10857
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 {
|
struct Definition {
|
||||||
SettingScope scope = SettingScope::Global;
|
SettingScope scope = SettingScope::Global;
|
||||||
|
|
@ -252,6 +279,9 @@ const std::map<QString, Definition, std::greater<QString>> DefinitionMap {
|
||||||
{ "disable_up_edit", {
|
{ "disable_up_edit", {
|
||||||
.type = SettingType::BoolSetting,
|
.type = SettingType::BoolSetting,
|
||||||
.defaultValue = false, }},
|
.defaultValue = false, }},
|
||||||
|
{ "replaces", {
|
||||||
|
.type = SettingType::QJsonArraySetting,
|
||||||
|
.limitHandler = ReplacesLimit(), }},
|
||||||
};
|
};
|
||||||
|
|
||||||
using OldOptionKey = QString;
|
using OldOptionKey = QString;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue