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

KDE's Doxygen guidelines are available online.