mirror of
https://github.com/redis/RedisDesktopManager.git
synced 2026-10-17 04:31:27 +08:00
Allow selecting default formatter
This commit is contained in:
@@ -77,3 +77,13 @@ void ServerConfig::setAskForSshPassword(bool v)
|
||||
{
|
||||
setParam<bool>("ask_ssh_password", v);
|
||||
}
|
||||
|
||||
QString ServerConfig::defaultFormatter() const
|
||||
{
|
||||
return param<QString>("default_formatter", QString("auto"));
|
||||
}
|
||||
|
||||
void ServerConfig::setDefaultFormatter(const QString &v)
|
||||
{
|
||||
setParam<QString>("default_formatter", v);
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ class ServerConfig : public RedisClient::ConnectionConfig
|
||||
Q_PROPERTY(bool overrideClusterHost READ overrideClusterHost WRITE setClusterHostOverride)
|
||||
Q_PROPERTY(bool ignoreSSLErrors READ ignoreAllSslErrors WRITE setIgnoreAllSslErrors)
|
||||
Q_PROPERTY(uint databaseScanLimit READ databaseScanLimit WRITE setDatabaseScanLimit)
|
||||
Q_PROPERTY(QString defaultFormatter READ defaultFormatter WRITE setDefaultFormatter)
|
||||
|
||||
|
||||
public:
|
||||
@@ -75,6 +76,9 @@ public:
|
||||
bool askForSshPassword() const;
|
||||
void setAskForSshPassword(bool v);
|
||||
|
||||
QString defaultFormatter() const;
|
||||
void setDefaultFormatter(const QString& v);
|
||||
|
||||
private:
|
||||
QWeakPointer<TreeOperations> m_owner;
|
||||
};
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <QVariant>
|
||||
#include "modules/value-editor/keymodel.h"
|
||||
#include "rowcache.h"
|
||||
#include "app/models/connectionconf.h"
|
||||
|
||||
template <typename T>
|
||||
class KeyModel : public ValueEditor::Model {
|
||||
@@ -208,6 +209,14 @@ class KeyModel : public ValueEditor::Model {
|
||||
return m_connection;
|
||||
}
|
||||
|
||||
virtual QString getDefaultFormatter() const override{
|
||||
if (!m_connection)
|
||||
return QString("auto");
|
||||
|
||||
// TODO(u_glide): Pass ServerConfig to KeyModel and remove this
|
||||
return m_connection->getConfig().getInternalParameters().value("default_formatter", QString("auto")).toString();
|
||||
}
|
||||
|
||||
virtual unsigned int dbIndex() const override { return m_dbIndex; }
|
||||
|
||||
virtual void loadRowsCount(ValueEditor::Model::Callback c) override {
|
||||
|
||||
@@ -60,6 +60,7 @@ class Model : public QEnableSharedFromThis<Model> {
|
||||
virtual QSharedPointer<ModelSignals> getConnector() const = 0;
|
||||
virtual QSharedPointer<RedisClient::Connection> getConnection() const = 0;
|
||||
virtual unsigned int dbIndex() const = 0;
|
||||
virtual QString getDefaultFormatter() const = 0;
|
||||
|
||||
virtual ~Model() {}
|
||||
};
|
||||
|
||||
@@ -189,6 +189,8 @@ QVariant ValueEditor::TabsModel::data(const QModelIndex& index,
|
||||
return model->isMultiRow();
|
||||
case showLoader:
|
||||
return false;
|
||||
case defaultFormatter:
|
||||
return model->getDefaultFormatter();
|
||||
case keyModel:
|
||||
QObject* modelPtr =
|
||||
static_cast<QObject*>(m_viewModels.at(index.row()).data());
|
||||
@@ -211,6 +213,7 @@ QHash<int, QByteArray> ValueEditor::TabsModel::roleNames() const {
|
||||
roles[keyModel] = "keyViewModel";
|
||||
roles[showLoader] = "showLoader";
|
||||
roles[tabName] = "tabName";
|
||||
roles[defaultFormatter] = "defaultFormatter";
|
||||
return roles;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ class TabsModel : public QAbstractListModel {
|
||||
keyModel,
|
||||
showLoader,
|
||||
tabName,
|
||||
defaultFormatter
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
@@ -846,6 +846,77 @@ Dialog {
|
||||
onCheckedChanged: if (root.settings) { root.settings.overrideClusterHost = checked }
|
||||
}
|
||||
|
||||
SettingsGroupTitle {
|
||||
text: qsTranslate("RESP","Formatters")
|
||||
Layout.columnSpan: 2
|
||||
}
|
||||
|
||||
BetterLabel { text: qsTranslate("RESP","Default value formatter:")}
|
||||
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
|
||||
BetterComboBox {
|
||||
id: defaultFormatterLogicSelector
|
||||
|
||||
Layout.fillWidth: true
|
||||
|
||||
property int customFormatterIndex: 2
|
||||
|
||||
ListModel {
|
||||
id: defaultFormatterOptionsModel
|
||||
|
||||
Component.onCompleted: {
|
||||
append({ value: "auto", text: qsTranslate("RESP", "Auto detect (JSON / Plain Text / HEX)") })
|
||||
append({ value: "last_selected", text: qsTranslate("RESP", "Last selected") })
|
||||
append({ value: "specific", text: qsTranslate("RESP", "Select formatter ...") })
|
||||
defaultFormatterLogicSelector.currentIndex = 0
|
||||
}
|
||||
}
|
||||
|
||||
textRole: "text"
|
||||
model: defaultFormatterOptionsModel
|
||||
|
||||
Connections {
|
||||
target: root
|
||||
|
||||
function onSettingsChanged(s) {
|
||||
if (!root.settings) {
|
||||
defaultFormatterLogicSelector.currentIndex = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (root.settings.defaultFormatter !== "auto"
|
||||
&& root.settings.defaultFormatter !== "last_selected") {
|
||||
defaultFormatterSelector._select(root.settings.defaultFormatter)
|
||||
defaultFormatterLogicSelector.currentIndex = defaultFormatterLogicSelector.customFormatterIndex;
|
||||
return;
|
||||
}
|
||||
|
||||
defaultFormatterLogicSelector.currentIndex = root.settings.defaultFormatter === "auto"? 0 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
onActivated: {
|
||||
if (currentIndex != customFormatterIndex) {
|
||||
root.settings.defaultFormatter = defaultFormatterOptionsModel.get(currentIndex)["value"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BetterComboBox {
|
||||
id: defaultFormatterSelector
|
||||
|
||||
visible: defaultFormatterLogicSelector.currentIndex == 2
|
||||
model: valueFormattersModel
|
||||
textRole: "name"
|
||||
|
||||
onActivated: {
|
||||
root.settings.defaultFormatter = currentText
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
Layout.columnSpan: 2
|
||||
Layout.fillHeight: true
|
||||
|
||||
@@ -364,17 +364,18 @@ Repeater {
|
||||
|
||||
source: keyTab.keyModel? Editor.getEditorByTypeString(keyType) : ""
|
||||
|
||||
function loadRowValue(row) {
|
||||
console.log("loading row value", row)
|
||||
if (valueEditor.item) {
|
||||
var rowValue = keyTab.keyModel.getRow(row)
|
||||
valueEditor.currentRow = row
|
||||
valueEditor.item.reset()
|
||||
valueEditor.item.setValue(rowValue)
|
||||
} else {
|
||||
console.log("cannot load row value - item is missing")
|
||||
}
|
||||
}
|
||||
function loadRowValue(row) {
|
||||
console.log("loading row value", row)
|
||||
if (valueEditor.item) {
|
||||
var rowValue = keyTab.keyModel.getRow(row)
|
||||
valueEditor.currentRow = row
|
||||
valueEditor.item.reset()
|
||||
valueEditor.item.defaultFormatter = defaultFormatter
|
||||
valueEditor.item.setValue(rowValue)
|
||||
} else {
|
||||
console.log("cannot load row value - item is missing")
|
||||
}
|
||||
}
|
||||
|
||||
function clear() {
|
||||
if (valueEditor.item) {
|
||||
|
||||
@@ -11,6 +11,7 @@ AbstractEditor {
|
||||
anchors.fill: parent
|
||||
|
||||
property bool active: false
|
||||
property alias defaultFormatter: textArea.defaultFormatter
|
||||
|
||||
MultilineEditor {
|
||||
id: keyText
|
||||
|
||||
@@ -27,6 +27,7 @@ Item
|
||||
property string formatterSettingsPrefix: ""
|
||||
property string lastSelectedFormatterSetting: "last_selected_" + root.formatterSettingsPrefix + "formatter"
|
||||
property string lastSelectedManualDecompression: "last_selected_" + root.formatterSettingsPrefix + "decompression"
|
||||
property string defaultFormatter: "auto"
|
||||
|
||||
property var __formatterCombobox: formatterSelector
|
||||
property var __textView: textView
|
||||
@@ -166,13 +167,22 @@ Item
|
||||
};
|
||||
|
||||
if (guessFormatter) {
|
||||
console.log("Default formatter:", root.defaultFormatter)
|
||||
|
||||
var formatterOverride = defaultFormatterSettings.value(
|
||||
root.formatterSettingsPrefix + keyName,
|
||||
defaultFormatterSettings.value(root.lastSelectedFormatterSetting, "")
|
||||
root.formatterSettingsPrefix + keyName, ""
|
||||
);
|
||||
|
||||
if (!formatterOverride) {
|
||||
return continueFormatting(true)
|
||||
if (root.defaultFormatter == "last_used") {
|
||||
formatterOverride = defaultFormatterSettings.value(root.lastSelectedFormatterSetting, "");
|
||||
} else if (root.defaultFormatter != "auto") {
|
||||
formatterOverride = root.defaultFormatter;
|
||||
}
|
||||
|
||||
if (!formatterOverride || root.defaultFormatter == "auto") {
|
||||
return continueFormatting(true)
|
||||
}
|
||||
}
|
||||
|
||||
var expectedFormatter = formatterSelector.find(formatterOverride);
|
||||
|
||||
@@ -12,6 +12,7 @@ AbstractEditor {
|
||||
|
||||
property bool active: false
|
||||
property string keyType: ""
|
||||
property alias defaultFormatter: textEditor.defaultFormatter
|
||||
|
||||
MultilineEditor {
|
||||
id: textEditor
|
||||
|
||||
@@ -12,6 +12,7 @@ AbstractEditor {
|
||||
anchors.fill: parent
|
||||
|
||||
property bool active: false
|
||||
property alias defaultFormatter: textArea.defaultFormatter
|
||||
|
||||
BetterLabel {
|
||||
Layout.fillWidth: true
|
||||
|
||||
@@ -12,6 +12,7 @@ AbstractEditor {
|
||||
anchors.fill: parent
|
||||
|
||||
property bool active: false
|
||||
property alias defaultFormatter: textArea.defaultFormatter
|
||||
|
||||
BetterLabel {
|
||||
Layout.fillWidth: true
|
||||
|
||||
Reference in New Issue
Block a user