2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Custom instant replaces

This commit is contained in:
RadRussianRus
2020-01-26 08:01:06 +03:00
parent 8b9582515e
commit 12dfa950bf
4 changed files with 48 additions and 1 deletions

View File

@@ -13,6 +13,7 @@ https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL
#include "core/application.h"
#include "base/parse_helper.h"
#include "facades.h"
#include "ui/widgets/input_fields.h"
#include <QtCore/QJsonDocument>
#include <QtCore/QJsonObject>
@@ -230,6 +231,28 @@ bool Manager::readCustomFile() {
if (settingsDisableUpEditIt != settings.constEnd() && (*settingsDisableUpEditIt).isBool()) {
cSetDisableUpEdit((*settingsDisableUpEditIt).toBool());
}
const auto settingsReplacesIt = settings.constFind(qsl("replaces"));
if (settingsReplacesIt != settings.constEnd() && (*settingsReplacesIt).isArray()) {
const auto settingsReplacesArray = (*settingsReplacesIt).toArray();
for (auto i = settingsReplacesArray.constBegin(), e = settingsReplacesArray.constEnd(); i != e; ++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();
AddCustomReplace(from, to);
Ui::AddCustomReplacement(from, to);
}
}
return true;
}
@@ -270,6 +293,9 @@ void Manager::writeDefaultFile() {
auto settingsScales = QJsonArray();
settings.insert(qsl("scales"), settingsScales);
auto settingsReplaces = QJsonArray();
settings.insert(qsl("replaces"), settingsReplaces);
auto document = QJsonDocument();
document.setObject(settings);
file.write(document.toJson(QJsonDocument::Indented));
@@ -330,6 +356,17 @@ void Manager::writeCurrentSettings() {
settings.insert(qsl("scales"), settingsScales);
auto settingsReplaces = QJsonArray();
auto currentReplaces = cCustomReplaces();
for (auto i = currentReplaces.constBegin(), e = currentReplaces.constEnd(); i != e; ++i) {
auto a = QJsonArray();
a << i.key() << i.value();
settingsReplaces << a;
}
settings.insert(qsl("replaces"), settingsReplaces);
auto document = QJsonDocument();
document.setObject(settings);
file.write(document.toJson(QJsonDocument::Indented));

View File

@@ -283,3 +283,9 @@ rpl::producer<int> DialogListLinesChanges() {
}
bool gDisableUpEdit = false;
CustomReplacementsMap gCustomReplaces;
bool AddCustomReplace(QString from, QString to) {
gCustomReplaces.insert(from, to);
return true;
}

View File

@@ -231,3 +231,7 @@ void SetDialogListLines(int lines);
[[nodiscard]] rpl::producer<int> DialogListLinesChanges();
DeclareSetting(bool, DisableUpEdit);
using CustomReplacementsMap = QMap<QString, QString>;
DeclareRefSetting(CustomReplacementsMap, CustomReplaces);
bool AddCustomReplace(QString from, QString to);