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

KDE's Doxygen guidelines are available online.