Changeset View
Changeset View
Standalone View
Standalone View
src/utils/kateconfig.h
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Line(s) | 53 | public: | |||
---|---|---|---|---|---|
56 | */ | 56 | */ | ||
57 | KateConfig(); | 57 | KateConfig(); | ||
58 | 58 | | |||
59 | /** | 59 | /** | ||
60 | * Virtual Destructor | 60 | * Virtual Destructor | ||
61 | */ | 61 | */ | ||
62 | virtual ~KateConfig(); | 62 | virtual ~KateConfig(); | ||
63 | 63 | | |||
64 | virtual bool isGlobal() const = 0; | ||||
65 | | ||||
66 | protected: | ||||
67 | virtual KateConfig *staticGlobal() = 0; | ||||
68 | | ||||
64 | public: | 69 | public: | ||
65 | /** | 70 | /** | ||
66 | * start some config changes | 71 | * start some config changes | ||
67 | * this method is needed to init some kind of transaction | 72 | * this method is needed to init some kind of transaction | ||
68 | * for config changes, update will only be done once, at | 73 | * for config changes, update will only be done once, at | ||
69 | * configEnd() call | 74 | * configEnd() call | ||
70 | */ | 75 | */ | ||
71 | void configStart(); | 76 | void configStart(); | ||
72 | 77 | | |||
73 | /** | 78 | /** | ||
74 | * end a config change transaction, update the concerned | 79 | * end a config change transaction, update the concerned | ||
75 | * documents/views/renderers | 80 | * documents/views/renderers | ||
76 | */ | 81 | */ | ||
77 | void configEnd(); | 82 | void configEnd(); | ||
78 | 83 | | |||
84 | enum DataType { | ||||
85 | BoolType = 0, | ||||
86 | TriStateType, | ||||
87 | IntengerType, | ||||
88 | StringType | ||||
89 | }; | ||||
90 | | ||||
91 | struct DataSet { | ||||
92 | DataSet(DataType _type, QVariant _defaultVal, int _minValue, int _maxValue) | ||||
93 | : defaultValue(_defaultVal) | ||||
94 | , type(_type) | ||||
95 | , minValue(_minValue) | ||||
96 | , maxValue(_maxValue) | ||||
97 | {}; | ||||
98 | | ||||
99 | DataSet() = default; // Needed to put it in a QHash | ||||
100 | | ||||
101 | // QStringList possibleValues() { ... }; // To fetch in a save way for type=string | ||||
102 | | ||||
103 | QVariant value; | ||||
104 | QVariant defaultValue; | ||||
105 | DataType type = BoolType; // Well, there is QVariant::type() so perhaps not needed | ||||
106 | bool changed = false; | ||||
107 | int minValue = std::numeric_limits<int>::min(); | ||||
108 | int maxValue = std::numeric_limits<int>::max(); | ||||
109 | | ||||
110 | protected: | ||||
111 | // foo-bar func-ref return QStringList with valid values for type=string | ||||
112 | }; | ||||
113 | | ||||
114 | /** | ||||
115 | * Despite the fact that all data goes to some QVariant, we have for each | ||||
116 | * kind of data type a special set function to do some validation check at | ||||
117 | * developing time | ||||
118 | */ | ||||
119 | void set(const char *key, bool on); | ||||
120 | void set(const char *key, int val); | ||||
121 | void set(const char *key, const QString &str); | ||||
122 | | ||||
123 | /** | ||||
124 | * Access functions to our settings | ||||
125 | */ | ||||
126 | bool isSet(const char *key) /*const*/; | ||||
127 | int intVal(const char *key) /*const*/; | ||||
128 | QString stringVal(const char *key) /*const*/; | ||||
129 | | ||||
130 | /** | ||||
131 | * General access to our setting to ask for any attribute | ||||
132 | */ | ||||
133 | const DataSet &data(const char *key) { | ||||
134 | const QString k = QLatin1String(key); | ||||
135 | Q_ASSERT_X(m_data.contains(k), "Validate Key", key); | ||||
136 | return m_data[k]; | ||||
137 | }; | ||||
138 | | ||||
139 | // See katecmds.cpp~348 | ||||
140 | bool isValid(const char *key, int val) { | ||||
141 | const QString k = QLatin1String(key); | ||||
142 | Q_ASSERT_X(m_data.contains(k), "Validate Key", key); | ||||
143 | DataSet &data = dataSet(key); | ||||
144 | return (data.minValue <= val && data.maxValue >= val); | ||||
145 | }; | ||||
146 | QString intHint(const char *key); | ||||
147 | | ||||
148 | /** | ||||
149 | * To fetch a list of all available keys of type settingsType. | ||||
150 | * If settingsType is negative, all keys are returned. | ||||
151 | * | ||||
152 | * May be needed when apply to ... | ||||
153 | * DocumentPrivate::readVariableLine | ||||
154 | * KateCommands::CoreCommands | ||||
155 | * VariableLineEdit::addKateItems | ||||
156 | * ...in a general way. | ||||
157 | */ | ||||
158 | // QStringList keyList(int settingsType = -1); | ||||
159 | | ||||
160 | /** | ||||
161 | * May handy at DocumentPrivate::readVariableLine | ||||
162 | * Perhaps return bool to indicate bad key or return int bad key=1/value=2 | ||||
163 | * Perhaps only part of KateDocumentConfig | ||||
164 | */ | ||||
165 | // void setByHyphenKey(QString key, QVariant val); | ||||
166 | | ||||
167 | /** | ||||
168 | * Once assigned the action, there is no need to add extra slots elsewhere | ||||
169 | * to kepp action and setting in sync. | ||||
170 | * | ||||
171 | * Unfortunatly run I quckly in trouble once Q_OBJECT/: public QObject was | ||||
172 | * added. 2nd problem is that KToggleAction/QAction has no signal with | ||||
173 | * included sender, but QActionGroup has. But can an action belong to more | ||||
174 | * than one group? | ||||
175 | */ | ||||
176 | // void assignAction(const char *key, KToggleAction *action); | ||||
177 | | ||||
79 | protected: | 178 | protected: | ||
80 | /** | 179 | /** | ||
81 | * do the real update | 180 | * do the real update | ||
82 | */ | 181 | */ | ||
83 | virtual void updateConfig() = 0; | 182 | virtual void updateConfig() = 0; | ||
84 | 183 | | |||
184 | /** | ||||
185 | * One register function per settings type to keep things simple and sane | ||||
186 | */ | ||||
187 | void registerBool(const char *key, const bool defaultVal) { | ||||
188 | registerSetting(key, BoolType, defaultVal); | ||||
189 | } | ||||
190 | void registerInteger(const char *key, const int defaultVal, const int minVal = std::numeric_limits<int>::min() | ||||
191 | , const int maxValue = std::numeric_limits<int>::max()) | ||||
192 | { | ||||
193 | Q_ASSERT_X(minVal < maxValue, "Validate Min/Max", key); | ||||
194 | Q_ASSERT_X(minVal < defaultVal && maxValue > defaultVal, "Validate DefaultVal", key); | ||||
195 | registerSetting(key, IntengerType, defaultVal, minVal, maxValue); | ||||
196 | } | ||||
197 | void registerString(const char *key, const char *defaultVal/*, TODO func ref to fetch valid values*/) { | ||||
198 | registerSetting(key, StringType, QLatin1String(defaultVal)); | ||||
199 | } | ||||
200 | | ||||
201 | /** | ||||
202 | * Little helper to get the requested setting | ||||
203 | */ | ||||
204 | DataSet &dataSet(const char *key) { | ||||
205 | const QString k = QLatin1String(key); | ||||
206 | Q_ASSERT_X(m_data.contains(k), "Validate Key", key); | ||||
207 | return m_data[k]; | ||||
208 | }; | ||||
209 | | ||||
210 | void readConfig(const KConfigGroup &config); | ||||
211 | void writeConfig(KConfigGroup &config); | ||||
212 | | ||||
85 | private: | 213 | private: | ||
86 | /** | 214 | /** | ||
87 | * recursion depth | 215 | * This general set version is only used by KateConfig::readConfig() | ||
216 | */ | ||||
217 | void set(const QString &key, const QVariant &val); | ||||
218 | | ||||
219 | /** | ||||
220 | * General register function, not intended for direct use, choose registerFoo instead | ||||
221 | */ | ||||
222 | void registerSetting(const char *key, const DataType type, const QVariant &defaultVal | ||||
223 | , const int minVal = std::numeric_limits<int>::min(), const int maxValue = std::numeric_limits<int>::max()) | ||||
224 | { | ||||
225 | Q_ASSERT_X(!m_data.contains(QLatin1String(key)), "Validate Unique Key", key); | ||||
226 | DataSet data(type, defaultVal, minVal, maxValue); | ||||
227 | m_data.insert(QLatin1String(key), data); | ||||
228 | }; | ||||
229 | | ||||
230 | /** | ||||
231 | * Our config brain | ||||
88 | */ | 232 | */ | ||
89 | uint configSessionNumber = 0; | 233 | QHash<QString, DataSet> m_data; | ||
90 | 234 | | |||
91 | /** | 235 | /** | ||
92 | * is a config session running | 236 | * config session recursion depth, when >0 is a config session running | ||
93 | */ | 237 | */ | ||
94 | bool configIsRunning = false; | 238 | uint m_configSessionNumber = 0; | ||
95 | }; | 239 | }; | ||
96 | 240 | | |||
97 | class KTEXTEDITOR_EXPORT KateGlobalConfig : public KateConfig | 241 | class KTEXTEDITOR_EXPORT KateGlobalConfig : public KateConfig | ||
98 | { | 242 | { | ||
99 | private: | 243 | private: | ||
100 | friend class KTextEditor::EditorPrivate; | 244 | friend class KTextEditor::EditorPrivate; | ||
101 | 245 | | |||
102 | /** | 246 | /** | ||
103 | * only used in KTextEditor::EditorPrivate for the static global fallback !!! | 247 | * only used in KTextEditor::EditorPrivate for the static global fallback !!! | ||
104 | */ | 248 | */ | ||
105 | KateGlobalConfig(); | 249 | KateGlobalConfig(); | ||
106 | 250 | | |||
107 | /** | 251 | /** | ||
108 | * Destructor | 252 | * Destructor | ||
109 | */ | 253 | */ | ||
110 | ~KateGlobalConfig() override; | 254 | ~KateGlobalConfig() override; | ||
111 | 255 | | |||
112 | public: | 256 | public: | ||
113 | static KateGlobalConfig *global() | 257 | static KateGlobalConfig *global() { | ||
114 | { | | |||
115 | return s_global; | 258 | return s_global; | ||
116 | } | 259 | } | ||
117 | 260 | | |||
261 | bool isGlobal() const override { | ||||
262 | return (this == global()); | ||||
263 | } | ||||
264 | | ||||
118 | public: | 265 | public: | ||
119 | /** | 266 | /** | ||
120 | * Read config from object | 267 | * Read config from object | ||
121 | */ | 268 | */ | ||
122 | void readConfig(const KConfigGroup &config); | 269 | void readConfig(const KConfigGroup &config); | ||
123 | 270 | | |||
124 | /** | 271 | /** | ||
125 | * Write config to object | 272 | * Write config to object | ||
126 | */ | 273 | */ | ||
127 | void writeConfig(KConfigGroup &config); | 274 | void writeConfig(KConfigGroup &config); | ||
128 | 275 | | |||
129 | protected: | 276 | protected: | ||
130 | void updateConfig() override; | 277 | void updateConfig() override; | ||
131 | 278 | | |||
279 | KateConfig *staticGlobal() override | ||||
280 | { | ||||
281 | return global(); | ||||
282 | } | ||||
283 | | ||||
132 | public: | 284 | public: | ||
133 | KEncodingProber::ProberType proberType() const | 285 | KEncodingProber::ProberType proberType() const | ||
134 | { | 286 | { | ||
135 | return m_proberType; | 287 | return m_proberType; | ||
136 | } | 288 | } | ||
137 | 289 | | |||
138 | void setProberType(KEncodingProber::ProberType proberType); | 290 | void setProberType(KEncodingProber::ProberType proberType); | ||
139 | 291 | | |||
Show All 24 Lines | 311 | public: | |||
164 | */ | 316 | */ | ||
165 | explicit KateDocumentConfig(KTextEditor::DocumentPrivate *doc); | 317 | explicit KateDocumentConfig(KTextEditor::DocumentPrivate *doc); | ||
166 | 318 | | |||
167 | /** | 319 | /** | ||
168 | * Cu DocumentConfig | 320 | * Cu DocumentConfig | ||
169 | */ | 321 | */ | ||
170 | ~KateDocumentConfig() override; | 322 | ~KateDocumentConfig() override; | ||
171 | 323 | | |||
172 | inline static KateDocumentConfig *global() | 324 | static KateDocumentConfig *global() { | ||
173 | { | | |||
174 | return s_global; | 325 | return s_global; | ||
175 | } | 326 | } | ||
176 | 327 | | |||
177 | inline bool isGlobal() const | 328 | bool isGlobal() const override { | ||
178 | { | | |||
179 | return (this == global()); | 329 | return (this == global()); | ||
180 | } | 330 | } | ||
181 | 331 | | |||
182 | public: | 332 | public: | ||
183 | /** | 333 | /** | ||
184 | * Read config from object | 334 | * Read config from object | ||
185 | */ | 335 | */ | ||
186 | void readConfig(const KConfigGroup &config); | 336 | void readConfig(const KConfigGroup &config); | ||
187 | 337 | | |||
188 | /** | 338 | /** | ||
189 | * Write config to object | 339 | * Write config to object | ||
190 | */ | 340 | */ | ||
191 | void writeConfig(KConfigGroup &config); | 341 | void writeConfig(KConfigGroup &config); | ||
192 | 342 | | |||
193 | protected: | 343 | protected: | ||
194 | void updateConfig() override; | 344 | void updateConfig() override; | ||
195 | 345 | | |||
346 | void init(); | ||||
347 | | ||||
348 | KateConfig *staticGlobal() override | ||||
349 | { | ||||
350 | return global(); | ||||
351 | } | ||||
352 | | ||||
196 | public: | 353 | public: | ||
197 | int tabWidth() const; | 354 | int tabWidth() const; | ||
198 | void setTabWidth(int tabWidth); | 355 | void setTabWidth(int tabWidth); | ||
199 | 356 | | |||
200 | int indentationWidth() const; | 357 | int indentationWidth() const; | ||
201 | void setIndentationWidth(int indentationWidth); | 358 | void setIndentationWidth(int indentationWidth); | ||
202 | 359 | | |||
203 | const QString &indentationMode() const; | | |||
204 | void setIndentationMode(const QString &identationMode); | | |||
205 | | ||||
206 | enum TabHandling { | 360 | enum TabHandling { | ||
207 | tabInsertsTab = 0, | 361 | tabInsertsTab = 0, | ||
208 | tabIndents = 1, | 362 | tabIndents = 1, | ||
209 | tabSmart = 2 //!< indents in leading space, otherwise inserts tab | 363 | tabSmart = 2 //!< indents in leading space, otherwise inserts tab | ||
210 | }; | 364 | }; | ||
211 | 365 | | |||
212 | uint tabHandling() const; | 366 | uint tabHandling() const; | ||
213 | void setTabHandling(uint tabHandling); | 367 | void setTabHandling(uint tabHandling); | ||
214 | 368 | | |||
215 | bool wordWrap() const; | | |||
216 | void setWordWrap(bool on); | | |||
217 | | ||||
218 | int wordWrapAt() const; | | |||
219 | void setWordWrapAt(int col); | | |||
220 | | ||||
221 | bool pageUpDownMovesCursor() const; | 369 | bool pageUpDownMovesCursor() const; | ||
222 | void setPageUpDownMovesCursor(bool on); | 370 | void setPageUpDownMovesCursor(bool on); | ||
223 | 371 | | |||
224 | void setKeepExtraSpaces(bool on); | 372 | void setKeepExtraSpaces(bool on); | ||
225 | bool keepExtraSpaces() const; | 373 | bool keepExtraSpaces() const; | ||
226 | 374 | | |||
227 | void setIndentPastedText(bool on); | 375 | void setIndentPastedText(bool on); | ||
228 | bool indentPastedText() const; | 376 | bool indentPastedText() const; | ||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Line(s) | 391 | uint markerSize() const; | |||
317 | 465 | | |||
318 | bool onTheFlySpellCheck() const; | 466 | bool onTheFlySpellCheck() const; | ||
319 | void setOnTheFlySpellCheck(bool on); | 467 | void setOnTheFlySpellCheck(bool on); | ||
320 | 468 | | |||
321 | int lineLengthLimit() const; | 469 | int lineLengthLimit() const; | ||
322 | void setLineLengthLimit(int limit); | 470 | void setLineLengthLimit(int limit); | ||
323 | 471 | | |||
324 | private: | 472 | private: | ||
325 | QString m_indentationMode; | | |||
326 | int m_indentationWidth = 2; | 473 | int m_indentationWidth = 2; | ||
327 | int m_tabWidth = 4; | 474 | int m_tabWidth = 4; | ||
328 | uint m_tabHandling = tabSmart; | 475 | uint m_tabHandling = tabSmart; | ||
329 | uint m_configFlags = 0; | 476 | uint m_configFlags = 0; | ||
330 | int m_wordWrapAt = 80; | | |||
331 | bool m_wordWrap; | | |||
332 | bool m_pageUpDownMovesCursor; | 477 | bool m_pageUpDownMovesCursor; | ||
333 | bool m_allowEolDetection; | 478 | bool m_allowEolDetection; | ||
334 | int m_eol; | 479 | int m_eol; | ||
335 | bool m_bom; | 480 | bool m_bom; | ||
336 | uint m_backupFlags; | 481 | uint m_backupFlags; | ||
337 | QString m_encoding; | 482 | QString m_encoding; | ||
338 | QString m_backupPrefix; | 483 | QString m_backupPrefix; | ||
339 | QString m_backupSuffix; | 484 | QString m_backupSuffix; | ||
340 | uint m_swapFileMode; | 485 | uint m_swapFileMode; | ||
341 | QString m_swapDirectory; | 486 | QString m_swapDirectory; | ||
342 | uint m_swapSyncInterval; | 487 | uint m_swapSyncInterval; | ||
343 | bool m_onTheFlySpellCheck; | 488 | bool m_onTheFlySpellCheck; | ||
344 | int m_lineLengthLimit; | 489 | int m_lineLengthLimit; | ||
345 | 490 | | |||
346 | bool m_tabWidthSet : 1; | 491 | bool m_tabWidthSet : 1; | ||
347 | bool m_indentationWidthSet : 1; | 492 | bool m_indentationWidthSet : 1; | ||
348 | bool m_indentationModeSet : 1; | | |||
349 | bool m_wordWrapSet : 1; | | |||
350 | bool m_wordWrapAtSet : 1; | | |||
351 | bool m_pageUpDownMovesCursorSet : 1; | 493 | bool m_pageUpDownMovesCursorSet : 1; | ||
352 | 494 | | |||
353 | bool m_keepExtraSpacesSet : 1; | 495 | bool m_keepExtraSpacesSet : 1; | ||
354 | bool m_keepExtraSpaces : 1; | 496 | bool m_keepExtraSpaces : 1; | ||
355 | bool m_indentPastedTextSet : 1; | 497 | bool m_indentPastedTextSet : 1; | ||
356 | bool m_indentPastedText : 1; | 498 | bool m_indentPastedText : 1; | ||
357 | bool m_backspaceIndentsSet : 1; | 499 | bool m_backspaceIndentsSet : 1; | ||
358 | bool m_backspaceIndents : 1; | 500 | bool m_backspaceIndents : 1; | ||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | 547 | public: | |||
408 | */ | 550 | */ | ||
409 | explicit KateViewConfig(KTextEditor::ViewPrivate *view); | 551 | explicit KateViewConfig(KTextEditor::ViewPrivate *view); | ||
410 | 552 | | |||
411 | /** | 553 | /** | ||
412 | * Cu DocumentConfig | 554 | * Cu DocumentConfig | ||
413 | */ | 555 | */ | ||
414 | ~KateViewConfig() override; | 556 | ~KateViewConfig() override; | ||
415 | 557 | | |||
416 | inline static KateViewConfig *global() | 558 | static KateViewConfig *global() { | ||
417 | { | | |||
418 | return s_global; | 559 | return s_global; | ||
419 | } | 560 | } | ||
420 | 561 | | |||
421 | inline bool isGlobal() const | 562 | bool isGlobal() const override { | ||
422 | { | | |||
423 | return (this == global()); | 563 | return (this == global()); | ||
424 | } | 564 | } | ||
425 | 565 | | |||
426 | public: | 566 | public: | ||
427 | /** | 567 | /** | ||
428 | * Read config from object | 568 | * Read config from object | ||
429 | */ | 569 | */ | ||
430 | void readConfig(const KConfigGroup &config); | 570 | void readConfig(const KConfigGroup &config); | ||
431 | 571 | | |||
432 | /** | 572 | /** | ||
433 | * Write config to object | 573 | * Write config to object | ||
434 | */ | 574 | */ | ||
435 | void writeConfig(KConfigGroup &config); | 575 | void writeConfig(KConfigGroup &config); | ||
436 | 576 | | |||
437 | protected: | 577 | protected: | ||
438 | void updateConfig() override; | 578 | void updateConfig() override; | ||
439 | 579 | | |||
580 | KateConfig *staticGlobal() override | ||||
581 | { | ||||
582 | return global(); | ||||
583 | } | ||||
584 | | ||||
440 | public: | 585 | public: | ||
441 | bool dynWordWrapSet() const | 586 | bool dynWordWrapSet() const | ||
442 | { | 587 | { | ||
443 | return m_dynWordWrapSet; | 588 | return m_dynWordWrapSet; | ||
444 | } | 589 | } | ||
445 | bool dynWordWrap() const; | 590 | bool dynWordWrap() const; | ||
446 | void setDynWordWrap(bool wrap); | 591 | void setDynWordWrap(bool wrap); | ||
447 | 592 | | |||
▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Line(s) | 827 | public: | |||
685 | */ | 830 | */ | ||
686 | explicit KateRendererConfig(KateRenderer *renderer); | 831 | explicit KateRendererConfig(KateRenderer *renderer); | ||
687 | 832 | | |||
688 | /** | 833 | /** | ||
689 | * Cu DocumentConfig | 834 | * Cu DocumentConfig | ||
690 | */ | 835 | */ | ||
691 | ~KateRendererConfig() override; | 836 | ~KateRendererConfig() override; | ||
692 | 837 | | |||
693 | inline static KateRendererConfig *global() | 838 | static KateRendererConfig *global() { | ||
694 | { | | |||
695 | return s_global; | 839 | return s_global; | ||
696 | } | 840 | } | ||
697 | 841 | | |||
698 | inline bool isGlobal() const | 842 | bool isGlobal() const override { | ||
699 | { | | |||
700 | return (this == global()); | 843 | return (this == global()); | ||
701 | } | 844 | } | ||
702 | 845 | | |||
703 | public: | 846 | public: | ||
704 | /** | 847 | /** | ||
705 | * Read config from object | 848 | * Read config from object | ||
706 | */ | 849 | */ | ||
707 | void readConfig(const KConfigGroup &config); | 850 | void readConfig(const KConfigGroup &config); | ||
708 | 851 | | |||
709 | /** | 852 | /** | ||
710 | * Write config to object | 853 | * Write config to object | ||
711 | */ | 854 | */ | ||
712 | void writeConfig(KConfigGroup &config); | 855 | void writeConfig(KConfigGroup &config); | ||
713 | 856 | | |||
714 | protected: | 857 | protected: | ||
715 | void updateConfig() override; | 858 | void updateConfig() override; | ||
716 | 859 | | |||
860 | KateConfig *staticGlobal() override | ||||
861 | { | ||||
862 | return global(); | ||||
863 | } | ||||
864 | | ||||
717 | public: | 865 | public: | ||
718 | const QString &schema() const; | 866 | const QString &schema() const; | ||
719 | void setSchema(const QString &schema); | 867 | void setSchema(const QString &schema); | ||
720 | 868 | | |||
721 | /** | 869 | /** | ||
722 | * Reload the schema from the schema manager. | 870 | * Reload the schema from the schema manager. | ||
723 | * For the global instance, have all other instances reload. | 871 | * For the global instance, have all other instances reload. | ||
724 | * Used by the schema config page to apply changes. | 872 | * Used by the schema config page to apply changes. | ||
▲ Show 20 Lines • Show All 91 Lines • Show Last 20 Lines |