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