Add configurable offline layout correction and latest Windows release
This commit is contained in:
@@ -62,6 +62,29 @@ void validateSettings(const Settings &s)
|
||||
throw std::runtime_error("Keyboard shortcuts must be unique");
|
||||
used.push_back(*key);
|
||||
}
|
||||
if (s.autoMinLength < 1 || s.autoMinLength > 32)
|
||||
throw std::runtime_error("Minimum word length must be between 1 and 32 letters");
|
||||
if (s.autoMaxRank < 0)
|
||||
throw std::runtime_error("Frequency rank limit must be zero or a positive whole number");
|
||||
for (const auto &characters : {s.autoPrefixChars, s.autoSuffixChars})
|
||||
{
|
||||
if (characters.size() > 32)
|
||||
throw std::runtime_error("Use at most 32 punctuation characters in each delimiter field");
|
||||
for (wchar_t c : characters)
|
||||
if (letter(c) || iswalnum(c) || iswspace(c) || c < 32 || (c >= 0xd800 && c <= 0xdfff))
|
||||
throw std::runtime_error(
|
||||
"Word delimiters must be punctuation, without letters, digits or spaces");
|
||||
}
|
||||
if (s.autoCorrect && s.autoLanguages.size() < 2)
|
||||
throw std::runtime_error("Select at least two languages for automatic correction");
|
||||
if (std::set<std::wstring>(s.autoLanguages.begin(), s.autoLanguages.end()).size() !=
|
||||
s.autoLanguages.size())
|
||||
throw std::runtime_error("Dictionary languages must be unique");
|
||||
for (auto &language : s.autoLanguages)
|
||||
if (language != L"en" && language != L"uk" && language != L"ru")
|
||||
throw std::runtime_error("Unsupported auto-correction language");
|
||||
if (s.autoNever.size() > 10000 || s.autoExcluded.size() > 1000)
|
||||
throw std::runtime_error("Too many auto-correction exceptions");
|
||||
if (s.maxItems < 10 || s.maxItems > 10000 || s.maxMiB < 1 || s.maxMiB > 2048 || s.maxImageMiB < 1 ||
|
||||
s.maxImageMiB > 64)
|
||||
throw std::runtime_error("History limits: 10–10000 items, 1–2048 MiB total, 1–64 MiB per image");
|
||||
@@ -100,6 +123,20 @@ Settings loadSettings(const std::filesystem::path &path, const std::vector<Layou
|
||||
s.autostart = j.value("startWithSystem", false);
|
||||
s.elevatedAutostart = j.value("autostartAsAdministrator", false);
|
||||
s.awake = j.value("preventScreenLock", false);
|
||||
s.autoCorrect = j.value("autoCorrectLayout", false);
|
||||
s.autoMaxRank = j.value("autoCorrectMaxRank", 0);
|
||||
s.autoMinLength = j.value("autoCorrectMinLength", 3);
|
||||
s.autoPrefixChars = str(j, "autoCorrectPrefixChars", s.autoPrefixChars);
|
||||
s.autoSuffixChars = str(j, "autoCorrectSuffixChars", s.autoSuffixChars);
|
||||
for (auto pair : {std::pair{"autoCorrectLanguages", &s.autoLanguages},
|
||||
{"autoCorrectNever", &s.autoNever},
|
||||
{"autoCorrectExcludedApps", &s.autoExcluded}})
|
||||
if (j.contains(pair.first))
|
||||
{
|
||||
pair.second->clear();
|
||||
for (auto &item : j.at(pair.first))
|
||||
pair.second->push_back(wide(item.get<std::string>()));
|
||||
}
|
||||
s.maxItems = std::clamp(j.value("maxItems", 500), 10, 10000);
|
||||
s.maxMiB = std::clamp(j.value("maxTotalMegabytes", 200), 1, 2048);
|
||||
s.maxImageMiB = std::clamp(j.value("maxImageMegabytes", 20), 1, 64);
|
||||
@@ -160,6 +197,19 @@ void saveSettings(const std::filesystem::path &path, const Settings &s)
|
||||
j["layouts"] = Json::array();
|
||||
for (auto &id : s.cycle)
|
||||
j["layouts"].push_back(utf8(id));
|
||||
j["autoCorrectLayout"] = s.autoCorrect;
|
||||
j["autoCorrectMaxRank"] = s.autoMaxRank;
|
||||
j["autoCorrectMinLength"] = s.autoMinLength;
|
||||
j["autoCorrectPrefixChars"] = utf8(s.autoPrefixChars);
|
||||
j["autoCorrectSuffixChars"] = utf8(s.autoSuffixChars);
|
||||
for (auto pair : {std::pair{"autoCorrectLanguages", &s.autoLanguages},
|
||||
{"autoCorrectNever", &s.autoNever},
|
||||
{"autoCorrectExcludedApps", &s.autoExcluded}})
|
||||
{
|
||||
j[pair.first] = Json::array();
|
||||
for (auto &item : *pair.second)
|
||||
j[pair.first].push_back(utf8(item));
|
||||
}
|
||||
j["layoutHotkeys"] = Json::array();
|
||||
for (size_t i = 0; i < std::min(s.directIds.size(), s.direct.size()); ++i)
|
||||
j["layoutHotkeys"].push_back({{"layoutId", utf8(s.directIds[i])}, {"hotkey", utf8(s.direct[i])}});
|
||||
|
||||
Reference in New Issue
Block a user