1/*
2 SPDX-FileCopyrightText: 2003 Christoph Cullmann <cullmann@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KATE_CONFIG_H
8#define KATE_CONFIG_H
9
10#include <ktexteditor_export.h>
11
12#include <ktexteditor/document.h>
13#include <ktexteditor/view.h>
14
15#include <functional>
16#include <map>
17#include <memory>
18
19#include <QBitArray>
20#include <QColor>
21#include <QList>
22#include <QObject>
23
24class KConfigGroup;
25namespace KTextEditor
26{
27class ViewPrivate;
28}
29namespace KTextEditor
30{
31class DocumentPrivate;
32}
33class KateRenderer;
34
35namespace KTextEditor
36{
37class EditorPrivate;
38}
39
40class KConfig;
41
42/**
43 * Base Class for the Kate Config Classes
44 * Current childs are KateDocumentConfig/KateDocumentConfig/KateDocumentConfig
45 */
46class KTEXTEDITOR_EXPORT KateConfig
47{
48public:
49 /**
50 * Start some config changes.
51 * This method is needed to init some kind of transaction for config changes,
52 * update will only be done once, at configEnd() call.
53 */
54 void configStart();
55
56 /**
57 * End a config change transaction, update the concerned
58 * KateDocumentConfig/KateDocumentConfig/KateDocumentConfig
59 */
60 void configEnd();
61
62 /**
63 * Is this a global config object?
64 * @return true when this is a global config object
65 */
66 bool isGlobal() const
67 {
68 return !m_parent;
69 }
70
71 /**
72 * All known config keys.
73 * This will use the knowledge about all registered keys of the global object.
74 * @return all known config keys
75 */
76 QStringList configKeys() const
77 {
78 return m_parent ? m_parent->configKeys() : *m_configKeys.get();
79 }
80
81 /**
82 * Is given key set in this config object?
83 * @param key config key, aka enum from KateConfig* classes
84 * @return is the wanted key set?
85 */
86 bool isSet(const int key) const
87 {
88 return m_configEntries.find(x: key) != m_configEntries.end();
89 }
90
91 /**
92 * Get a config value.
93 * @param key config key, aka enum from KateConfig* classes
94 * @return value for the wanted key, will assert if key is not valid
95 */
96 QVariant value(const int key) const;
97
98 /**
99 * Set a config value.
100 * Will assert if key is invalid.
101 * Might not alter the value if given value fails validation.
102 * @param key config key, aka enum from KateConfig* classes
103 * @param value value to set
104 * @return true on success
105 */
106 bool setValue(const int key, const QVariant &value);
107
108 /**
109 * Get a config value for the string key.
110 * @param key config key, aka commandName from KateConfig* classes
111 * @return value for the wanted key, will return invalid variant if key is not known
112 */
113 QVariant value(const QString &key) const;
114
115 /**
116 * Set a config value.
117 * Will do nothing if key is not known or the given value fails validation.
118 * @param key config key, aka commandName from KateConfig* classes
119 * @param value value to set
120 * @return true on success
121 */
122 bool setValue(const QString &key, const QVariant &value);
123
124protected:
125 /**
126 * Construct a KateConfig.
127 * @param parent parent config object, if any
128 */
129 KateConfig(const KateConfig *parent = nullptr);
130
131 /**
132 * Virtual Destructor
133 */
134 virtual ~KateConfig();
135
136 /**
137 * One config entry.
138 */
139 class ConfigEntry
140 {
141 public:
142 /**
143 * Construct one config entry.
144 * @param enumId value of the enum for this config entry
145 * @param configId value of the key for the KConfig file for this config entry
146 * @param command command name
147 * @param defaultVal default value
148 * @param valid validator function, default none
149 */
150 ConfigEntry(int enumId, const char *configId, QString command, QVariant defaultVal, std::function<bool(const QVariant &)> valid = nullptr)
151 : enumKey(enumId)
152 , configKey(configId)
153 , commandName(command)
154 , defaultValue(defaultVal)
155 , value(defaultVal)
156 , validator(valid)
157 {
158 }
159
160 /**
161 * Enum key for this config entry, shall be unique
162 */
163 const int enumKey;
164
165 /**
166 * KConfig entry key for this config entry, shall be unique in its group
167 * e.g. "Tab Width"
168 */
169 const char *const configKey;
170
171 /**
172 * Command name as used in e.g. ConfigInterface or modeline/command line
173 * e.g. tab-width
174 */
175 const QString commandName;
176
177 /**
178 * Default value if nothing special was configured
179 */
180 const QVariant defaultValue;
181
182 /**
183 * The concrete value, per default == defaultValue
184 */
185 QVariant value;
186
187 /**
188 * An optional validator function, only when these returns true
189 * we accept a given new value.
190 * Is no validator set, we accept any value.
191 */
192 std::function<bool(const QVariant &)> validator;
193 };
194
195 /**
196 * Read all config entries from given config group.
197 * @param config config group to read from
198 */
199 void readConfigEntries(const KConfigGroup &config);
200
201 /**
202 * Write all config entries to given config group.
203 * @param config config group to write to
204 */
205 void writeConfigEntries(KConfigGroup &config) const;
206
207 /**
208 * Register a new config entry.
209 * Used by the sub classes to register all there known ones.
210 * @param entry new entry to add
211 */
212 void addConfigEntry(ConfigEntry &&entry);
213
214 /**
215 * Finalize the config entries.
216 * Called by the sub classes after all entries are registered
217 */
218 void finalizeConfigEntries();
219
220 /**
221 * do the real update
222 */
223 virtual void updateConfig() = 0;
224
225private:
226 /**
227 * Get full map of config entries, aka the m_configEntries of the top config object
228 * @return full map with all config entries
229 */
230 const std::map<int, ConfigEntry> &fullConfigEntries() const
231 {
232 return m_parent ? m_parent->fullConfigEntries() : m_configEntries;
233 }
234 /**
235 * Get hash of config entries, aka the m_configKeyToEntry of the top config object
236 * @return full hash with all config entries
237 */
238 const QHash<QString, const ConfigEntry *> &fullConfigKeyToEntry() const
239 {
240 return m_parent ? m_parent->fullConfigKeyToEntry() : *m_configKeyToEntry.get();
241 }
242
243private:
244 /**
245 * parent config object, if any
246 */
247 const KateConfig *const m_parent = nullptr;
248
249 /**
250 * two cases:
251 * - we have m_parent == nullptr => this contains all known config entries
252 * - we have m_parent != nullptr => this contains all set config entries for this level of configuration
253 *
254 * uses a map ATM for deterministic iteration e.g. for read/writeConfig
255 */
256 std::map<int, ConfigEntry> m_configEntries;
257
258 /**
259 * All known config keys, filled only for the object with m_parent == nullptr
260 */
261 std::unique_ptr<QStringList> m_configKeys;
262
263 /**
264 * Hash of config keys => config entry, filled only for the object with m_parent == nullptr
265 */
266 std::unique_ptr<QHash<QString, const ConfigEntry *>> m_configKeyToEntry;
267
268protected:
269 /**
270 * recursion depth
271 */
272 int configSessionNumber = 0;
273};
274
275class KTEXTEDITOR_EXPORT KateGlobalConfig : public KateConfig
276{
277private:
278 friend class KTextEditor::EditorPrivate;
279
280 /**
281 * only used in KTextEditor::EditorPrivate for the static global fallback !!!
282 */
283 KateGlobalConfig();
284
285public:
286 static KateGlobalConfig *global()
287 {
288 return s_global;
289 }
290
291 /**
292 * Known config entries
293 */
294 enum ConfigEntryTypes {
295 /**
296 * Encoding prober
297 */
298 EncodingProberType,
299
300 /**
301 * Fallback encoding
302 */
303 FallbackEncoding
304 };
305
306public:
307 /**
308 * Read config from object
309 */
310 void readConfig(const KConfigGroup &config);
311
312 /**
313 * Write config to object
314 */
315 void writeConfig(KConfigGroup &config);
316
317protected:
318 void updateConfig() override;
319
320public:
321 QString fallbackEncoding() const
322 {
323 return value(key: FallbackEncoding).toString();
324 }
325
326 bool setFallbackEncoding(const QString &encoding)
327 {
328 return setValue(key: FallbackEncoding, value: encoding);
329 }
330
331private:
332 static KateGlobalConfig *s_global;
333};
334
335class KTEXTEDITOR_EXPORT KateDocumentConfig : public KateConfig
336{
337private:
338 friend class KTextEditor::EditorPrivate;
339
340 KateDocumentConfig();
341
342public:
343 /**
344 * Construct a DocumentConfig
345 */
346 explicit KateDocumentConfig(KTextEditor::DocumentPrivate *doc);
347
348 inline static KateDocumentConfig *global()
349 {
350 return s_global;
351 }
352
353 /**
354 * Known config entries
355 */
356 enum ConfigEntryTypes {
357 /**
358 * Tabulator width
359 */
360 TabWidth,
361
362 /**
363 * Indentation width
364 */
365 IndentationWidth,
366
367 /**
368 * On-the-fly spellcheck enabled?
369 */
370 OnTheFlySpellCheck,
371
372 /**
373 * Indent pasted text?
374 */
375 IndentOnTextPaste,
376
377 /**
378 * Replace tabs with spaces?
379 */
380 ReplaceTabsWithSpaces,
381
382 /**
383 * Backup files for local files?
384 */
385 BackupOnSaveLocal,
386
387 /**
388 * Backup files for remote files?
389 */
390 BackupOnSaveRemote,
391
392 /**
393 * Prefix for backup files
394 */
395 BackupOnSavePrefix,
396
397 /**
398 * Suffix for backup files
399 */
400 BackupOnSaveSuffix,
401
402 /**
403 * Indentation mode, like "normal"
404 */
405 IndentationMode,
406
407 /**
408 * Tab handling, like indent, insert tab, smart
409 */
410 TabHandlingMode,
411
412 /**
413 * Static word wrap?
414 */
415 StaticWordWrap,
416
417 /**
418 * Static word wrap column
419 */
420 StaticWordWrapColumn,
421
422 /**
423 * PageUp/Down moves cursor?
424 */
425 PageUpDownMovesCursor,
426
427 /**
428 * Smart Home key?
429 */
430 SmartHome,
431
432 /**
433 * Show Tabs?
434 */
435 ShowTabs,
436
437 /**
438 * Indent on tab?
439 */
440 IndentOnTab,
441
442 /**
443 * Keep extra space?
444 */
445 KeepExtraSpaces,
446
447 /**
448 * Backspace key indents?
449 */
450 BackspaceIndents,
451
452 /**
453 * Show spaces mode like none, all, ...
454 */
455 ShowSpacesMode,
456
457 /**
458 * Trailing Marker Size
459 */
460 TrailingMarkerSize,
461
462 /**
463 * Remove spaces mode
464 */
465 RemoveSpacesMode,
466
467 /**
468 * Ensure newline at end of file
469 */
470 NewlineAtEOF,
471
472 /**
473 * Overwrite mode?
474 */
475 OverwriteMode,
476
477 /**
478 * Encoding
479 */
480 Encoding,
481
482 /**
483 * End of line mode: dos, mac, unix
484 */
485 EndOfLine,
486
487 /**
488 * Allow EOL detection
489 */
490 AllowEndOfLineDetection,
491
492 /**
493 * Use Byte Order Mark
494 */
495 ByteOrderMark,
496
497 /**
498 * Swap file mode
499 */
500 SwapFile,
501
502 /**
503 * Swap file directory
504 */
505 SwapFileDirectory,
506
507 /**
508 * Swap file sync interval
509 */
510 SwapFileSyncInterval,
511
512 /**
513 * Line length limit
514 */
515 LineLengthLimit,
516
517 /**
518 * Camel Cursor Movement?
519 */
520 CamelCursor,
521
522 /**
523 * Automatically detect file indentation
524 */
525 AutoDetectIndent,
526
527 /**
528 * Automatically save?
529 */
530 AutoSave,
531 /**
532 * Automatically save on focus lost
533 */
534 AutoSaveOnFocusOut,
535 /**
536 * Auto save interval
537 */
538 AutoSaveInteral,
539
540 /**
541 * Should we auto-reload if the old state is in version control?
542 */
543 AutoReloadIfStateIsInVersionControl,
544
545 /**
546 * Should we auto-reload if any external changes occur?
547 */
548 AutoReloadOnExternalChanges,
549
550 /**
551 * Should we use editorconfig
552 */
553 UseEditorConfig
554 };
555
556public:
557 /**
558 * Read config from object
559 */
560 void readConfig(const KConfigGroup &config);
561
562 /**
563 * Write config to object
564 */
565 void writeConfig(KConfigGroup &config);
566
567protected:
568 void updateConfig() override;
569
570public:
571 int tabWidth() const
572 {
573 return value(key: TabWidth).toInt();
574 }
575
576 void setTabWidth(int tabWidth)
577 {
578 setValue(key: TabWidth, value: QVariant(tabWidth));
579 }
580
581 int indentationWidth() const
582 {
583 return value(key: IndentationWidth).toInt();
584 }
585
586 void setIndentationWidth(int indentationWidth)
587 {
588 setValue(key: IndentationWidth, value: QVariant(indentationWidth));
589 }
590
591 bool onTheFlySpellCheck() const
592 {
593 return value(key: OnTheFlySpellCheck).toBool();
594 }
595
596 void setOnTheFlySpellCheck(bool on)
597 {
598 setValue(key: OnTheFlySpellCheck, value: QVariant(on));
599 }
600
601 bool indentPastedText() const
602 {
603 return value(key: IndentOnTextPaste).toBool();
604 }
605
606 void setIndentPastedText(bool on)
607 {
608 setValue(key: IndentOnTextPaste, value: QVariant(on));
609 }
610
611 bool replaceTabsDyn() const
612 {
613 return value(key: ReplaceTabsWithSpaces).toBool();
614 }
615
616 void setReplaceTabsDyn(bool on)
617 {
618 setValue(key: ReplaceTabsWithSpaces, value: QVariant(on));
619 }
620
621 bool backupOnSaveLocal() const
622 {
623 return value(key: BackupOnSaveLocal).toBool();
624 }
625
626 void setBackupOnSaveLocal(bool on)
627 {
628 setValue(key: BackupOnSaveLocal, value: QVariant(on));
629 }
630
631 bool backupOnSaveRemote() const
632 {
633 return value(key: BackupOnSaveRemote).toBool();
634 }
635
636 void setBackupOnSaveRemote(bool on)
637 {
638 setValue(key: BackupOnSaveRemote, value: QVariant(on));
639 }
640
641 QString backupPrefix() const
642 {
643 return value(key: BackupOnSavePrefix).toString();
644 }
645
646 void setBackupPrefix(const QString &prefix)
647 {
648 setValue(key: BackupOnSavePrefix, value: QVariant(prefix));
649 }
650
651 QString backupSuffix() const
652 {
653 return value(key: BackupOnSaveSuffix).toString();
654 }
655
656 void setBackupSuffix(const QString &suffix)
657 {
658 setValue(key: BackupOnSaveSuffix, value: QVariant(suffix));
659 }
660
661 QString indentationMode() const
662 {
663 return value(key: IndentationMode).toString();
664 }
665
666 void setIndentationMode(const QString &identationMode)
667 {
668 setValue(key: IndentationMode, value: identationMode);
669 }
670
671 enum TabHandling {
672 tabInsertsTab = 0,
673 tabIndents = 1,
674 tabSmart = 2 //!< indents in leading space, otherwise inserts tab
675 };
676
677 enum WhitespaceRendering {
678 None,
679 Trailing,
680 All
681 };
682
683 int tabHandling() const
684 {
685 return value(key: TabHandlingMode).toInt();
686 }
687
688 void setTabHandling(int tabHandling)
689 {
690 setValue(key: TabHandlingMode, value: tabHandling);
691 }
692
693 bool wordWrap() const
694 {
695 return value(key: StaticWordWrap).toBool();
696 }
697
698 void setWordWrap(bool on)
699 {
700 setValue(key: StaticWordWrap, value: on);
701 }
702
703 int wordWrapAt() const
704 {
705 return value(key: StaticWordWrapColumn).toInt();
706 }
707
708 void setWordWrapAt(int col)
709 {
710 setValue(key: StaticWordWrapColumn, value: col);
711 }
712
713 bool pageUpDownMovesCursor() const
714 {
715 return value(key: PageUpDownMovesCursor).toBool();
716 }
717
718 void setPageUpDownMovesCursor(bool on)
719 {
720 setValue(key: PageUpDownMovesCursor, value: on);
721 }
722
723 void setKeepExtraSpaces(bool on)
724 {
725 setValue(key: KeepExtraSpaces, value: on);
726 }
727
728 bool keepExtraSpaces() const
729 {
730 return value(key: KeepExtraSpaces).toBool();
731 }
732
733 void setBackspaceIndents(bool on)
734 {
735 setValue(key: BackspaceIndents, value: on);
736 }
737
738 bool backspaceIndents() const
739 {
740 return value(key: BackspaceIndents).toBool();
741 }
742
743 void setSmartHome(bool on)
744 {
745 setValue(key: SmartHome, value: on);
746 }
747
748 bool smartHome() const
749 {
750 return value(key: SmartHome).toBool();
751 }
752
753 void setShowTabs(bool on)
754 {
755 setValue(key: ShowTabs, value: on);
756 }
757
758 bool showTabs() const
759 {
760 return value(key: ShowTabs).toBool();
761 }
762
763 void setShowSpaces(WhitespaceRendering mode)
764 {
765 setValue(key: ShowSpacesMode, value: mode);
766 }
767
768 WhitespaceRendering showSpaces() const
769 {
770 return WhitespaceRendering(value(key: ShowSpacesMode).toInt());
771 }
772
773 void setMarkerSize(int markerSize)
774 {
775 setValue(key: TrailingMarkerSize, value: markerSize);
776 }
777
778 int markerSize() const
779 {
780 return value(key: TrailingMarkerSize).toInt();
781 }
782
783 /**
784 * Remove trailing spaces on save.
785 * triState = 0: never remove trailing spaces
786 * triState = 1: remove trailing spaces of modified lines (line modification system)
787 * triState = 2: remove trailing spaces in entire document
788 */
789 void setRemoveSpaces(int triState)
790 {
791 setValue(key: RemoveSpacesMode, value: triState);
792 }
793
794 int removeSpaces() const
795 {
796 return value(key: RemoveSpacesMode).toInt();
797 }
798
799 void setNewLineAtEof(bool on)
800 {
801 setValue(key: NewlineAtEOF, value: on);
802 }
803
804 bool newLineAtEof() const
805 {
806 return value(key: NewlineAtEOF).toBool();
807 }
808
809 void setOvr(bool on)
810 {
811 setValue(key: OverwriteMode, value: on);
812 }
813
814 bool ovr() const
815 {
816 return value(key: OverwriteMode).toBool();
817 }
818
819 void setTabIndents(bool on)
820 {
821 setValue(key: IndentOnTab, value: on);
822 }
823
824 bool tabIndentsEnabled() const
825 {
826 return value(key: IndentOnTab).toBool();
827 }
828
829 QString encoding() const
830 {
831 return value(key: Encoding).toString();
832 }
833
834 bool setEncoding(const QString &encoding)
835 {
836 return setValue(key: Encoding, value: encoding);
837 }
838
839 enum Eol {
840 eolUnix = 0,
841 eolDos = 1,
842 eolMac = 2
843 };
844
845 int eol() const
846 {
847 return value(key: EndOfLine).toInt();
848 }
849
850 /**
851 * Get current end of line string.
852 * Based on current set eol mode.
853 * @return current end of line string
854 */
855 QString eolString() const;
856
857 void setEol(int mode)
858 {
859 setValue(key: EndOfLine, value: mode);
860 }
861
862 bool bom() const
863 {
864 return value(key: ByteOrderMark).toBool();
865 }
866
867 void setBom(bool bom)
868 {
869 setValue(key: ByteOrderMark, value: bom);
870 }
871
872 bool allowEolDetection() const
873 {
874 return value(key: AllowEndOfLineDetection).toBool();
875 }
876
877 void setAllowEolDetection(bool on)
878 {
879 setValue(key: AllowEndOfLineDetection, value: on);
880 }
881
882 QString swapDirectory() const
883 {
884 return value(key: SwapFileDirectory).toString();
885 }
886
887 void setSwapDirectory(const QString &directory)
888 {
889 setValue(key: SwapFileDirectory, value: directory);
890 }
891
892 enum SwapFileMode {
893 DisableSwapFile = 0,
894 EnableSwapFile,
895 SwapFilePresetDirectory
896 };
897
898 SwapFileMode swapFileMode() const
899 {
900 return SwapFileMode(value(key: SwapFile).toInt());
901 }
902
903 void setSwapFileMode(int mode)
904 {
905 setValue(key: SwapFile, value: mode);
906 }
907
908 int swapSyncInterval() const
909 {
910 return value(key: SwapFileSyncInterval).toInt();
911 }
912
913 void setSwapSyncInterval(int interval)
914 {
915 setValue(key: SwapFileSyncInterval, value: interval);
916 }
917
918 int lineLengthLimit() const
919 {
920 return value(key: LineLengthLimit).toInt();
921 }
922
923 void setLineLengthLimit(int limit)
924 {
925 setValue(key: LineLengthLimit, value: limit);
926 }
927
928 void setCamelCursor(bool on)
929 {
930 setValue(key: CamelCursor, value: on);
931 }
932
933 bool camelCursor() const
934 {
935 return value(key: CamelCursor).toBool();
936 }
937
938 void setAutoDetectIndent(bool on)
939 {
940 setValue(key: AutoDetectIndent, value: on);
941 }
942
943 bool autoDetectIndent() const
944 {
945 return value(key: AutoDetectIndent).toBool();
946 }
947
948 bool autoSave() const
949 {
950 return value(key: AutoSave).toBool();
951 }
952
953 bool autoSaveOnFocusOut() const
954 {
955 return value(key: AutoSaveOnFocusOut).toBool();
956 }
957
958 int autoSaveInterval() const
959 {
960 return value(key: AutoSaveInteral).toInt();
961 }
962
963private:
964 static KateDocumentConfig *s_global;
965 KTextEditor::DocumentPrivate *m_doc = nullptr;
966};
967
968class KTEXTEDITOR_EXPORT KateViewConfig : public KateConfig
969{
970private:
971 friend class KTextEditor::EditorPrivate;
972
973 /**
974 * only used in KTextEditor::EditorPrivate for the static global fallback !!!
975 */
976 KTEXTEDITOR_NO_EXPORT
977 KateViewConfig();
978
979public:
980 /**
981 * Construct a ViewConfig
982 */
983 explicit KateViewConfig(KTextEditor::ViewPrivate *view);
984
985 /**
986 * Cu ViewConfig
987 */
988 ~KateViewConfig() override;
989
990 inline static KateViewConfig *global()
991 {
992 return s_global;
993 }
994
995 /**
996 * All known config keys
997 * Keep them sorted alphabetically for our convenience.
998 * Keep the same order when adding config entries with addConfigEntry() in
999 * KateViewConfig::KateViewConfig() otherwise the code will assert.
1000 */
1001 enum ConfigEntryTypes {
1002 AllowMarkMenu,
1003 AutoBrackets,
1004 AutoCenterLines,
1005 AutomaticCompletionInvocation,
1006 AutomaticCompletionPreselectFirst,
1007 BackspaceRemoveComposedCharacters,
1008 BookmarkSorting,
1009 CharsToEncloseSelection,
1010 ClipboardHistoryEntries,
1011 DefaultMarkType,
1012 DynWordWrapAlignIndent,
1013 DynWordWrapIndicators,
1014 DynWrapAnywhere,
1015 DynWrapAtStaticMarker,
1016 DynamicWordWrap,
1017 EnterToInsertCompletion,
1018 FoldFirstLine,
1019 InputMode,
1020 KeywordCompletion,
1021 MaxHistorySize,
1022 MousePasteAtCursorPosition,
1023 PersistentSelection,
1024 ScrollBarMiniMapWidth,
1025 ScrollPastEnd,
1026 SearchFlags,
1027 TabCompletion,
1028 ShowBracketMatchPreview,
1029 ShowFoldingBar,
1030 ShowFoldingPreview,
1031 ShowIconBar,
1032 ShowLineCount,
1033 ShowLineModification,
1034 ShowLineNumbers,
1035 ShowScrollBarMarks,
1036 ShowScrollBarMiniMap,
1037 ShowScrollBarMiniMapAll,
1038 ShowScrollBarPreview,
1039 ShowScrollbars,
1040 ShowWordCount,
1041 TextDragAndDrop,
1042 SmartCopyCut,
1043 UserSetsOfCharsToEncloseSelection,
1044 ViInputModeStealKeys,
1045 ViRelativeLineNumbers,
1046 WordCompletion,
1047 WordCompletionMinimalWordLength,
1048 WordCompletionRemoveTail,
1049 ShowDocWithCompletion,
1050 MultiCursorModifier,
1051 ShowFoldingOnHoverOnly,
1052 ShowStatusbarLineColumn,
1053 ShowStatusbarDictionary,
1054 ShowStatusbarInputMode,
1055 ShowStatusbarHighlightingMode,
1056 ShowStatusbarTabSettings,
1057 ShowStatusbarFileEncoding,
1058 StatusbarLineColumnCompact,
1059 ShowStatusbarEOL,
1060 EnableAccessibility,
1061 CycleThroughBookmarks,
1062 };
1063
1064public:
1065 /**
1066 * Read config from object
1067 */
1068 void readConfig(const KConfigGroup &config);
1069
1070 /**
1071 * Write config to object
1072 */
1073 void writeConfig(KConfigGroup &config);
1074
1075protected:
1076 void updateConfig() override;
1077
1078public:
1079 bool dynWordWrap() const
1080 {
1081 return value(key: DynamicWordWrap).toBool();
1082 }
1083 void setDynWordWrap(bool on)
1084 {
1085 setValue(key: DynamicWordWrap, value: on);
1086 }
1087 bool dynWrapAnywhere() const
1088 {
1089 return value(key: DynWrapAnywhere).toBool();
1090 }
1091
1092 bool dynWrapAtStaticMarker() const
1093 {
1094 return value(key: DynWrapAtStaticMarker).toBool();
1095 }
1096
1097 int dynWordWrapIndicators() const
1098 {
1099 return value(key: DynWordWrapIndicators).toInt();
1100 }
1101
1102 int dynWordWrapAlignIndent() const
1103 {
1104 return value(key: DynWordWrapAlignIndent).toInt();
1105 }
1106
1107 bool lineNumbers() const
1108 {
1109 return value(key: ShowLineNumbers).toBool();
1110 }
1111
1112 bool scrollBarMarks() const
1113 {
1114 return value(key: ShowScrollBarMarks).toBool();
1115 }
1116
1117 bool scrollBarPreview() const
1118 {
1119 return value(key: ShowScrollBarPreview).toBool();
1120 }
1121
1122 bool scrollBarMiniMap() const
1123 {
1124 return value(key: ShowScrollBarMiniMap).toBool();
1125 }
1126
1127 bool scrollBarMiniMapAll() const
1128 {
1129 return value(key: ShowScrollBarMiniMapAll).toBool();
1130 }
1131
1132 int scrollBarMiniMapWidth() const
1133 {
1134 return value(key: ScrollBarMiniMapWidth).toInt();
1135 }
1136
1137 /* Whether to show scrollbars */
1138 enum ScrollbarMode {
1139 AlwaysOn = 0,
1140 ShowWhenNeeded,
1141 AlwaysOff
1142 };
1143
1144 int showScrollbars() const
1145 {
1146 return value(key: ShowScrollbars).toInt();
1147 }
1148
1149 bool showDocWithCompletion() const
1150 {
1151 return value(key: ShowDocWithCompletion).toBool();
1152 }
1153
1154 Qt::KeyboardModifiers multiCursorModifiers() const
1155 {
1156 return static_cast<Qt::KeyboardModifiers>(value(key: MultiCursorModifier).toInt());
1157 }
1158
1159 void setMultiCursorModifiers(Qt::KeyboardModifiers m)
1160 {
1161 setValue(key: MultiCursorModifier, value: (int)m);
1162 }
1163
1164 bool iconBar() const
1165 {
1166 return value(key: ShowIconBar).toBool();
1167 }
1168
1169 bool foldingBar() const
1170 {
1171 return value(key: ShowFoldingBar).toBool();
1172 }
1173
1174 bool foldingPreview() const
1175 {
1176 return value(key: ShowFoldingPreview).toBool();
1177 }
1178
1179 bool lineModification() const
1180 {
1181 return value(key: ShowLineModification).toBool();
1182 }
1183
1184 int bookmarkSort() const
1185 {
1186 return value(key: BookmarkSorting).toInt();
1187 }
1188
1189 int autoCenterLines() const
1190 {
1191 return value(key: AutoCenterLines).toInt();
1192 }
1193
1194 enum SearchFlags {
1195 IncMatchCase = 1 << 0,
1196 IncHighlightAll = 1 << 1,
1197 IncFromCursor = 1 << 2,
1198 PowerMatchCase = 1 << 3,
1199 PowerHighlightAll = 1 << 4,
1200 PowerFromCursor = 1 << 5,
1201 // PowerSelectionOnly = 1 << 6, Better not save to file // Sebastian
1202 PowerModePlainText = 1 << 7,
1203 PowerModeWholeWords = 1 << 8,
1204 PowerModeEscapeSequences = 1 << 9,
1205 PowerModeRegularExpression = 1 << 10,
1206 PowerUsePlaceholders = 1 << 11
1207 };
1208
1209 uint searchFlags() const
1210 {
1211 return value(key: SearchFlags).toUInt();
1212 }
1213 void setSearchFlags(uint flags)
1214 {
1215 setValue(key: SearchFlags, value: flags);
1216 }
1217
1218 int maxHistorySize() const
1219 {
1220 return value(key: MaxHistorySize).toInt();
1221 }
1222
1223 uint defaultMarkType() const
1224 {
1225 return value(key: DefaultMarkType).toUInt();
1226 }
1227
1228 bool allowMarkMenu() const
1229 {
1230 return value(key: AllowMarkMenu).toBool();
1231 }
1232
1233 bool persistentSelection() const
1234 {
1235 return value(key: PersistentSelection).toBool();
1236 }
1237
1238 KTextEditor::View::InputMode inputMode() const
1239 {
1240 return static_cast<KTextEditor::View::InputMode>(value(key: InputMode).toUInt());
1241 }
1242
1243 bool viInputModeStealKeys() const
1244 {
1245 return value(key: ViInputModeStealKeys).toBool();
1246 }
1247
1248 bool viRelativeLineNumbers() const
1249 {
1250 return value(key: ViRelativeLineNumbers).toBool();
1251 }
1252
1253 // Do we still need the enum and related functions below?
1254 enum TextToSearch {
1255 Nowhere = 0,
1256 SelectionOnly = 1,
1257 SelectionWord = 2,
1258 WordOnly = 3,
1259 WordSelection = 4
1260 };
1261
1262 bool automaticCompletionInvocation() const
1263 {
1264 return value(key: AutomaticCompletionInvocation).toBool();
1265 }
1266
1267 bool automaticCompletionPreselectFirst() const
1268 {
1269 return value(key: AutomaticCompletionPreselectFirst).toBool();
1270 }
1271
1272 bool tabCompletion() const
1273 {
1274 return value(key: TabCompletion).toBool();
1275 }
1276
1277 bool wordCompletion() const
1278 {
1279 return value(key: WordCompletion).toBool();
1280 }
1281
1282 bool keywordCompletion() const
1283 {
1284 return value(key: KeywordCompletion).toBool();
1285 }
1286
1287 int wordCompletionMinimalWordLength() const
1288 {
1289 return value(key: WordCompletionMinimalWordLength).toInt();
1290 }
1291
1292 bool wordCompletionRemoveTail() const
1293 {
1294 return value(key: WordCompletionRemoveTail).toBool();
1295 }
1296
1297 bool textDragAndDrop() const
1298 {
1299 return value(key: TextDragAndDrop).toBool();
1300 }
1301
1302 bool smartCopyCut() const
1303 {
1304 return value(key: SmartCopyCut).toBool();
1305 }
1306
1307 bool mousePasteAtCursorPosition() const
1308 {
1309 return value(key: MousePasteAtCursorPosition).toBool();
1310 }
1311
1312 int clipboardHistoryEntries() const
1313 {
1314 return value(key: ClipboardHistoryEntries).toInt();
1315 }
1316
1317 bool scrollPastEnd() const
1318 {
1319 return value(key: ScrollPastEnd).toBool();
1320 }
1321
1322 bool foldFirstLine() const
1323 {
1324 return value(key: FoldFirstLine).toBool();
1325 }
1326
1327 bool showWordCount() const
1328 {
1329 return value(key: ShowWordCount).toBool();
1330 }
1331 void setShowWordCount(bool on)
1332 {
1333 setValue(key: ShowWordCount, value: on);
1334 }
1335
1336 bool showLineCount() const
1337 {
1338 return value(key: ShowLineCount).toBool();
1339 }
1340
1341 void setShowLineCount(bool on)
1342 {
1343 setValue(key: ShowLineCount, value: on);
1344 }
1345
1346 bool autoBrackets() const
1347 {
1348 return value(key: AutoBrackets).toBool();
1349 }
1350
1351 bool encloseSelectionInChars() const
1352 {
1353 return !value(key: CharsToEncloseSelection).toString().isEmpty();
1354 }
1355
1356 QString charsToEncloseSelection() const
1357 {
1358 return value(key: CharsToEncloseSelection).toString();
1359 }
1360
1361 bool backspaceRemoveComposed() const
1362 {
1363 return value(key: BackspaceRemoveComposedCharacters).toBool();
1364 }
1365
1366 bool showFoldingOnHoverOnly() const
1367 {
1368 return value(key: ShowFoldingOnHoverOnly).toBool();
1369 }
1370
1371private:
1372 static KateViewConfig *s_global;
1373 KTextEditor::ViewPrivate *m_view = nullptr;
1374};
1375
1376class KTEXTEDITOR_EXPORT KateRendererConfig : public KateConfig
1377{
1378private:
1379 friend class KTextEditor::EditorPrivate;
1380
1381 /**
1382 * only used in KTextEditor::EditorPrivate for the static global fallback !!!
1383 */
1384 KTEXTEDITOR_NO_EXPORT
1385 KateRendererConfig();
1386
1387public:
1388 /**
1389 * Construct a RendererConfig
1390 */
1391 explicit KateRendererConfig(KateRenderer *renderer);
1392
1393 /**
1394 * Cu RendererConfig
1395 */
1396 ~KateRendererConfig() override;
1397
1398 inline static KateRendererConfig *global()
1399 {
1400 return s_global;
1401 }
1402
1403 /**
1404 * All known config keys
1405 * Keep them sorted alphabetic for our convenience
1406 */
1407 enum ConfigEntryTypes {
1408 /**
1409 * auto-select the color theme based on application palette
1410 */
1411 AutoColorThemeSelection
1412 };
1413
1414public:
1415 /**
1416 * Read config from object
1417 */
1418 void readConfig(const KConfigGroup &config);
1419
1420 /**
1421 * Write config to object
1422 */
1423 void writeConfig(KConfigGroup &config);
1424
1425protected:
1426 void updateConfig() override;
1427
1428public:
1429 const QString &schema() const;
1430 void setSchema(QString schema);
1431
1432 /**
1433 * Reload the schema from the schema manager.
1434 * For the global instance, have all other instances reload.
1435 * Used by the schema config page to apply changes.
1436 */
1437 void reloadSchema();
1438
1439 /**
1440 * Base font to use for the views and co.
1441 * Will be adjusted there to avoid rendering artifacts for HiDPI stuff.
1442 * @return base font to use
1443 */
1444 const QFont &baseFont() const;
1445
1446 void setFont(const QFont &font);
1447
1448 bool wordWrapMarker() const;
1449 void setWordWrapMarker(bool on);
1450
1451 const QColor &backgroundColor() const;
1452 void setBackgroundColor(const QColor &col);
1453
1454 const QColor &selectionColor() const;
1455 void setSelectionColor(const QColor &col);
1456
1457 const QColor &highlightedLineColor() const;
1458 void setHighlightedLineColor(const QColor &col);
1459
1460 const QColor &lineMarkerColor(KTextEditor::Document::MarkTypes type = KTextEditor::Document::markType01) const; // markType01 == Bookmark
1461
1462 const QColor &highlightedBracketColor() const;
1463 void setHighlightedBracketColor(const QColor &col);
1464
1465 const QColor &wordWrapMarkerColor() const;
1466 void setWordWrapMarkerColor(const QColor &col);
1467
1468 const QColor &tabMarkerColor() const;
1469 void setTabMarkerColor(const QColor &col);
1470
1471 const QColor &indentationLineColor() const;
1472 void setIndentationLineColor(const QColor &col);
1473
1474 const QColor &iconBarColor() const;
1475 void setIconBarColor(const QColor &col);
1476
1477 const QColor &foldingColor() const;
1478 void setFoldingColor(const QColor &col);
1479
1480 // the line number color is used for the line numbers on the left bar
1481 const QColor &lineNumberColor() const;
1482 void setLineNumberColor(const QColor &col);
1483 const QColor &currentLineNumberColor() const;
1484 void setCurrentLineNumberColor(const QColor &col);
1485
1486 // the color of the separator between line numbers and icon bar
1487 const QColor &separatorColor() const;
1488 void setSeparatorColor(const QColor &col);
1489
1490 const QColor &spellingMistakeLineColor() const;
1491 void setSpellingMistakeLineColor(const QColor &col);
1492
1493 bool showIndentationLines() const;
1494 void setShowIndentationLines(bool on);
1495
1496 bool showWholeBracketExpression() const;
1497 void setShowWholeBracketExpression(bool on);
1498
1499 static bool animateBracketMatching();
1500 void setAnimateBracketMatching(bool on);
1501
1502 const QColor &templateBackgroundColor() const;
1503 const QColor &templateEditablePlaceholderColor() const;
1504 const QColor &templateFocusedEditablePlaceholderColor() const;
1505 const QColor &templateNotEditablePlaceholderColor() const;
1506
1507 const QColor &modifiedLineColor() const;
1508 void setModifiedLineColor(const QColor &col);
1509
1510 const QColor &savedLineColor() const;
1511 void setSavedLineColor(const QColor &col);
1512
1513 const QColor &searchHighlightColor() const;
1514 void setSearchHighlightColor(const QColor &col);
1515
1516 const QColor &replaceHighlightColor() const;
1517 void setReplaceHighlightColor(const QColor &col);
1518
1519 void setLineHeightMultiplier(qreal value);
1520
1521 qreal lineHeightMultiplier() const
1522 {
1523 return s_global->m_lineHeightMultiplier;
1524 }
1525
1526private:
1527 /**
1528 * Read the schema properties from the config file.
1529 */
1530 KTEXTEDITOR_NO_EXPORT
1531 void setSchemaInternal(const QString &schema);
1532
1533private:
1534 QString m_schema;
1535 QFont m_font;
1536 QColor m_backgroundColor;
1537 QColor m_selectionColor;
1538 QColor m_highlightedLineColor;
1539 QColor m_highlightedBracketColor;
1540 QColor m_wordWrapMarkerColor;
1541 QColor m_tabMarkerColor;
1542 QColor m_indentationLineColor;
1543 QColor m_iconBarColor;
1544 QColor m_foldingColor;
1545 QColor m_lineNumberColor;
1546 QColor m_currentLineNumberColor;
1547 QColor m_separatorColor;
1548 QColor m_spellingMistakeLineColor;
1549 std::vector<QColor> m_lineMarkerColor;
1550
1551 QColor m_templateBackgroundColor;
1552 QColor m_templateEditablePlaceholderColor;
1553 QColor m_templateFocusedEditablePlaceholderColor;
1554 QColor m_templateNotEditablePlaceholderColor;
1555
1556 QColor m_modifiedLineColor;
1557 QColor m_savedLineColor;
1558 QColor m_searchHighlightColor;
1559 QColor m_replaceHighlightColor;
1560
1561 qreal m_lineHeightMultiplier = 1.0;
1562
1563 bool m_wordWrapMarker = false;
1564 bool m_showIndentationLines = false;
1565 bool m_showWholeBracketExpression = false;
1566 bool m_animateBracketMatching = false;
1567
1568 bool m_schemaSet : 1;
1569 bool m_fontSet : 1;
1570 bool m_wordWrapMarkerSet : 1;
1571 bool m_showIndentationLinesSet : 1;
1572 bool m_showWholeBracketExpressionSet : 1;
1573 bool m_backgroundColorSet : 1;
1574 bool m_selectionColorSet : 1;
1575 bool m_highlightedLineColorSet : 1;
1576 bool m_highlightedBracketColorSet : 1;
1577 bool m_wordWrapMarkerColorSet : 1;
1578 bool m_tabMarkerColorSet : 1;
1579 bool m_indentationLineColorSet : 1;
1580 bool m_iconBarColorSet : 1;
1581 bool m_foldingColorSet : 1;
1582 bool m_lineNumberColorSet : 1;
1583 bool m_currentLineNumberColorSet : 1;
1584 bool m_separatorColorSet : 1;
1585 bool m_spellingMistakeLineColorSet : 1;
1586 bool m_templateColorsSet : 1;
1587 bool m_modifiedLineColorSet : 1;
1588 bool m_savedLineColorSet : 1;
1589 bool m_searchHighlightColorSet : 1;
1590 bool m_replaceHighlightColorSet : 1;
1591 QBitArray m_lineMarkerColorSet;
1592
1593private:
1594 static KateRendererConfig *s_global;
1595 KateRenderer *m_renderer = nullptr;
1596};
1597
1598#endif
1599

source code of ktexteditor/src/utils/kateconfig.h