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 */
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(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 };
1057
1058public:
1059 /**
1060 * Read config from object
1061 */
1062 void readConfig(const KConfigGroup &config);
1063
1064 /**
1065 * Write config to object
1066 */
1067 void writeConfig(KConfigGroup &config);
1068
1069protected:
1070 void updateConfig() override;
1071
1072public:
1073 bool dynWordWrap() const
1074 {
1075 return value(DynamicWordWrap).toBool();
1076 }
1077 void setDynWordWrap(bool on)
1078 {
1079 setValue(DynamicWordWrap, on);
1080 }
1081 bool dynWrapAnywhere() const
1082 {
1083 return value(DynWrapAnywhere).toBool();
1084 }
1085
1086 bool dynWrapAtStaticMarker() const
1087 {
1088 return value(DynWrapAtStaticMarker).toBool();
1089 }
1090
1091 int dynWordWrapIndicators() const
1092 {
1093 return value(DynWordWrapIndicators).toInt();
1094 }
1095
1096 int dynWordWrapAlignIndent() const
1097 {
1098 return value(DynWordWrapAlignIndent).toInt();
1099 }
1100
1101 bool lineNumbers() const
1102 {
1103 return value(ShowLineNumbers).toBool();
1104 }
1105
1106 bool scrollBarMarks() const
1107 {
1108 return value(ShowScrollBarMarks).toBool();
1109 }
1110
1111 bool scrollBarPreview() const
1112 {
1113 return value(ShowScrollBarPreview).toBool();
1114 }
1115
1116 bool scrollBarMiniMap() const
1117 {
1118 return value(ShowScrollBarMiniMap).toBool();
1119 }
1120
1121 bool scrollBarMiniMapAll() const
1122 {
1123 return value(ShowScrollBarMiniMapAll).toBool();
1124 }
1125
1126 int scrollBarMiniMapWidth() const
1127 {
1128 return value(ScrollBarMiniMapWidth).toInt();
1129 }
1130
1131 /* Whether to show scrollbars */
1132 enum ScrollbarMode {
1133 AlwaysOn = 0,
1134 ShowWhenNeeded,
1135 AlwaysOff
1136 };
1137
1138 int showScrollbars() const
1139 {
1140 return value(ShowScrollbars).toInt();
1141 }
1142
1143 bool showDocWithCompletion() const
1144 {
1145 return value(ShowDocWithCompletion).toBool();
1146 }
1147
1148 Qt::KeyboardModifiers multiCursorModifiers() const
1149 {
1150 return static_cast<Qt::KeyboardModifiers>(value(MultiCursorModifier).toInt());
1151 }
1152
1153 void setMultiCursorModifiers(Qt::KeyboardModifiers m)
1154 {
1155 setValue(MultiCursorModifier, (int)m);
1156 }
1157
1158 bool iconBar() const
1159 {
1160 return value(ShowIconBar).toBool();
1161 }
1162
1163 bool foldingBar() const
1164 {
1165 return value(ShowFoldingBar).toBool();
1166 }
1167
1168 bool foldingPreview() const
1169 {
1170 return value(ShowFoldingPreview).toBool();
1171 }
1172
1173 bool lineModification() const
1174 {
1175 return value(ShowLineModification).toBool();
1176 }
1177
1178 int bookmarkSort() const
1179 {
1180 return value(BookmarkSorting).toInt();
1181 }
1182
1183 int autoCenterLines() const
1184 {
1185 return value(AutoCenterLines).toInt();
1186 }
1187
1188 enum SearchFlags {
1189 IncMatchCase = 1 << 0,
1190 IncHighlightAll = 1 << 1,
1191 IncFromCursor = 1 << 2,
1192 PowerMatchCase = 1 << 3,
1193 PowerHighlightAll = 1 << 4,
1194 PowerFromCursor = 1 << 5,
1195 // PowerSelectionOnly = 1 << 6, Better not save to file // Sebastian
1196 PowerModePlainText = 1 << 7,
1197 PowerModeWholeWords = 1 << 8,
1198 PowerModeEscapeSequences = 1 << 9,
1199 PowerModeRegularExpression = 1 << 10,
1200 PowerUsePlaceholders = 1 << 11
1201 };
1202
1203 uint searchFlags() const
1204 {
1205 return value(SearchFlags).toUInt();
1206 }
1207 void setSearchFlags(uint flags)
1208 {
1209 setValue(SearchFlags, flags);
1210 }
1211
1212 int maxHistorySize() const
1213 {
1214 return value(MaxHistorySize).toInt();
1215 }
1216
1217 uint defaultMarkType() const
1218 {
1219 return value(DefaultMarkType).toUInt();
1220 }
1221
1222 bool allowMarkMenu() const
1223 {
1224 return value(AllowMarkMenu).toBool();
1225 }
1226
1227 bool persistentSelection() const
1228 {
1229 return value(PersistentSelection).toBool();
1230 }
1231
1232 KTextEditor::View::InputMode inputMode() const
1233 {
1234 return static_cast<KTextEditor::View::InputMode>(value(InputMode).toUInt());
1235 }
1236
1237 bool viInputModeStealKeys() const
1238 {
1239 return value(ViInputModeStealKeys).toBool();
1240 }
1241
1242 bool viRelativeLineNumbers() const
1243 {
1244 return value(ViRelativeLineNumbers).toBool();
1245 }
1246
1247 // Do we still need the enum and related functions below?
1248 enum TextToSearch {
1249 Nowhere = 0,
1250 SelectionOnly = 1,
1251 SelectionWord = 2,
1252 WordOnly = 3,
1253 WordSelection = 4
1254 };
1255
1256 bool automaticCompletionInvocation() const
1257 {
1258 return value(AutomaticCompletionInvocation).toBool();
1259 }
1260
1261 bool automaticCompletionPreselectFirst() const
1262 {
1263 return value(AutomaticCompletionPreselectFirst).toBool();
1264 }
1265
1266 bool tabCompletion() const
1267 {
1268 return value(TabCompletion).toBool();
1269 }
1270
1271 bool wordCompletion() const
1272 {
1273 return value(WordCompletion).toBool();
1274 }
1275
1276 bool keywordCompletion() const
1277 {
1278 return value(KeywordCompletion).toBool();
1279 }
1280
1281 int wordCompletionMinimalWordLength() const
1282 {
1283 return value(WordCompletionMinimalWordLength).toInt();
1284 }
1285
1286 bool wordCompletionRemoveTail() const
1287 {
1288 return value(WordCompletionRemoveTail).toBool();
1289 }
1290
1291 bool textDragAndDrop() const
1292 {
1293 return value(TextDragAndDrop).toBool();
1294 }
1295
1296 bool smartCopyCut() const
1297 {
1298 return value(SmartCopyCut).toBool();
1299 }
1300
1301 bool mousePasteAtCursorPosition() const
1302 {
1303 return value(MousePasteAtCursorPosition).toBool();
1304 }
1305
1306 int clipboardHistoryEntries() const
1307 {
1308 return value(ClipboardHistoryEntries).toInt();
1309 }
1310
1311 bool scrollPastEnd() const
1312 {
1313 return value(ScrollPastEnd).toBool();
1314 }
1315
1316 bool foldFirstLine() const
1317 {
1318 return value(FoldFirstLine).toBool();
1319 }
1320
1321 bool showWordCount() const
1322 {
1323 return value(ShowWordCount).toBool();
1324 }
1325 void setShowWordCount(bool on)
1326 {
1327 setValue(ShowWordCount, on);
1328 }
1329
1330 bool showLineCount() const
1331 {
1332 return value(ShowLineCount).toBool();
1333 }
1334
1335 void setShowLineCount(bool on)
1336 {
1337 setValue(ShowLineCount, on);
1338 }
1339
1340 bool autoBrackets() const
1341 {
1342 return value(AutoBrackets).toBool();
1343 }
1344
1345 bool encloseSelectionInChars() const
1346 {
1347 return !value(CharsToEncloseSelection).toString().isEmpty();
1348 }
1349
1350 QString charsToEncloseSelection() const
1351 {
1352 return value(CharsToEncloseSelection).toString();
1353 }
1354
1355 bool backspaceRemoveComposed() const
1356 {
1357 return value(BackspaceRemoveComposedCharacters).toBool();
1358 }
1359
1360 bool showFoldingOnHoverOnly() const
1361 {
1362 return value(ShowFoldingOnHoverOnly).toBool();
1363 }
1364
1365private:
1366 static KateViewConfig *s_global;
1367 KTextEditor::ViewPrivate *m_view = nullptr;
1368};
1369
1370class KTEXTEDITOR_EXPORT KateRendererConfig : public KateConfig
1371{
1372private:
1373 friend class KTextEditor::EditorPrivate;
1374
1375 /**
1376 * only used in KTextEditor::EditorPrivate for the static global fallback !!!
1377 */
1378 KTEXTEDITOR_NO_EXPORT
1379 KateRendererConfig();
1380
1381public:
1382 /**
1383 * Construct a RendererConfig
1384 */
1385 explicit KateRendererConfig(KateRenderer *renderer);
1386
1387 /**
1388 * Cu RendererConfig
1389 */
1390 ~KateRendererConfig() override;
1391
1392 inline static KateRendererConfig *global()
1393 {
1394 return s_global;
1395 }
1396
1397 /**
1398 * All known config keys
1399 * Keep them sorted alphabetic for our convenience
1400 */
1401 enum ConfigEntryTypes {
1402 /**
1403 * auto-select the color theme based on application palette
1404 */
1405 AutoColorThemeSelection
1406 };
1407
1408public:
1409 /**
1410 * Read config from object
1411 */
1412 void readConfig(const KConfigGroup &config);
1413
1414 /**
1415 * Write config to object
1416 */
1417 void writeConfig(KConfigGroup &config);
1418
1419protected:
1420 void updateConfig() override;
1421
1422public:
1423 const QString &schema() const;
1424 void setSchema(QString schema);
1425
1426 /**
1427 * Reload the schema from the schema manager.
1428 * For the global instance, have all other instances reload.
1429 * Used by the schema config page to apply changes.
1430 */
1431 void reloadSchema();
1432
1433 /**
1434 * Base font to use for the views and co.
1435 * Will be adjusted there to avoid rendering artifacts for HiDPI stuff.
1436 * @return base font to use
1437 */
1438 const QFont &baseFont() const;
1439
1440 void setFont(const QFont &font);
1441
1442 bool wordWrapMarker() const;
1443 void setWordWrapMarker(bool on);
1444
1445 const QColor &backgroundColor() const;
1446 void setBackgroundColor(const QColor &col);
1447
1448 const QColor &selectionColor() const;
1449 void setSelectionColor(const QColor &col);
1450
1451 const QColor &highlightedLineColor() const;
1452 void setHighlightedLineColor(const QColor &col);
1453
1454 const QColor &lineMarkerColor(KTextEditor::Document::MarkTypes type = KTextEditor::Document::markType01) const; // markType01 == Bookmark
1455
1456 const QColor &highlightedBracketColor() const;
1457 void setHighlightedBracketColor(const QColor &col);
1458
1459 const QColor &wordWrapMarkerColor() const;
1460 void setWordWrapMarkerColor(const QColor &col);
1461
1462 const QColor &tabMarkerColor() const;
1463 void setTabMarkerColor(const QColor &col);
1464
1465 const QColor &indentationLineColor() const;
1466 void setIndentationLineColor(const QColor &col);
1467
1468 const QColor &iconBarColor() const;
1469 void setIconBarColor(const QColor &col);
1470
1471 const QColor &foldingColor() const;
1472 void setFoldingColor(const QColor &col);
1473
1474 // the line number color is used for the line numbers on the left bar
1475 const QColor &lineNumberColor() const;
1476 void setLineNumberColor(const QColor &col);
1477 const QColor &currentLineNumberColor() const;
1478 void setCurrentLineNumberColor(const QColor &col);
1479
1480 // the color of the separator between line numbers and icon bar
1481 const QColor &separatorColor() const;
1482 void setSeparatorColor(const QColor &col);
1483
1484 const QColor &spellingMistakeLineColor() const;
1485 void setSpellingMistakeLineColor(const QColor &col);
1486
1487 bool showIndentationLines() const;
1488 void setShowIndentationLines(bool on);
1489
1490 bool showWholeBracketExpression() const;
1491 void setShowWholeBracketExpression(bool on);
1492
1493 static bool animateBracketMatching();
1494 void setAnimateBracketMatching(bool on);
1495
1496 const QColor &templateBackgroundColor() const;
1497 const QColor &templateEditablePlaceholderColor() const;
1498 const QColor &templateFocusedEditablePlaceholderColor() const;
1499 const QColor &templateNotEditablePlaceholderColor() const;
1500
1501 const QColor &modifiedLineColor() const;
1502 void setModifiedLineColor(const QColor &col);
1503
1504 const QColor &savedLineColor() const;
1505 void setSavedLineColor(const QColor &col);
1506
1507 const QColor &searchHighlightColor() const;
1508 void setSearchHighlightColor(const QColor &col);
1509
1510 const QColor &replaceHighlightColor() const;
1511 void setReplaceHighlightColor(const QColor &col);
1512
1513 void setLineHeightMultiplier(qreal value);
1514
1515 qreal lineHeightMultiplier() const
1516 {
1517 return s_global->m_lineHeightMultiplier;
1518 }
1519
1520private:
1521 /**
1522 * Read the schema properties from the config file.
1523 */
1524 KTEXTEDITOR_NO_EXPORT
1525 void setSchemaInternal(const QString &schema);
1526
1527private:
1528 QString m_schema;
1529 QFont m_font;
1530 QColor m_backgroundColor;
1531 QColor m_selectionColor;
1532 QColor m_highlightedLineColor;
1533 QColor m_highlightedBracketColor;
1534 QColor m_wordWrapMarkerColor;
1535 QColor m_tabMarkerColor;
1536 QColor m_indentationLineColor;
1537 QColor m_iconBarColor;
1538 QColor m_foldingColor;
1539 QColor m_lineNumberColor;
1540 QColor m_currentLineNumberColor;
1541 QColor m_separatorColor;
1542 QColor m_spellingMistakeLineColor;
1543 std::vector<QColor> m_lineMarkerColor;
1544
1545 QColor m_templateBackgroundColor;
1546 QColor m_templateEditablePlaceholderColor;
1547 QColor m_templateFocusedEditablePlaceholderColor;
1548 QColor m_templateNotEditablePlaceholderColor;
1549
1550 QColor m_modifiedLineColor;
1551 QColor m_savedLineColor;
1552 QColor m_searchHighlightColor;
1553 QColor m_replaceHighlightColor;
1554
1555 qreal m_lineHeightMultiplier = 1.0;
1556
1557 bool m_wordWrapMarker = false;
1558 bool m_showIndentationLines = false;
1559 bool m_showWholeBracketExpression = false;
1560 bool m_animateBracketMatching = false;
1561
1562 bool m_schemaSet : 1;
1563 bool m_fontSet : 1;
1564 bool m_wordWrapMarkerSet : 1;
1565 bool m_showIndentationLinesSet : 1;
1566 bool m_showWholeBracketExpressionSet : 1;
1567 bool m_backgroundColorSet : 1;
1568 bool m_selectionColorSet : 1;
1569 bool m_highlightedLineColorSet : 1;
1570 bool m_highlightedBracketColorSet : 1;
1571 bool m_wordWrapMarkerColorSet : 1;
1572 bool m_tabMarkerColorSet : 1;
1573 bool m_indentationLineColorSet : 1;
1574 bool m_iconBarColorSet : 1;
1575 bool m_foldingColorSet : 1;
1576 bool m_lineNumberColorSet : 1;
1577 bool m_currentLineNumberColorSet : 1;
1578 bool m_separatorColorSet : 1;
1579 bool m_spellingMistakeLineColorSet : 1;
1580 bool m_templateColorsSet : 1;
1581 bool m_modifiedLineColorSet : 1;
1582 bool m_savedLineColorSet : 1;
1583 bool m_searchHighlightColorSet : 1;
1584 bool m_replaceHighlightColorSet : 1;
1585 QBitArray m_lineMarkerColorSet;
1586
1587private:
1588 static KateRendererConfig *s_global;
1589 KateRenderer *m_renderer = nullptr;
1590};
1591
1592#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
virtual ~KateConfig()
Virtual Destructor.
QStringList configKeys() const
All known config keys.
Definition kateconfig.h:76
virtual void updateConfig()=0
do the real update
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-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:11:27 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.