KTextEditor

kateconfig.h
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 */
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(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 */
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 */
176
177 /**
178 * Default value if nothing special was configured
179 */
181
182 /**
183 * The concrete value, per default == defaultValue
184 */
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 */
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 */
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(FallbackEncoding).toString();
324 }
325
326 bool setFallbackEncoding(const QString &encoding)
327 {
328 return setValue(FallbackEncoding, 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 use editorconfig
547 */
548 UseEditorConfig
549 };
550
551public:
552 /**
553 * Read config from object
554 */
555 void readConfig(const KConfigGroup &config);
556
557 /**
558 * Write config to object
559 */
560 void writeConfig(KConfigGroup &config);
561
562protected:
563 void updateConfig() override;
564
565public:
566 int tabWidth() const
567 {
568 return value(TabWidth).toInt();
569 }
570
571 void setTabWidth(int tabWidth)
572 {
573 setValue(TabWidth, QVariant(tabWidth));
574 }
575
576 int indentationWidth() const
577 {
578 return value(IndentationWidth).toInt();
579 }
580
581 void setIndentationWidth(int indentationWidth)
582 {
583 setValue(IndentationWidth, QVariant(indentationWidth));
584 }
585
586 bool onTheFlySpellCheck() const
587 {
588 return value(OnTheFlySpellCheck).toBool();
589 }
590
591 void setOnTheFlySpellCheck(bool on)
592 {
593 setValue(OnTheFlySpellCheck, QVariant(on));
594 }
595
596 bool indentPastedText() const
597 {
598 return value(IndentOnTextPaste).toBool();
599 }
600
601 void setIndentPastedText(bool on)
602 {
603 setValue(IndentOnTextPaste, QVariant(on));
604 }
605
606 bool replaceTabsDyn() const
607 {
608 return value(ReplaceTabsWithSpaces).toBool();
609 }
610
611 void setReplaceTabsDyn(bool on)
612 {
613 setValue(ReplaceTabsWithSpaces, QVariant(on));
614 }
615
616 bool backupOnSaveLocal() const
617 {
618 return value(BackupOnSaveLocal).toBool();
619 }
620
621 void setBackupOnSaveLocal(bool on)
622 {
623 setValue(BackupOnSaveLocal, QVariant(on));
624 }
625
626 bool backupOnSaveRemote() const
627 {
628 return value(BackupOnSaveRemote).toBool();
629 }
630
631 void setBackupOnSaveRemote(bool on)
632 {
633 setValue(BackupOnSaveRemote, QVariant(on));
634 }
635
636 QString backupPrefix() const
637 {
638 return value(BackupOnSavePrefix).toString();
639 }
640
641 void setBackupPrefix(const QString &prefix)
642 {
643 setValue(BackupOnSavePrefix, QVariant(prefix));
644 }
645
646 QString backupSuffix() const
647 {
648 return value(BackupOnSaveSuffix).toString();
649 }
650
651 void setBackupSuffix(const QString &suffix)
652 {
653 setValue(BackupOnSaveSuffix, QVariant(suffix));
654 }
655
656 QString indentationMode() const
657 {
658 return value(IndentationMode).toString();
659 }
660
661 void setIndentationMode(const QString &identationMode)
662 {
663 setValue(IndentationMode, identationMode);
664 }
665
666 enum TabHandling {
667 tabInsertsTab = 0,
668 tabIndents = 1,
669 tabSmart = 2 //!< indents in leading space, otherwise inserts tab
670 };
671
672 enum WhitespaceRendering {
673 None,
674 Trailing,
675 All
676 };
677
678 int tabHandling() const
679 {
680 return value(TabHandlingMode).toInt();
681 }
682
683 void setTabHandling(int tabHandling)
684 {
685 setValue(TabHandlingMode, tabHandling);
686 }
687
688 bool wordWrap() const
689 {
690 return value(StaticWordWrap).toBool();
691 }
692
693 void setWordWrap(bool on)
694 {
695 setValue(StaticWordWrap, on);
696 }
697
698 int wordWrapAt() const
699 {
700 return value(StaticWordWrapColumn).toInt();
701 }
702
703 void setWordWrapAt(int col)
704 {
705 setValue(StaticWordWrapColumn, col);
706 }
707
708 bool pageUpDownMovesCursor() const
709 {
710 return value(PageUpDownMovesCursor).toBool();
711 }
712
713 void setPageUpDownMovesCursor(bool on)
714 {
715 setValue(PageUpDownMovesCursor, on);
716 }
717
718 void setKeepExtraSpaces(bool on)
719 {
720 setValue(KeepExtraSpaces, on);
721 }
722
723 bool keepExtraSpaces() const
724 {
725 return value(KeepExtraSpaces).toBool();
726 }
727
728 void setBackspaceIndents(bool on)
729 {
730 setValue(BackspaceIndents, on);
731 }
732
733 bool backspaceIndents() const
734 {
735 return value(BackspaceIndents).toBool();
736 }
737
738 void setSmartHome(bool on)
739 {
740 setValue(SmartHome, on);
741 }
742
743 bool smartHome() const
744 {
745 return value(SmartHome).toBool();
746 }
747
748 void setShowTabs(bool on)
749 {
750 setValue(ShowTabs, on);
751 }
752
753 bool showTabs() const
754 {
755 return value(ShowTabs).toBool();
756 }
757
758 void setShowSpaces(WhitespaceRendering mode)
759 {
760 setValue(ShowSpacesMode, mode);
761 }
762
763 WhitespaceRendering showSpaces() const
764 {
765 return WhitespaceRendering(value(ShowSpacesMode).toInt());
766 }
767
768 void setMarkerSize(int markerSize)
769 {
770 setValue(TrailingMarkerSize, markerSize);
771 }
772
773 int markerSize() const
774 {
775 return value(TrailingMarkerSize).toInt();
776 }
777
778 /**
779 * Remove trailing spaces on save.
780 * triState = 0: never remove trailing spaces
781 * triState = 1: remove trailing spaces of modified lines (line modification system)
782 * triState = 2: remove trailing spaces in entire document
783 */
784 void setRemoveSpaces(int triState)
785 {
786 setValue(RemoveSpacesMode, triState);
787 }
788
789 int removeSpaces() const
790 {
791 return value(RemoveSpacesMode).toInt();
792 }
793
794 void setNewLineAtEof(bool on)
795 {
796 setValue(NewlineAtEOF, on);
797 }
798
799 bool newLineAtEof() const
800 {
801 return value(NewlineAtEOF).toBool();
802 }
803
804 void setOvr(bool on)
805 {
806 setValue(OverwriteMode, on);
807 }
808
809 bool ovr() const
810 {
811 return value(OverwriteMode).toBool();
812 }
813
814 void setTabIndents(bool on)
815 {
816 setValue(IndentOnTab, on);
817 }
818
819 bool tabIndentsEnabled() const
820 {
821 return value(IndentOnTab).toBool();
822 }
823
824 QString encoding() const
825 {
826 return value(Encoding).toString();
827 }
828
829 bool setEncoding(const QString &encoding)
830 {
831 return setValue(Encoding, encoding);
832 }
833
834 enum Eol {
835 eolUnix = 0,
836 eolDos = 1,
837 eolMac = 2
838 };
839
840 int eol() const
841 {
842 return value(EndOfLine).toInt();
843 }
844
845 /**
846 * Get current end of line string.
847 * Based on current set eol mode.
848 * @return current end of line string
849 */
850 QString eolString() const;
851
852 void setEol(int mode)
853 {
854 setValue(EndOfLine, mode);
855 }
856
857 bool bom() const
858 {
859 return value(ByteOrderMark).toBool();
860 }
861
862 void setBom(bool bom)
863 {
864 setValue(ByteOrderMark, bom);
865 }
866
867 bool allowEolDetection() const
868 {
869 return value(AllowEndOfLineDetection).toBool();
870 }
871
872 void setAllowEolDetection(bool on)
873 {
874 setValue(AllowEndOfLineDetection, on);
875 }
876
877 QString swapDirectory() const
878 {
879 return value(SwapFileDirectory).toString();
880 }
881
882 void setSwapDirectory(const QString &directory)
883 {
884 setValue(SwapFileDirectory, directory);
885 }
886
887 enum SwapFileMode {
888 DisableSwapFile = 0,
889 EnableSwapFile,
890 SwapFilePresetDirectory
891 };
892
893 SwapFileMode swapFileMode() const
894 {
895 return SwapFileMode(value(SwapFile).toInt());
896 }
897
898 void setSwapFileMode(int mode)
899 {
900 setValue(SwapFile, mode);
901 }
902
903 int swapSyncInterval() const
904 {
905 return value(SwapFileSyncInterval).toInt();
906 }
907
908 void setSwapSyncInterval(int interval)
909 {
910 setValue(SwapFileSyncInterval, interval);
911 }
912
913 int lineLengthLimit() const
914 {
915 return value(LineLengthLimit).toInt();
916 }
917
918 void setLineLengthLimit(int limit)
919 {
920 setValue(LineLengthLimit, limit);
921 }
922
923 void setCamelCursor(bool on)
924 {
925 setValue(CamelCursor, on);
926 }
927
928 bool camelCursor() const
929 {
930 return value(CamelCursor).toBool();
931 }
932
933 void setAutoDetectIndent(bool on)
934 {
935 setValue(AutoDetectIndent, on);
936 }
937
938 bool autoDetectIndent() const
939 {
940 return value(AutoDetectIndent).toBool();
941 }
942
943 bool autoSave() const
944 {
945 return value(AutoSave).toBool();
946 }
947
948 bool autoSaveOnFocusOut() const
949 {
950 return value(AutoSaveOnFocusOut).toBool();
951 }
952
953 int autoSaveInterval() const
954 {
955 return value(AutoSaveInteral).toInt();
956 }
957
958private:
959 static KateDocumentConfig *s_global;
960 KTextEditor::DocumentPrivate *m_doc = nullptr;
961};
962
963class KTEXTEDITOR_EXPORT KateViewConfig : public KateConfig
964{
965private:
966 friend class KTextEditor::EditorPrivate;
967
968 /**
969 * only used in KTextEditor::EditorPrivate for the static global fallback !!!
970 */
971 KTEXTEDITOR_NO_EXPORT
972 KateViewConfig();
973
974public:
975 /**
976 * Construct a ViewConfig
977 */
978 explicit KateViewConfig(KTextEditor::ViewPrivate *view);
979
980 /**
981 * Cu ViewConfig
982 */
983 ~KateViewConfig() override;
984
985 inline static KateViewConfig *global()
986 {
987 return s_global;
988 }
989
990 /**
991 * All known config keys
992 * Keep them sorted alphabetically for our convenience.
993 * Keep the same order when adding config entries with addConfigEntry() in
994 * KateViewConfig::KateViewConfig() otherwise the code will assert.
995 */
996 enum ConfigEntryTypes {
997 AllowMarkMenu,
998 AutoBrackets,
999 AutoCenterLines,
1000 AutomaticCompletionInvocation,
1001 AutomaticCompletionPreselectFirst,
1002 BackspaceRemoveComposedCharacters,
1003 BookmarkSorting,
1004 CharsToEncloseSelection,
1005 ClipboardHistoryEntries,
1006 DefaultMarkType,
1007 DynWordWrapAlignIndent,
1008 DynWordWrapIndicators,
1009 DynWrapAnywhere,
1010 DynWrapAtStaticMarker,
1011 DynamicWordWrap,
1012 EnterToInsertCompletion,
1013 FoldFirstLine,
1014 InputMode,
1015 KeywordCompletion,
1016 MaxHistorySize,
1017 MousePasteAtCursorPosition,
1018 PersistentSelection,
1019 ScrollBarMiniMapWidth,
1020 ScrollPastEnd,
1021 SearchFlags,
1022 TabCompletion,
1023 ShowBracketMatchPreview,
1024 ShowFoldingBar,
1025 ShowFoldingPreview,
1026 ShowIconBar,
1027 ShowLineCount,
1028 ShowLineModification,
1029 ShowLineNumbers,
1030 ShowScrollBarMarks,
1031 ShowScrollBarMiniMap,
1032 ShowScrollBarMiniMapAll,
1033 ShowScrollBarPreview,
1034 ShowScrollbars,
1035 ShowWordCount,
1036 TextDragAndDrop,
1037 SmartCopyCut,
1038 UserSetsOfCharsToEncloseSelection,
1039 ViInputModeStealKeys,
1040 ViRelativeLineNumbers,
1041 WordCompletion,
1042 WordCompletionMinimalWordLength,
1043 WordCompletionRemoveTail,
1044 ShowDocWithCompletion,
1045 MultiCursorModifier,
1046 ShowFoldingOnHoverOnly,
1047 ShowStatusbarLineColumn,
1048 ShowStatusbarDictionary,
1049 ShowStatusbarInputMode,
1050 ShowStatusbarHighlightingMode,
1051 ShowStatusbarTabSettings,
1052 ShowStatusbarFileEncoding,
1053 StatusbarLineColumnCompact,
1054 ShowStatusbarEOL,
1055 EnableAccessibility,
1056 CycleThroughBookmarks,
1057 };
1058
1059public:
1060 /**
1061 * Read config from object
1062 */
1063 void readConfig(const KConfigGroup &config);
1064
1065 /**
1066 * Write config to object
1067 */
1068 void writeConfig(KConfigGroup &config);
1069
1070protected:
1071 void updateConfig() override;
1072
1073public:
1074 bool dynWordWrap() const
1075 {
1076 return value(DynamicWordWrap).toBool();
1077 }
1078 void setDynWordWrap(bool on)
1079 {
1080 setValue(DynamicWordWrap, on);
1081 }
1082 bool dynWrapAnywhere() const
1083 {
1084 return value(DynWrapAnywhere).toBool();
1085 }
1086
1087 bool dynWrapAtStaticMarker() const
1088 {
1089 return value(DynWrapAtStaticMarker).toBool();
1090 }
1091
1092 int dynWordWrapIndicators() const
1093 {
1094 return value(DynWordWrapIndicators).toInt();
1095 }
1096
1097 int dynWordWrapAlignIndent() const
1098 {
1099 return value(DynWordWrapAlignIndent).toInt();
1100 }
1101
1102 bool lineNumbers() const
1103 {
1104 return value(ShowLineNumbers).toBool();
1105 }
1106
1107 bool scrollBarMarks() const
1108 {
1109 return value(ShowScrollBarMarks).toBool();
1110 }
1111
1112 bool scrollBarPreview() const
1113 {
1114 return value(ShowScrollBarPreview).toBool();
1115 }
1116
1117 bool scrollBarMiniMap() const
1118 {
1119 return value(ShowScrollBarMiniMap).toBool();
1120 }
1121
1122 bool scrollBarMiniMapAll() const
1123 {
1124 return value(ShowScrollBarMiniMapAll).toBool();
1125 }
1126
1127 int scrollBarMiniMapWidth() const
1128 {
1129 return value(ScrollBarMiniMapWidth).toInt();
1130 }
1131
1132 /* Whether to show scrollbars */
1133 enum ScrollbarMode {
1134 AlwaysOn = 0,
1135 ShowWhenNeeded,
1136 AlwaysOff
1137 };
1138
1139 int showScrollbars() const
1140 {
1141 return value(ShowScrollbars).toInt();
1142 }
1143
1144 bool showDocWithCompletion() const
1145 {
1146 return value(ShowDocWithCompletion).toBool();
1147 }
1148
1149 Qt::KeyboardModifiers multiCursorModifiers() const
1150 {
1151 return static_cast<Qt::KeyboardModifiers>(value(MultiCursorModifier).toInt());
1152 }
1153
1154 void setMultiCursorModifiers(Qt::KeyboardModifiers m)
1155 {
1156 setValue(MultiCursorModifier, (int)m);
1157 }
1158
1159 bool iconBar() const
1160 {
1161 return value(ShowIconBar).toBool();
1162 }
1163
1164 bool foldingBar() const
1165 {
1166 return value(ShowFoldingBar).toBool();
1167 }
1168
1169 bool foldingPreview() const
1170 {
1171 return value(ShowFoldingPreview).toBool();
1172 }
1173
1174 bool lineModification() const
1175 {
1176 return value(ShowLineModification).toBool();
1177 }
1178
1179 int bookmarkSort() const
1180 {
1181 return value(BookmarkSorting).toInt();
1182 }
1183
1184 int autoCenterLines() const
1185 {
1186 return value(AutoCenterLines).toInt();
1187 }
1188
1189 enum SearchFlags {
1190 IncMatchCase = 1 << 0,
1191 IncHighlightAll = 1 << 1,
1192 IncFromCursor = 1 << 2,
1193 PowerMatchCase = 1 << 3,
1194 PowerHighlightAll = 1 << 4,
1195 PowerFromCursor = 1 << 5,
1196 // PowerSelectionOnly = 1 << 6, Better not save to file // Sebastian
1197 PowerModePlainText = 1 << 7,
1198 PowerModeWholeWords = 1 << 8,
1199 PowerModeEscapeSequences = 1 << 9,
1200 PowerModeRegularExpression = 1 << 10,
1201 PowerUsePlaceholders = 1 << 11
1202 };
1203
1204 uint searchFlags() const
1205 {
1206 return value(SearchFlags).toUInt();
1207 }
1208 void setSearchFlags(uint flags)
1209 {
1210 setValue(SearchFlags, flags);
1211 }
1212
1213 int maxHistorySize() const
1214 {
1215 return value(MaxHistorySize).toInt();
1216 }
1217
1218 uint defaultMarkType() const
1219 {
1220 return value(DefaultMarkType).toUInt();
1221 }
1222
1223 bool allowMarkMenu() const
1224 {
1225 return value(AllowMarkMenu).toBool();
1226 }
1227
1228 bool persistentSelection() const
1229 {
1230 return value(PersistentSelection).toBool();
1231 }
1232
1233 KTextEditor::View::InputMode inputMode() const
1234 {
1235 return static_cast<KTextEditor::View::InputMode>(value(InputMode).toUInt());
1236 }
1237
1238 bool viInputModeStealKeys() const
1239 {
1240 return value(ViInputModeStealKeys).toBool();
1241 }
1242
1243 bool viRelativeLineNumbers() const
1244 {
1245 return value(ViRelativeLineNumbers).toBool();
1246 }
1247
1248 // Do we still need the enum and related functions below?
1249 enum TextToSearch {
1250 Nowhere = 0,
1251 SelectionOnly = 1,
1252 SelectionWord = 2,
1253 WordOnly = 3,
1254 WordSelection = 4
1255 };
1256
1257 bool automaticCompletionInvocation() const
1258 {
1259 return value(AutomaticCompletionInvocation).toBool();
1260 }
1261
1262 bool automaticCompletionPreselectFirst() const
1263 {
1264 return value(AutomaticCompletionPreselectFirst).toBool();
1265 }
1266
1267 bool tabCompletion() const
1268 {
1269 return value(TabCompletion).toBool();
1270 }
1271
1272 bool wordCompletion() const
1273 {
1274 return value(WordCompletion).toBool();
1275 }
1276
1277 bool keywordCompletion() const
1278 {
1279 return value(KeywordCompletion).toBool();
1280 }
1281
1282 int wordCompletionMinimalWordLength() const
1283 {
1284 return value(WordCompletionMinimalWordLength).toInt();
1285 }
1286
1287 bool wordCompletionRemoveTail() const
1288 {
1289 return value(WordCompletionRemoveTail).toBool();
1290 }
1291
1292 bool textDragAndDrop() const
1293 {
1294 return value(TextDragAndDrop).toBool();
1295 }
1296
1297 bool smartCopyCut() const
1298 {
1299 return value(SmartCopyCut).toBool();
1300 }
1301
1302 bool mousePasteAtCursorPosition() const
1303 {
1304 return value(MousePasteAtCursorPosition).toBool();
1305 }
1306
1307 int clipboardHistoryEntries() const
1308 {
1309 return value(ClipboardHistoryEntries).toInt();
1310 }
1311
1312 bool scrollPastEnd() const
1313 {
1314 return value(ScrollPastEnd).toBool();
1315 }
1316
1317 bool foldFirstLine() const
1318 {
1319 return value(FoldFirstLine).toBool();
1320 }
1321
1322 bool showWordCount() const
1323 {
1324 return value(ShowWordCount).toBool();
1325 }
1326 void setShowWordCount(bool on)
1327 {
1328 setValue(ShowWordCount, on);
1329 }
1330
1331 bool showLineCount() const
1332 {
1333 return value(ShowLineCount).toBool();
1334 }
1335
1336 void setShowLineCount(bool on)
1337 {
1338 setValue(ShowLineCount, on);
1339 }
1340
1341 bool autoBrackets() const
1342 {
1343 return value(AutoBrackets).toBool();
1344 }
1345
1346 bool encloseSelectionInChars() const
1347 {
1348 return !value(CharsToEncloseSelection).toString().isEmpty();
1349 }
1350
1351 QString charsToEncloseSelection() const
1352 {
1353 return value(CharsToEncloseSelection).toString();
1354 }
1355
1356 bool backspaceRemoveComposed() const
1357 {
1358 return value(BackspaceRemoveComposedCharacters).toBool();
1359 }
1360
1361 bool showFoldingOnHoverOnly() const
1362 {
1363 return value(ShowFoldingOnHoverOnly).toBool();
1364 }
1365
1366private:
1367 static KateViewConfig *s_global;
1368 KTextEditor::ViewPrivate *m_view = nullptr;
1369};
1370
1371class KTEXTEDITOR_EXPORT KateRendererConfig : public KateConfig
1372{
1373private:
1374 friend class KTextEditor::EditorPrivate;
1375
1376 /**
1377 * only used in KTextEditor::EditorPrivate for the static global fallback !!!
1378 */
1379 KTEXTEDITOR_NO_EXPORT
1380 KateRendererConfig();
1381
1382public:
1383 /**
1384 * Construct a RendererConfig
1385 */
1386 explicit KateRendererConfig(KateRenderer *renderer);
1387
1388 /**
1389 * Cu RendererConfig
1390 */
1391 ~KateRendererConfig() override;
1392
1393 inline static KateRendererConfig *global()
1394 {
1395 return s_global;
1396 }
1397
1398 /**
1399 * All known config keys
1400 * Keep them sorted alphabetic for our convenience
1401 */
1402 enum ConfigEntryTypes {
1403 /**
1404 * auto-select the color theme based on application palette
1405 */
1406 AutoColorThemeSelection
1407 };
1408
1409public:
1410 /**
1411 * Read config from object
1412 */
1413 void readConfig(const KConfigGroup &config);
1414
1415 /**
1416 * Write config to object
1417 */
1418 void writeConfig(KConfigGroup &config);
1419
1420protected:
1421 void updateConfig() override;
1422
1423public:
1424 const QString &schema() const;
1425 void setSchema(QString schema);
1426
1427 /**
1428 * Reload the schema from the schema manager.
1429 * For the global instance, have all other instances reload.
1430 * Used by the schema config page to apply changes.
1431 */
1432 void reloadSchema();
1433
1434 /**
1435 * Base font to use for the views and co.
1436 * Will be adjusted there to avoid rendering artifacts for HiDPI stuff.
1437 * @return base font to use
1438 */
1439 const QFont &baseFont() const;
1440
1441 void setFont(const QFont &font);
1442
1443 bool wordWrapMarker() const;
1444 void setWordWrapMarker(bool on);
1445
1446 const QColor &backgroundColor() const;
1447 void setBackgroundColor(const QColor &col);
1448
1449 const QColor &selectionColor() const;
1450 void setSelectionColor(const QColor &col);
1451
1452 const QColor &highlightedLineColor() const;
1453 void setHighlightedLineColor(const QColor &col);
1454
1455 const QColor &lineMarkerColor(KTextEditor::Document::MarkTypes type = KTextEditor::Document::markType01) const; // markType01 == Bookmark
1456
1457 const QColor &highlightedBracketColor() const;
1458 void setHighlightedBracketColor(const QColor &col);
1459
1460 const QColor &wordWrapMarkerColor() const;
1461 void setWordWrapMarkerColor(const QColor &col);
1462
1463 const QColor &tabMarkerColor() const;
1464 void setTabMarkerColor(const QColor &col);
1465
1466 const QColor &indentationLineColor() const;
1467 void setIndentationLineColor(const QColor &col);
1468
1469 const QColor &iconBarColor() const;
1470 void setIconBarColor(const QColor &col);
1471
1472 const QColor &foldingColor() const;
1473 void setFoldingColor(const QColor &col);
1474
1475 // the line number color is used for the line numbers on the left bar
1476 const QColor &lineNumberColor() const;
1477 void setLineNumberColor(const QColor &col);
1478 const QColor &currentLineNumberColor() const;
1479 void setCurrentLineNumberColor(const QColor &col);
1480
1481 // the color of the separator between line numbers and icon bar
1482 const QColor &separatorColor() const;
1483 void setSeparatorColor(const QColor &col);
1484
1485 const QColor &spellingMistakeLineColor() const;
1486 void setSpellingMistakeLineColor(const QColor &col);
1487
1488 bool showIndentationLines() const;
1489 void setShowIndentationLines(bool on);
1490
1491 bool showWholeBracketExpression() const;
1492 void setShowWholeBracketExpression(bool on);
1493
1494 static bool animateBracketMatching();
1495 void setAnimateBracketMatching(bool on);
1496
1497 const QColor &templateBackgroundColor() const;
1498 const QColor &templateEditablePlaceholderColor() const;
1499 const QColor &templateFocusedEditablePlaceholderColor() const;
1500 const QColor &templateNotEditablePlaceholderColor() const;
1501
1502 const QColor &modifiedLineColor() const;
1503 void setModifiedLineColor(const QColor &col);
1504
1505 const QColor &savedLineColor() const;
1506 void setSavedLineColor(const QColor &col);
1507
1508 const QColor &searchHighlightColor() const;
1509 void setSearchHighlightColor(const QColor &col);
1510
1511 const QColor &replaceHighlightColor() const;
1512 void setReplaceHighlightColor(const QColor &col);
1513
1514 void setLineHeightMultiplier(qreal value);
1515
1516 qreal lineHeightMultiplier() const
1517 {
1518 return s_global->m_lineHeightMultiplier;
1519 }
1520
1521private:
1522 /**
1523 * Read the schema properties from the config file.
1524 */
1525 KTEXTEDITOR_NO_EXPORT
1526 void setSchemaInternal(const QString &schema);
1527
1528private:
1529 QString m_schema;
1530 QFont m_font;
1531 QColor m_backgroundColor;
1532 QColor m_selectionColor;
1533 QColor m_highlightedLineColor;
1534 QColor m_highlightedBracketColor;
1535 QColor m_wordWrapMarkerColor;
1536 QColor m_tabMarkerColor;
1537 QColor m_indentationLineColor;
1538 QColor m_iconBarColor;
1539 QColor m_foldingColor;
1540 QColor m_lineNumberColor;
1541 QColor m_currentLineNumberColor;
1542 QColor m_separatorColor;
1543 QColor m_spellingMistakeLineColor;
1544 std::vector<QColor> m_lineMarkerColor;
1545
1546 QColor m_templateBackgroundColor;
1547 QColor m_templateEditablePlaceholderColor;
1548 QColor m_templateFocusedEditablePlaceholderColor;
1549 QColor m_templateNotEditablePlaceholderColor;
1550
1551 QColor m_modifiedLineColor;
1552 QColor m_savedLineColor;
1553 QColor m_searchHighlightColor;
1554 QColor m_replaceHighlightColor;
1555
1556 qreal m_lineHeightMultiplier = 1.0;
1557
1558 bool m_wordWrapMarker = false;
1559 bool m_showIndentationLines = false;
1560 bool m_showWholeBracketExpression = false;
1561 bool m_animateBracketMatching = false;
1562
1563 bool m_schemaSet : 1;
1564 bool m_fontSet : 1;
1565 bool m_wordWrapMarkerSet : 1;
1566 bool m_showIndentationLinesSet : 1;
1567 bool m_showWholeBracketExpressionSet : 1;
1568 bool m_backgroundColorSet : 1;
1569 bool m_selectionColorSet : 1;
1570 bool m_highlightedLineColorSet : 1;
1571 bool m_highlightedBracketColorSet : 1;
1572 bool m_wordWrapMarkerColorSet : 1;
1573 bool m_tabMarkerColorSet : 1;
1574 bool m_indentationLineColorSet : 1;
1575 bool m_iconBarColorSet : 1;
1576 bool m_foldingColorSet : 1;
1577 bool m_lineNumberColorSet : 1;
1578 bool m_currentLineNumberColorSet : 1;
1579 bool m_separatorColorSet : 1;
1580 bool m_spellingMistakeLineColorSet : 1;
1581 bool m_templateColorsSet : 1;
1582 bool m_modifiedLineColorSet : 1;
1583 bool m_savedLineColorSet : 1;
1584 bool m_searchHighlightColorSet : 1;
1585 bool m_replaceHighlightColorSet : 1;
1586 QBitArray m_lineMarkerColorSet;
1587
1588private:
1589 static KateRendererConfig *s_global;
1590 KateRenderer *m_renderer = nullptr;
1591};
1592
1593#endif
Backend of KTextEditor::Document related public KTextEditor interfaces.
MarkTypes
Predefined mark types.
Definition document.h:1557
@ markType01
Bookmark.
Definition document.h:1559
KTextEditor::EditorPrivate One instance of this class is hold alive during a kate part session,...
Definition kateglobal.h:65
InputMode
Possible input modes.
Definition view.h:286
One config entry.
Definition kateconfig.h:140
const QString commandName
Command name as used in e.g.
Definition kateconfig.h:175
const char *const configKey
KConfig entry key for this config entry, shall be unique in its group e.g.
Definition kateconfig.h:169
const int enumKey
Enum key for this config entry, shall be unique.
Definition kateconfig.h:163
std::function< bool(const QVariant &)> validator
An optional validator function, only when these returns true we accept a given new value.
Definition kateconfig.h:192
QVariant value
The concrete value, per default == defaultValue.
Definition kateconfig.h:185
const QVariant defaultValue
Default value if nothing special was configured.
Definition kateconfig.h:180
ConfigEntry(int enumId, const char *configId, QString command, QVariant defaultVal, std::function< bool(const QVariant &)> valid=nullptr)
Construct one config entry.
Definition kateconfig.h:150
Base Class for the Kate Config Classes Current childs are KateDocumentConfig/KateDocumentConfig/KateD...
Definition kateconfig.h:47
bool isGlobal() const
Is this a global config object?
Definition kateconfig.h:66
bool isSet(const int key) const
Is given key set in this config object?
Definition kateconfig.h:86
KateConfig(const KateConfig *parent=nullptr)
Construct a KateConfig.
virtual ~KateConfig()
Virtual Destructor.
int configSessionNumber
recursion depth
Definition kateconfig.h:272
QStringList configKeys() const
All known config keys.
Definition kateconfig.h:76
void writeConfigEntries(KConfigGroup &config) const
Write all config entries to given config group.
void configEnd()
End a config change transaction, update the concerned KateDocumentConfig/KateDocumentConfig/KateDocum...
void readConfigEntries(const KConfigGroup &config)
Read all config entries from given config group.
void finalizeConfigEntries()
Finalize the config entries.
void configStart()
Start some config changes.
virtual void updateConfig()=0
do the real update
void addConfigEntry(ConfigEntry &&entry)
Register a new config entry.
Handles all of the work of rendering the text (used for the views and printing)
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
typedef KeyboardModifiers
QTextStream & bom(QTextStream &stream)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 21 2025 11:52:52 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.