diff --git a/autotests/src/katedocument_test.cpp b/autotests/src/katedocument_test.cpp --- a/autotests/src/katedocument_test.cpp +++ b/autotests/src/katedocument_test.cpp @@ -292,7 +292,7 @@ doc.setHighlightingMode ("C++"); doc.config()->setTabWidth(4); - doc.config()->setIndentationMode("cppstyle"); + doc.config()->set("Indentation Mode", "cppstyle"); // no replace tabs, no indent pasted text doc.setConfigValue("replace-tabs", false); diff --git a/src/completion/katecompletionconfig.h b/src/completion/katecompletionconfig.h --- a/src/completion/katecompletionconfig.h +++ b/src/completion/katecompletionconfig.h @@ -60,6 +60,10 @@ protected: void updateConfig() override; + // Dummy functions to satisfy complier due to be pure virtual + KateConfig *staticGlobal() override { return nullptr; } + bool isGlobal() const override { return true; } + private Q_SLOTS: void moveColumnUp(); void moveColumnDown(); diff --git a/src/dialogs/katedialogs.cpp b/src/dialogs/katedialogs.cpp --- a/src/dialogs/katedialogs.cpp +++ b/src/dialogs/katedialogs.cpp @@ -175,7 +175,7 @@ KateDocumentConfig::global()->setBackspaceIndents(ui->chkBackspaceUnindents->isChecked()); KateDocumentConfig::global()->setIndentPastedText(ui->chkIndentPaste->isChecked()); KateDocumentConfig::global()->setIndentationWidth(ui->sbIndentWidth->value()); - KateDocumentConfig::global()->setIndentationMode(KateAutoIndent::modeName(ui->cmbMode->currentIndex())); + KateDocumentConfig::global()->set("Indentation Mode", KateAutoIndent::modeName(ui->cmbMode->currentIndex())); KateDocumentConfig::global()->setTabWidth(ui->sbTabWidth->value()); KateDocumentConfig::global()->setReplaceTabsDyn(ui->rbIndentWithSpaces->isChecked()); @@ -204,7 +204,7 @@ ui->rbTabIndents->setChecked(KateDocumentConfig::global()->tabHandling() == KateDocumentConfig::tabIndents); ui->rbTabSmart->setChecked(KateDocumentConfig::global()->tabHandling() == KateDocumentConfig::tabSmart); - ui->cmbMode->setCurrentIndex(KateAutoIndent::modeNumber(KateDocumentConfig::global()->indentationMode())); + ui->cmbMode->setCurrentIndex(KateAutoIndent::modeNumber(KateDocumentConfig::global()->stringVal("Indentation Mode"))); if (KateDocumentConfig::global()->replaceTabsDyn()) { ui->rbIndentWithSpaces->setChecked(true); @@ -489,8 +489,8 @@ KateViewConfig::global()->configStart(); KateDocumentConfig::global()->configStart(); - KateDocumentConfig::global()->setWordWrapAt(ui->sbWordWrap->value()); - KateDocumentConfig::global()->setWordWrap(ui->chkStaticWordWrap->isChecked()); + KateDocumentConfig::global()->set("Word Wrap Column", ui->sbWordWrap->value()); + KateDocumentConfig::global()->set("Word Wrap", ui->chkStaticWordWrap->isChecked()); KateRendererConfig::global()->setWordWrapMarker(ui->chkShowStaticWordWrapMarker->isChecked()); @@ -506,10 +506,10 @@ void KateEditGeneralConfigTab::reload() { - ui->chkStaticWordWrap->setChecked(KateDocumentConfig::global()->wordWrap()); + ui->chkStaticWordWrap->setChecked(KateDocumentConfig::global()->isSet("Word Wrap")); ui->chkShowStaticWordWrapMarker->setChecked(KateRendererConfig::global()->wordWrapMarker()); ui->sbWordWrap->setSuffix(ki18ncp("Wrap words at (value is at 20 or larger)", " character", " characters")); - ui->sbWordWrap->setValue(KateDocumentConfig::global()->wordWrapAt()); + ui->sbWordWrap->setValue(KateDocumentConfig::global()->intVal("Word Wrap Column")); ui->chkAutoBrackets->setChecked(KateViewConfig::global()->autoBrackets()); ui->chkSmartCopyCut->setChecked(KateViewConfig::global()->smartCopyCut()); ui->chkMousePasteAtCursorPosition->setChecked(KateViewConfig::global()->mousePasteAtCursorPosition()); diff --git a/src/document/editorconfig.cpp b/src/document/editorconfig.cpp --- a/src/document/editorconfig.cpp +++ b/src/document/editorconfig.cpp @@ -142,7 +142,7 @@ } else if (QLatin1String("insert_final_newline") == key && checkBoolValue(value, &boolValue)) { m_document->config()->setNewLineAtEof(boolValue); } else if (QLatin1String("max_line_length") == key && checkIntValue(value, &intValue)) { - m_document->config()->setWordWrapAt(intValue); + m_document->config()->set("Word Wrap Column", intValue); } else if (QLatin1String("tab_width") == key && checkIntValue(value, &intValue)) { m_document->config()->setTabWidth(intValue); tabWidth = intValue; diff --git a/src/document/katebuffer.cpp b/src/document/katebuffer.cpp --- a/src/document/katebuffer.cpp +++ b/src/document/katebuffer.cpp @@ -347,7 +347,7 @@ // try to set indentation if (!h->indentation().isEmpty()) { - m_doc->config()->setIndentationMode(h->indentation()); + m_doc->config()->set("Indentation Mode", h->indentation()); } } } diff --git a/src/document/katedocument.cpp b/src/document/katedocument.cpp --- a/src/document/katedocument.cpp +++ b/src/document/katedocument.cpp @@ -1027,7 +1027,7 @@ // wrap the new/changed text, if something really changed! if (m_buffer->editChanged() && (editSessionNumber == 1)) - if (m_undoManager->isActive() && config()->wordWrap()) { + if (m_undoManager->isActive() && config()->isSet("Word Wrap")) { wrapText(m_buffer->editTagStart(), m_buffer->editTagEnd()); } @@ -1105,7 +1105,7 @@ return false; } - int col = config()->wordWrapAt(); + int col = config()->intVal("Word Wrap Column"); if (col == 0) { return false; @@ -1880,7 +1880,7 @@ } // indent mode - config()->setIndentationMode(kconfig.readEntry("Indentation Mode", config()->indentationMode())); + config()->set("Indentation Mode", kconfig.readEntry("Indentation Mode", config()->stringVal("Indentation Mode"))); // Restore Bookmarks const QList marks = kconfig.readEntry("Bookmarks", QList()); @@ -1924,7 +1924,7 @@ } // indent mode - kconfig.writeEntry("Indentation Mode", config()->indentationMode()); + kconfig.writeEntry("Indentation Mode", config()->stringVal("Indentation Mode")); // Save Bookmarks QList marks; @@ -3252,7 +3252,7 @@ return; } - if (config()->wordWrap() && textLine->endsWith(QLatin1String(" "))) { + if (config()->isSet("Word Wrap") && textLine->endsWith(QLatin1String(" "))) { // gg: in hard wordwrap mode, backspace must also eat the trailing space removeText(KTextEditor::Range(line - 1, textLine->length() - 1, line, 0)); } else { @@ -4371,22 +4371,22 @@ void KTextEditor::DocumentPrivate::setWordWrap(bool on) { - config()->setWordWrap(on); + config()->set("Word Wrap", on); } bool KTextEditor::DocumentPrivate::wordWrap() const { - return config()->wordWrap(); + return config()->isSet("Word Wrap"); } void KTextEditor::DocumentPrivate::setWordWrapAt(uint col) { - config()->setWordWrapAt(col); + config()->set("Word Wrap Column", static_cast(col)); } unsigned int KTextEditor::DocumentPrivate::wordWrapAt() const { - return config()->wordWrapAt(); + return config()->intVal("Word Wrap Column"); } void KTextEditor::DocumentPrivate::setPageUpDownMovesCursor(bool on) @@ -4415,7 +4415,7 @@ m_undoManager->updateConfig(); // switch indenter if needed and update config.... - m_indenter->setMode(m_config->indentationMode()); + m_indenter->setMode(m_config->stringVal("Indentation Mode")); m_indenter->updateConfig(); // set tab width there, too @@ -4621,9 +4621,9 @@ } else if (var == QLatin1String("indent-width") && checkIntValue(val, &n)) { m_config->setIndentationWidth(n); } else if (var == QLatin1String("indent-mode")) { - m_config->setIndentationMode(val); - } else if (var == QLatin1String("word-wrap-column") && checkIntValue(val, &n) && n > 0) { // uint, but hard word wrap at 0 will be no fun ;) - m_config->setWordWrapAt(n); + m_config->set("Indentation Mode", val); + } else if (var == QLatin1String("word-wrap-column") && checkIntValue(val, &n)) { + m_config->set("Word Wrap Column", n); } // STRING SETTINGS @@ -4952,7 +4952,7 @@ } // temporarily disable static word wrap (see bug #328900) - const bool wordWrapEnabled = config()->wordWrap(); + const bool wordWrapEnabled = config()->isSet("Word Wrap"); if (wordWrapEnabled) { setWordWrap(false); } @@ -5006,7 +5006,7 @@ * and user did not set it before! */ if (!m_indenterSetByUser && !KTextEditor::EditorPrivate::self()->modeManager()->fileType(newType).indenter.isEmpty()) { - config()->setIndentationMode(KTextEditor::EditorPrivate::self()->modeManager()->fileType(newType).indenter); + config()->set("Indentation Mode", KTextEditor::EditorPrivate::self()->modeManager()->fileType(newType).indenter); } // views! diff --git a/src/render/katerenderer.cpp b/src/render/katerenderer.cpp --- a/src/render/katerenderer.cpp +++ b/src/render/katerenderer.cpp @@ -900,7 +900,7 @@ const QPainter::RenderHints backupRenderHints = paint.renderHints(); paint.setRenderHint(QPainter::Antialiasing, false); paint.setPen(config()->wordWrapMarkerColor()); - int _x = qreal(m_doc->config()->wordWrapAt()) * fm.width(QLatin1Char('x')) - xStart; + int _x = qreal(m_doc->config()->intVal("Word Wrap Column")) * fm.width(QLatin1Char('x')) - xStart; paint.drawLine(_x, 0, _x, lineHeight()); paint.setRenderHints(backupRenderHints); } diff --git a/src/utils/kateautoindent.cpp b/src/utils/kateautoindent.cpp --- a/src/utils/kateautoindent.cpp +++ b/src/utils/kateautoindent.cpp @@ -358,7 +358,7 @@ << doc->highlight()->name() << "', style '" << doc->highlight()->style() << "'" ", but script require '" << m_script->indentHeader().requiredStyle() << "'" ; - doc->config()->setIndentationMode(MODE_NORMAL()); + doc->config()->set("Indentation Mode", MODE_NORMAL()); } } } @@ -480,7 +480,7 @@ QString requiredStyle = KateAutoIndent::modeRequiredStyle(z); action->setEnabled(requiredStyle.isEmpty() || requiredStyle == doc->highlight()->style()); - if (doc->config()->indentationMode() == KateAutoIndent::modeName(z)) { + if (doc->config()->stringVal("Indentation Mode") == KateAutoIndent::modeName(z)) { action->setChecked(true); } } @@ -492,7 +492,7 @@ void KateViewIndentationAction::setMode(QAction *action) { // set new mode - doc->config()->setIndentationMode(KateAutoIndent::modeName(action->data().toInt())); + doc->config()->set("Indentation Mode", KateAutoIndent::modeName(action->data().toInt())); doc->rememberUserDidSetIndentationMode(); } //END KateViewIndentationAction diff --git a/src/utils/katecmds.cpp b/src/utils/katecmds.cpp --- a/src/utils/katecmds.cpp +++ b/src/utils/katecmds.cpp @@ -302,7 +302,7 @@ } if (cmd == QLatin1String("set-indent-mode")) { - v->doc()->config()->setIndentationMode(args.join(QLatin1Char(' '))); + v->doc()->config()->set("Indentation Mode", args.join(QLatin1Char(' '))); v->doc()->rememberUserDidSetIndentationMode(); return true; } else if (cmd == QLatin1String("set-highlight")) { @@ -346,8 +346,8 @@ } v->doc()->config()->setIndentationWidth(val); } else if (cmd == QLatin1String("set-word-wrap-column")) { - if (val < 2) { - KCC_ERR(i18n("Column must be at least 1.")); + if (!v->doc()->config()->isValid("Word Wrap Column", val)) { + KCC_ERR(v->doc()->config()->intHint("Word Wrap Column")); } v->doc()->setWordWrapAt(val); } else if (cmd == QLatin1String("goto")) { diff --git a/src/utils/kateconfig.h b/src/utils/kateconfig.h --- a/src/utils/kateconfig.h +++ b/src/utils/kateconfig.h @@ -61,6 +61,11 @@ */ virtual ~KateConfig(); + virtual bool isGlobal() const = 0; + +protected: + virtual KateConfig *staticGlobal() = 0; + public: /** * start some config changes @@ -76,22 +81,161 @@ */ void configEnd(); + enum DataType { + BoolType = 0, + TriStateType, + IntengerType, + StringType + }; + + struct DataSet { + DataSet(DataType _type, QVariant _defaultVal, int _minValue, int _maxValue) + : defaultValue(_defaultVal) + , type(_type) + , minValue(_minValue) + , maxValue(_maxValue) + {}; + + DataSet() = default; // Needed to put it in a QHash + + // QStringList possibleValues() { ... }; // To fetch in a save way for type=string + + QVariant value; + QVariant defaultValue; + DataType type = BoolType; // Well, there is QVariant::type() so perhaps not needed + bool changed = false; + int minValue = std::numeric_limits::min(); + int maxValue = std::numeric_limits::max(); + + protected: + // foo-bar func-ref return QStringList with valid values for type=string + }; + + /** + * Despite the fact that all data goes to some QVariant, we have for each + * kind of data type a special set function to do some validation check at + * developing time + */ + void set(const char *key, bool on); + void set(const char *key, int val); + void set(const char *key, const QString &str); + + /** + * Access functions to our settings + */ + bool isSet(const char *key) /*const*/; + int intVal(const char *key) /*const*/; + QString stringVal(const char *key) /*const*/; + + /** + * General access to our setting to ask for any attribute + */ + const DataSet &data(const char *key) { + const QString k = QLatin1String(key); + Q_ASSERT_X(m_data.contains(k), "Validate Key", key); + return m_data[k]; + }; + + // See katecmds.cpp~348 + bool isValid(const char *key, int val) { + const QString k = QLatin1String(key); + Q_ASSERT_X(m_data.contains(k), "Validate Key", key); + DataSet &data = dataSet(key); + return (data.minValue <= val && data.maxValue >= val); + }; + QString intHint(const char *key); + + /** + * To fetch a list of all available keys of type settingsType. + * If settingsType is negative, all keys are returned. + * + * May be needed when apply to ... + * DocumentPrivate::readVariableLine + * KateCommands::CoreCommands + * VariableLineEdit::addKateItems + * ...in a general way. + */ +// QStringList keyList(int settingsType = -1); + + /** + * May handy at DocumentPrivate::readVariableLine + * Perhaps return bool to indicate bad key or return int bad key=1/value=2 + * Perhaps only part of KateDocumentConfig + */ +// void setByHyphenKey(QString key, QVariant val); + + /** + * Once assigned the action, there is no need to add extra slots elsewhere + * to kepp action and setting in sync. + * + * Unfortunatly run I quckly in trouble once Q_OBJECT/: public QObject was + * added. 2nd problem is that KToggleAction/QAction has no signal with + * included sender, but QActionGroup has. But can an action belong to more + * than one group? + */ +// void assignAction(const char *key, KToggleAction *action); + protected: /** * do the real update */ virtual void updateConfig() = 0; + /** + * One register function per settings type to keep things simple and sane + */ + void registerBool(const char *key, const bool defaultVal) { + registerSetting(key, BoolType, defaultVal); + } + void registerInteger(const char *key, const int defaultVal, const int minVal = std::numeric_limits::min() + , const int maxValue = std::numeric_limits::max()) + { + Q_ASSERT_X(minVal < maxValue, "Validate Min/Max", key); + Q_ASSERT_X(minVal < defaultVal && maxValue > defaultVal, "Validate DefaultVal", key); + registerSetting(key, IntengerType, defaultVal, minVal, maxValue); + } + void registerString(const char *key, const char *defaultVal/*, TODO func ref to fetch valid values*/) { + registerSetting(key, StringType, QLatin1String(defaultVal)); + } + + /** + * Little helper to get the requested setting + */ + DataSet &dataSet(const char *key) { + const QString k = QLatin1String(key); + Q_ASSERT_X(m_data.contains(k), "Validate Key", key); + return m_data[k]; + }; + + void readConfig(const KConfigGroup &config); + void writeConfig(KConfigGroup &config); + private: /** - * recursion depth + * This general set version is only used by KateConfig::readConfig() + */ + void set(const QString &key, const QVariant &val); + + /** + * General register function, not intended for direct use, choose registerFoo instead + */ + void registerSetting(const char *key, const DataType type, const QVariant &defaultVal + , const int minVal = std::numeric_limits::min(), const int maxValue = std::numeric_limits::max()) + { + Q_ASSERT_X(!m_data.contains(QLatin1String(key)), "Validate Unique Key", key); + DataSet data(type, defaultVal, minVal, maxValue); + m_data.insert(QLatin1String(key), data); + }; + + /** + * Our config brain */ - uint configSessionNumber = 0; + QHash m_data; /** - * is a config session running + * config session recursion depth, when >0 is a config session running */ - bool configIsRunning = false; + uint m_configSessionNumber = 0; }; class KTEXTEDITOR_EXPORT KateGlobalConfig : public KateConfig @@ -110,11 +254,14 @@ ~KateGlobalConfig() override; public: - static KateGlobalConfig *global() - { + static KateGlobalConfig *global() { return s_global; } + bool isGlobal() const override { + return (this == global()); + } + public: /** * Read config from object @@ -129,6 +276,11 @@ protected: void updateConfig() override; + KateConfig *staticGlobal() override + { + return global(); + } + public: KEncodingProber::ProberType proberType() const { @@ -169,13 +321,11 @@ */ ~KateDocumentConfig() override; - inline static KateDocumentConfig *global() - { + static KateDocumentConfig *global() { return s_global; } - inline bool isGlobal() const - { + bool isGlobal() const override { return (this == global()); } @@ -193,16 +343,20 @@ protected: void updateConfig() override; + void init(); + + KateConfig *staticGlobal() override + { + return global(); + } + public: int tabWidth() const; void setTabWidth(int tabWidth); int indentationWidth() const; void setIndentationWidth(int indentationWidth); - const QString &indentationMode() const; - void setIndentationMode(const QString &identationMode); - enum TabHandling { tabInsertsTab = 0, tabIndents = 1, @@ -212,12 +366,6 @@ uint tabHandling() const; void setTabHandling(uint tabHandling); - bool wordWrap() const; - void setWordWrap(bool on); - - int wordWrapAt() const; - void setWordWrapAt(int col); - bool pageUpDownMovesCursor() const; void setPageUpDownMovesCursor(bool on); @@ -322,13 +470,10 @@ void setLineLengthLimit(int limit); private: - QString m_indentationMode; int m_indentationWidth = 2; int m_tabWidth = 4; uint m_tabHandling = tabSmart; uint m_configFlags = 0; - int m_wordWrapAt = 80; - bool m_wordWrap; bool m_pageUpDownMovesCursor; bool m_allowEolDetection; int m_eol; @@ -345,9 +490,6 @@ bool m_tabWidthSet : 1; bool m_indentationWidthSet : 1; - bool m_indentationModeSet : 1; - bool m_wordWrapSet : 1; - bool m_wordWrapAtSet : 1; bool m_pageUpDownMovesCursorSet : 1; bool m_keepExtraSpacesSet : 1; @@ -413,13 +555,11 @@ */ ~KateViewConfig() override; - inline static KateViewConfig *global() - { + static KateViewConfig *global() { return s_global; } - inline bool isGlobal() const - { + bool isGlobal() const override { return (this == global()); } @@ -437,6 +577,11 @@ protected: void updateConfig() override; + KateConfig *staticGlobal() override + { + return global(); + } + public: bool dynWordWrapSet() const { @@ -690,13 +835,11 @@ */ ~KateRendererConfig() override; - inline static KateRendererConfig *global() - { + static KateRendererConfig *global() { return s_global; } - inline bool isGlobal() const - { + bool isGlobal() const override { return (this == global()); } @@ -714,6 +857,11 @@ protected: void updateConfig() override; + KateConfig *staticGlobal() override + { + return global(); + } + public: const QString &schema() const; void setSchema(const QString &schema); diff --git a/src/utils/kateconfig.cpp b/src/utils/kateconfig.cpp --- a/src/utils/kateconfig.cpp +++ b/src/utils/kateconfig.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -47,30 +48,159 @@ void KateConfig::configStart() { - configSessionNumber++; + m_configSessionNumber++; +} - if (configSessionNumber > 1) { +void KateConfig::configEnd() +{ + if (m_configSessionNumber == 0) { return; } - configIsRunning = true; + m_configSessionNumber--; + + if (m_configSessionNumber > 0) { + return; + } + + updateConfig(); } -void KateConfig::configEnd() +void KateConfig::set(const char *key, bool on) { - if (configSessionNumber == 0) { + DataSet &data = dataSet(key); + Q_ASSERT(data.type == BoolType); + + if (data.changed && data.value.toBool() == on) { return; } - configSessionNumber--; + configStart(); + + data.changed = true; + data.value = on; + + configEnd(); +} + +void KateConfig::set(const char *key, int val) +{ + DataSet &data = dataSet(key); + Q_ASSERT(data.type == IntengerType); + + // Ensure we are in bounds of valid range + val = std::min(std::max(val, data.minValue), data.maxValue); - if (configSessionNumber > 0) { + if (data.changed && data.value.toInt() == val) { return; } - configIsRunning = false; + configStart(); - updateConfig(); + data.changed = true; + data.value = val; + + configEnd(); +} + +void KateConfig::set(const char *key, const QString &str) +{ + DataSet &data = dataSet(key); + Q_ASSERT(data.type == StringType); + + if (data.changed && data.value.toString() == str) { + return; + } + + configStart(); + + data.changed = true; + data.value = str; + + configEnd(); +} + +void KateConfig::set(const QString &key, const QVariant &val) +{ + DataSet &data = dataSet(key.toLatin1().constData()); + + if (data.changed && data.value == val) { + return; + } + + configStart(); + + data.changed = true; + data.value = val; + + configEnd(); +} + +bool KateConfig::isSet(const char *key) /*const*/ +{ + const DataSet &data = dataSet(key); + Q_ASSERT(data.type == BoolType); + + if (data.changed || isGlobal()) { + return data.value.toBool(); + } + + return staticGlobal()->isSet(key); +} + +int KateConfig::intVal(const char *key) /*const*/ +{ + const DataSet &data = dataSet(key); + Q_ASSERT(data.type == IntengerType); + + if (data.changed || isGlobal()) { + return data.value.toInt(); + } + + return staticGlobal()->intVal(key); +} + +QString KateConfig::intHint(const char *key) +{ + const QString k = QLatin1String(key); + Q_ASSERT_X(m_data.contains(k), "Validate Key", key); + DataSet &data = dataSet(key); + return i18n("Value must between %1 and %2", data.minValue, data.maxValue); +} + +QString KateConfig::stringVal(const char *key) /*const*/ +{ + const DataSet &data = dataSet(key); + Q_ASSERT(data.type == StringType); + + if (data.changed || isGlobal()) { + return data.value.toString(); + } + + return staticGlobal()->stringVal(key); +} + +void KateConfig::readConfig(const KConfigGroup &config) +{ + configStart(); + + QHashIterator i(m_data); + while (i.hasNext()) { + i.next(); + set(i.key(), config.readEntry(i.key(), i.value().defaultValue)); + } + + configEnd(); +} + +void KateConfig::writeConfig(KConfigGroup &config) +{ + QHashIterator i(m_data); + while (i.hasNext()) { + i.next(); + // Q: Only write when changed? + config.writeEntry(i.key(), i.value().value); + } } //END @@ -103,14 +233,18 @@ { configStart(); + KateConfig::readConfig(config); + setProberType((KEncodingProber::ProberType)config.readEntry(KEY_PROBER_TYPE, (int)KEncodingProber::Universal)); setFallbackEncoding(config.readEntry(KEY_FALLBACK_ENCODING, "")); configEnd(); } void KateGlobalConfig::writeConfig(KConfigGroup &config) { + KateConfig::writeConfig(config); + config.writeEntry(KEY_PROBER_TYPE, (int)proberType()); config.writeEntry(KEY_FALLBACK_ENCODING, fallbackEncoding()); } @@ -168,9 +302,6 @@ KateDocumentConfig::KateDocumentConfig() : m_tabWidthSet(false), m_indentationWidthSet(false), - m_indentationModeSet(false), - m_wordWrapSet(false), - m_wordWrapAtSet(false), m_pageUpDownMovesCursorSet(false), m_keepExtraSpacesSet(false), m_indentPastedTextSet(false), @@ -199,7 +330,7 @@ { s_global = this; - + init(); // init with defaults from config or really hardcoded ones KConfigGroup cg(KTextEditor::EditorPrivate::config(), "KTextEditor Document"); readConfig(cg); @@ -210,12 +341,8 @@ m_tabWidth(4), m_tabHandling(tabSmart), m_configFlags(0), - m_wordWrapAt(80), m_tabWidthSet(false), m_indentationWidthSet(false), - m_indentationModeSet(false), - m_wordWrapSet(false), - m_wordWrapAtSet(false), m_pageUpDownMovesCursorSet(false), m_keepExtraSpacesSet(false), m_indentPastedTextSet(false), @@ -243,6 +370,7 @@ m_lineLengthLimitSet(false), m_doc(nullptr) { + init(); // init with defaults from config or really hardcoded ones readConfig(cg); } @@ -252,9 +380,6 @@ m_configFlags(0), m_tabWidthSet(false), m_indentationWidthSet(false), - m_indentationModeSet(false), - m_wordWrapSet(false), - m_wordWrapAtSet(false), m_pageUpDownMovesCursorSet(false), m_keepExtraSpacesSet(false), m_indentPastedTextSet(false), @@ -282,6 +407,15 @@ m_lineLengthLimitSet(false), m_doc(doc) { + init(); +} + +void KateDocumentConfig::init() +{ + // I fear you will dislike that and want initializer lists + registerInteger("Word Wrap Column", 80, 20, 200); // Range used in config dialog and variablelineedit.cpp~347, but autotest used also 10! + registerBool("Word Wrap", false); + registerString("Indentation Mode", "normal"); } KateDocumentConfig::~KateDocumentConfig() @@ -292,10 +426,7 @@ { const char KEY_TAB_WIDTH[] = "Tab Width"; const char KEY_INDENTATION_WIDTH[] = "Indentation Width"; -const char KEY_INDENTATION_MODE[] = "Indentation Mode"; const char KEY_TAB_HANDLING[] = "Tab Handling"; -const char KEY_WORD_WRAP[] = "Word Wrap"; -const char KEY_WORD_WRAP_AT[] = "Word Wrap Column"; const char KEY_PAGEUP_DOWN_MOVES_CURSOR[] = "PageUp/PageDown Moves Cursor"; const char KEY_SMART_HOME[] = "Smart Home"; const char KEY_SHOW_TABS[] = "Show Tabs"; @@ -327,16 +458,14 @@ { configStart(); + KateConfig::readConfig(config); + setTabWidth(config.readEntry(KEY_TAB_WIDTH, 4)); setIndentationWidth(config.readEntry(KEY_INDENTATION_WIDTH, 4)); - setIndentationMode(config.readEntry(KEY_INDENTATION_MODE, "normal")); - setTabHandling(config.readEntry(KEY_TAB_HANDLING, int(KateDocumentConfig::tabSmart))); - setWordWrap(config.readEntry(KEY_WORD_WRAP, false)); - setWordWrapAt(config.readEntry(KEY_WORD_WRAP_AT, 80)); setPageUpDownMovesCursor(config.readEntry(KEY_PAGEUP_DOWN_MOVES_CURSOR, false)); setSmartHome(config.readEntry(KEY_SMART_HOME, true)); @@ -378,16 +507,14 @@ void KateDocumentConfig::writeConfig(KConfigGroup &config) { + KateConfig::writeConfig(config); + config.writeEntry(KEY_TAB_WIDTH, tabWidth()); config.writeEntry(KEY_INDENTATION_WIDTH, indentationWidth()); - config.writeEntry(KEY_INDENTATION_MODE, indentationMode()); config.writeEntry(KEY_TAB_HANDLING, tabHandling()); - config.writeEntry(KEY_WORD_WRAP, wordWrap()); - config.writeEntry(KEY_WORD_WRAP_AT, wordWrapAt()); - config.writeEntry(KEY_PAGEUP_DOWN_MOVES_CURSOR, pageUpDownMovesCursor()); config.writeEntry(KEY_SMART_HOME, smartHome()); @@ -498,29 +625,6 @@ configEnd(); } -const QString &KateDocumentConfig::indentationMode() const -{ - if (m_indentationModeSet || isGlobal()) { - return m_indentationMode; - } - - return s_global->indentationMode(); -} - -void KateDocumentConfig::setIndentationMode(const QString &indentationMode) -{ - if (m_indentationModeSet && m_indentationMode == indentationMode) { - return; - } - - configStart(); - - m_indentationModeSet = true; - m_indentationMode = indentationMode; - - configEnd(); -} - uint KateDocumentConfig::tabHandling() const { // This setting is purely a user preference, @@ -541,56 +645,6 @@ configEnd(); } -bool KateDocumentConfig::wordWrap() const -{ - if (m_wordWrapSet || isGlobal()) { - return m_wordWrap; - } - - return s_global->wordWrap(); -} - -void KateDocumentConfig::setWordWrap(bool on) -{ - if (m_wordWrapSet && m_wordWrap == on) { - return; - } - - configStart(); - - m_wordWrapSet = true; - m_wordWrap = on; - - configEnd(); -} - -int KateDocumentConfig::wordWrapAt() const -{ - if (m_wordWrapAtSet || isGlobal()) { - return m_wordWrapAt; - } - - return s_global->wordWrapAt(); -} - -void KateDocumentConfig::setWordWrapAt(int col) -{ - if (col < 1) { - return; - } - - if (m_wordWrapAtSet && m_wordWrapAt == col) { - return; - } - - configStart(); - - m_wordWrapAtSet = true; - m_wordWrapAt = col; - - configEnd(); -} - bool KateDocumentConfig::pageUpDownMovesCursor() const { if (m_pageUpDownMovesCursorSet || isGlobal()) { @@ -1370,6 +1424,8 @@ { configStart(); + KateConfig::readConfig(config); + // default on setDynWordWrap(config.readEntry(KEY_DYN_WORD_WRAP, true)); setDynWrapAtStaticMarker(config.readEntry(KEY_DYN_WORD_WRAP_AT_STATIC_MARKER, false)); @@ -1436,6 +1492,8 @@ void KateViewConfig::writeConfig(KConfigGroup &config) { + KateConfig::writeConfig(config); + config.writeEntry(KEY_DYN_WORD_WRAP, dynWordWrap()); config.writeEntry(KEY_DYN_WORD_WRAP_AT_STATIC_MARKER, dynWrapAtStaticMarker()); config.writeEntry(KEY_DYN_WORD_WRAP_INDICATORS, dynWordWrapIndicators()); @@ -2443,6 +2501,8 @@ { configStart(); + KateConfig::readConfig(config); + // "Normal" Schema MUST BE THERE, see global kateschemarc setSchema(config.readEntry(KEY_SCHEMA, "Normal")); @@ -2459,6 +2519,8 @@ void KateRendererConfig::writeConfig(KConfigGroup &config) { + KateConfig::writeConfig(config); + config.writeEntry(KEY_SCHEMA, schema()); config.writeEntry(KEY_WORD_WRAP_MARKER, wordWrapMarker()); diff --git a/src/variableeditor/variablelineedit.cpp b/src/variableeditor/variablelineedit.cpp --- a/src/variableeditor/variablelineedit.cpp +++ b/src/variableeditor/variablelineedit.cpp @@ -236,7 +236,7 @@ listview->addItem(item); // Add 'indent-mode' to list - item = new VariableStringListItem(QStringLiteral("indent-mode"), KateAutoIndent::listIdentifiers(), docConfig->indentationMode()); + item = new VariableStringListItem(QStringLiteral("indent-mode"), KateAutoIndent::listIdentifiers(), docConfig->stringVal("Indentation Mode")); item->setHelpText(i18nc("short translation please", "Set the auto indentation style.")); listview->addItem(item); @@ -343,8 +343,8 @@ listview->addItem(item); // Add 'word-wrap-column' to list - item = new VariableIntItem(QStringLiteral("word-wrap-column"), docConfig->wordWrapAt()); - static_cast(item)->setRange(20, 200); + item = new VariableIntItem(QStringLiteral("word-wrap-column"), docConfig->intVal("Word Wrap Column")); + static_cast(item)->setRange(docConfig->data("Word Wrap Column").minValue, docConfig->data("Word Wrap Column").maxValue); item->setHelpText(i18nc("short translation please", "Set the word wrap column.")); listview->addItem(item); @@ -354,7 +354,7 @@ listview->addItem(item); // Add 'word-wrap' to list - item = new VariableBoolItem(QStringLiteral("word-wrap"), docConfig->wordWrap()); + item = new VariableBoolItem(QStringLiteral("word-wrap"), docConfig->isSet("Word Wrap")); item->setHelpText(i18nc("short translation please", "Enable word wrap while typing text.")); listview->addItem(item); } diff --git a/src/view/kateviewinternal.cpp b/src/view/kateviewinternal.cpp --- a/src/view/kateviewinternal.cpp +++ b/src/view/kateviewinternal.cpp @@ -617,7 +617,7 @@ int wrapWidth = width(); if (view()->config()->dynWrapAtStaticMarker() && view()->config()->dynWordWrap()) { // We need to transform char count to a pixel width, stolen from PrintPainter::updateCache() - QString s; s.fill(QLatin1Char('5'), view()->doc()->config()->wordWrapAt()); + QString s; s.fill(QLatin1Char('5'), view()->doc()->config()->intVal("Word Wrap Column")); wrapWidth = qMin(width(), static_cast(renderer()->currentFontMetrics().width(s))); }