KTextEditor

kateconfig.cpp
1/*
2 SPDX-FileCopyrightText: 2007, 2008 Matthew Woehlke <mw_triad@users.sourceforge.net>
3 SPDX-FileCopyrightText: 2003 Christoph Cullmann <cullmann@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "kateconfig.h"
9
10#include "katedocument.h"
11#include "kateglobal.h"
12#include "katepartdebug.h"
13#include "katerenderer.h"
14#include "katesyntaxmanager.h"
15#include "kateview.h"
16
17#include <KConfigGroup>
18
19#include <KEncodingProber>
20#include <QGuiApplication>
21#include <QSettings>
22#include <QStringDecoder>
23#include <QStringEncoder>
24#include <QStringListModel>
25
26#include <Sonnet/GuessLanguage>
27#include <Sonnet/Speller>
28
29// BEGIN KateConfig
31 : m_parent(parent)
32 , m_configKeys(m_parent ? nullptr : new QStringList())
33 , m_configKeyToEntry(m_parent ? nullptr : new QHash<QString, const ConfigEntry *>())
34{
35}
36
37KateConfig::~KateConfig() = default;
38
40{
41 // shall only be called for toplevel config
42 Q_ASSERT(isGlobal());
43
44 // There shall be no gaps in the entries; i.e. in KateViewConfig constructor
45 // addConfigEntry() is called on each value from the ConfigEntryTypes enum in
46 // the same order as the enumrators.
47 // we might later want to use a vector
48 // qDebug() << m_configEntries.size() << entry.enumKey;
49 Q_ASSERT(m_configEntries.size() == static_cast<size_t>(entry.enumKey));
50
51 // add new element
52 m_configEntries.emplace(entry.enumKey, entry);
53}
54
56{
57 // shall only be called for toplevel config
58 Q_ASSERT(isGlobal());
59
60 // compute list of all config keys + register map from key => config entry
61 //
62 // we skip entries without a command name, these config entries are not exposed ATM
63 for (const auto &entry : m_configEntries) {
64 if (!entry.second.commandName.isEmpty()) {
65 Q_ASSERT_X(!m_configKeys->contains(entry.second.commandName),
66 "finalizeConfigEntries",
67 (QLatin1String("KEY NOT UNIQUE: ") + entry.second.commandName).toLocal8Bit().constData());
68 m_configKeys->append(entry.second.commandName);
69 m_configKeyToEntry->insert(entry.second.commandName, &entry.second);
70 }
71 }
72}
73
75{
77
78 // read all config entries, even the ones ATM not set in this config object but known in the toplevel one
79 for (const auto &entry : fullConfigEntries()) {
80 setValue(entry.second.enumKey, config.readEntry(entry.second.configKey, entry.second.defaultValue));
81 }
82
83 configEnd();
84}
85
87{
88 // write all config entries, even the ones ATM not set in this config object but known in the toplevel one
89 for (const auto &entry : fullConfigEntries()) {
90 config.writeEntry(entry.second.configKey, value(entry.second.enumKey));
91 }
92}
93
95{
97
98 if (configSessionNumber > 1) {
99 return;
100 }
101}
102
104{
105 if (configSessionNumber == 0) {
106 return;
107 }
108
110
111 if (configSessionNumber > 0) {
112 return;
113 }
114
115 updateConfig();
116}
117
118QVariant KateConfig::value(const int key) const
119{
120 // first: local lookup
121 const auto it = m_configEntries.find(key);
122 if (it != m_configEntries.end()) {
123 return it->second.value;
124 }
125
126 // else: fallback to parent config, if any
127 if (m_parent) {
128 return m_parent->value(key);
129 }
130
131 // if we arrive here, the key was invalid! => programming error
132 // for release builds, we just return invalid variant
133 Q_ASSERT(false);
134 return QVariant();
135}
136
137bool KateConfig::setValue(const int key, const QVariant &value)
138{
139 // check: is this key known at all?
140 const auto &knownEntries = fullConfigEntries();
141 const auto knownIt = knownEntries.find(key);
142 if (knownIt == knownEntries.end()) {
143 // if we arrive here, the key was invalid! => programming error
144 // for release builds, we just fail to set the value
145 Q_ASSERT(false);
146 return false;
147 }
148
149 // validator set? use it, if not accepting, abort setting
150 if (knownIt->second.validator && !knownIt->second.validator(value)) {
151 return false;
152 }
153
154 // check if value already there for this config
155 auto valueIt = m_configEntries.find(key);
156 if (valueIt != m_configEntries.end()) {
157 // skip any work if value is equal
158 if (valueIt->second.value == value) {
159 return true;
160 }
161
162 // else: alter value and be done
163 configStart();
164 valueIt->second.value = value;
165 configEnd();
166 return true;
167 }
168
169 // if not in this hash, we must copy the known entry and adjust the value
170 configStart();
171 auto res = m_configEntries.emplace(key, knownIt->second);
172 res.first->second.value = value;
173 configEnd();
174 return true;
175}
176
178{
179 // check if we know this key, if not, return invalid variant
180 const auto &knownEntries = fullConfigKeyToEntry();
181 const auto it = knownEntries.find(key);
182 if (it == knownEntries.end()) {
183 return QVariant();
184 }
185
186 // key known, dispatch to normal value() function with enum
187 return value(it.value()->enumKey);
188}
189
191{
192 // check if we know this key, if not, ignore the set
193 const auto &knownEntries = fullConfigKeyToEntry();
194 const auto it = knownEntries.find(key);
195 if (it == knownEntries.end()) {
196 return false;
197 }
198
199 // key known, dispatch to normal setValue() function with enum
200 return setValue(it.value()->enumKey, value);
201}
202
203// END
204
205// BEGIN HelperFunctions
206KateGlobalConfig *KateGlobalConfig::s_global = nullptr;
207KateDocumentConfig *KateDocumentConfig::s_global = nullptr;
208KateViewConfig *KateViewConfig::s_global = nullptr;
209KateRendererConfig *KateRendererConfig::s_global = nullptr;
210
211/**
212 * validate if an encoding is ok
213 * @param name encoding name
214 * @return encoding ok?
215 */
216static bool isEncodingOk(const QString &name)
217{
219}
220
221static bool inBounds(const int min, const QVariant &value, const int max)
222{
223 const int val = value.toInt();
224 return (val >= min) && (val <= max);
225}
226
227static bool isPositive(const QVariant &value)
228{
229 bool ok;
230 value.toUInt(&ok);
231 return ok;
232}
233// END
234
235// BEGIN KateGlobalConfig
236KateGlobalConfig::KateGlobalConfig()
237{
238 // register this as our global instance
239 Q_ASSERT(isGlobal());
240 s_global = this;
241
242 // avoid updateConfig effects like config write in constructor, see bug 377067
243 Q_ASSERT(configSessionNumber == 0);
245
246 // init all known config entries
247 addConfigEntry(ConfigEntry(EncodingProberType, "Encoding Prober Type", QString(), KEncodingProber::Universal));
248 addConfigEntry(ConfigEntry(FallbackEncoding,
249 "Fallback Encoding",
250 QString(),
252 [](const QVariant &value) {
253 return isEncodingOk(value.toString());
254 }));
255
256 // finalize the entries, e.g. hashs them
258
259 // init with defaults from config or really hardcoded ones
260 KConfigGroup cg(KTextEditor::EditorPrivate::config(), QStringLiteral("KTextEditor Editor"));
261 readConfig(cg);
262
263 // avoid updateConfig effects like config write in constructor, see bug 377067
264 Q_ASSERT(configSessionNumber == 1);
266}
267
268void KateGlobalConfig::readConfig(const KConfigGroup &config)
269{
270 // start config update group
271 configStart();
272
273 // read generic entries
274 readConfigEntries(config);
275
276 // end config update group, might trigger updateConfig()
277 configEnd();
278}
279
280void KateGlobalConfig::writeConfig(KConfigGroup &config)
281{
282 // write generic entries
283 writeConfigEntries(config);
284}
285
286void KateGlobalConfig::updateConfig()
287{
288 // write config
289 KConfigGroup cg(KTextEditor::EditorPrivate::config(), QStringLiteral("KTextEditor Editor"));
290 writeConfig(cg);
292
293 // trigger emission of KTextEditor::Editor::configChanged
295}
296// END
297
298// BEGIN KateDocumentConfig
299KateDocumentConfig::KateDocumentConfig()
300{
301 // register this as our global instance
302 Q_ASSERT(isGlobal());
303 s_global = this;
304
305 // avoid updateConfig effects like config write in constructor, see bug 377067
306 Q_ASSERT(configSessionNumber == 0);
308
309 // init all known config entries
310 addConfigEntry(ConfigEntry(TabWidth, "Tab Width", QStringLiteral("tab-width"), 4, [](const QVariant &value) {
311 return value.toInt() >= 1;
312 }));
313 addConfigEntry(ConfigEntry(IndentationWidth, "Indentation Width", QStringLiteral("indent-width"), 4, [](const QVariant &value) {
314 return value.toInt() >= 1;
315 }));
316 addConfigEntry(ConfigEntry(OnTheFlySpellCheck, "On-The-Fly Spellcheck", QStringLiteral("on-the-fly-spellcheck"), false));
317 addConfigEntry(ConfigEntry(IndentOnTextPaste, "Indent On Text Paste", QStringLiteral("indent-pasted-text"), true));
318 addConfigEntry(ConfigEntry(ReplaceTabsWithSpaces, "ReplaceTabsDyn", QStringLiteral("replace-tabs"), true));
319 addConfigEntry(ConfigEntry(BackupOnSaveLocal, "Backup Local", QStringLiteral("backup-on-save-local"), false));
320 addConfigEntry(ConfigEntry(BackupOnSaveRemote, "Backup Remote", QStringLiteral("backup-on-save-remote"), false));
321 addConfigEntry(ConfigEntry(BackupOnSavePrefix, "Backup Prefix", QStringLiteral("backup-on-save-prefix"), QString()));
322 addConfigEntry(ConfigEntry(BackupOnSaveSuffix, "Backup Suffix", QStringLiteral("backup-on-save-suffix"), QStringLiteral("~")));
323 addConfigEntry(ConfigEntry(IndentationMode, "Indentation Mode", QString(), QStringLiteral("normal")));
324 addConfigEntry(ConfigEntry(TabHandlingMode, "Tab Handling", QString(), KateDocumentConfig::tabSmart));
325 addConfigEntry(ConfigEntry(StaticWordWrap, "Word Wrap", QString(), false));
326 addConfigEntry(ConfigEntry(StaticWordWrapColumn, "Word Wrap Column", QString(), 80, [](const QVariant &value) {
327 return value.toInt() >= 1;
328 }));
329 addConfigEntry(ConfigEntry(PageUpDownMovesCursor, "PageUp/PageDown Moves Cursor", QString(), false));
330 addConfigEntry(ConfigEntry(SmartHome, "Smart Home", QString(), true));
331 addConfigEntry(ConfigEntry(ShowTabs, "Show Tabs", QString(), true));
332 addConfigEntry(ConfigEntry(IndentOnTab, "Indent On Tab", QString(), true));
333 addConfigEntry(ConfigEntry(KeepExtraSpaces, "Keep Extra Spaces", QStringLiteral("keep-extra-spaces"), false));
334 addConfigEntry(ConfigEntry(BackspaceIndents, "Indent On Backspace", QString(), true));
335 addConfigEntry(ConfigEntry(ShowSpacesMode, "Show Spaces", QString(), KateDocumentConfig::None));
336 addConfigEntry(ConfigEntry(TrailingMarkerSize, "Trailing Marker Size", QString(), 1));
338 ConfigEntry(RemoveSpacesMode, "Remove Spaces", QStringLiteral("remove-spaces"), 1 /* on modified lines per default */, [](const QVariant &value) {
339 return inBounds(0, value, 2);
340 }));
341 addConfigEntry(ConfigEntry(NewlineAtEOF, "Newline at End of File", QString(), true));
342 addConfigEntry(ConfigEntry(OverwriteMode, "Overwrite Mode", QString(), false));
344 ConfigEntry(Encoding, "Encoding", QString(), QString::fromUtf8(QStringConverter::nameForEncoding(QStringConverter::Utf8)), [](const QVariant &value) {
345 return isEncodingOk(value.toString());
346 }));
347 addConfigEntry(ConfigEntry(EndOfLine, "End of Line", QString(), 0));
348 addConfigEntry(ConfigEntry(AllowEndOfLineDetection, "Allow End of Line Detection", QString(), true));
349 addConfigEntry(ConfigEntry(ByteOrderMark, "BOM", QString(), false));
350 addConfigEntry(ConfigEntry(SwapFile, "Swap File Mode", QString(), KateDocumentConfig::EnableSwapFile));
351 addConfigEntry(ConfigEntry(SwapFileDirectory, "Swap Directory", QString(), QString()));
352 addConfigEntry(ConfigEntry(SwapFileSyncInterval, "Swap Sync Interval", QString(), 15));
353 addConfigEntry(ConfigEntry(LineLengthLimit, "Line Length Limit", QString(), 10000));
354 addConfigEntry(ConfigEntry(CamelCursor, "Camel Cursor", QString(), true));
355 addConfigEntry(ConfigEntry(AutoDetectIndent, "Auto Detect Indent", QString(), true));
356
357 // Auto save and co.
358 addConfigEntry(ConfigEntry(AutoSave, "Auto Save", QString(), false));
359 addConfigEntry(ConfigEntry(AutoSaveOnFocusOut, "Auto Save On Focus Out", QString(), false));
360 addConfigEntry(ConfigEntry(AutoSaveInteral, "Auto Save Interval", QString(), 0));
361
362 // Shall we do auto reloading for stuff e.g. in Git?
363 addConfigEntry(ConfigEntry(AutoReloadIfStateIsInVersionControl, "Auto Reload If State Is In Version Control", QString(), true));
364 // .editorconfig
365 addConfigEntry(ConfigEntry(UseEditorConfig, "Use Editor Config", QString(), true));
366
367 // finalize the entries, e.g. hashs them
369
370 // init with defaults from config or really hardcoded ones
371 KConfigGroup cg(KTextEditor::EditorPrivate::config(), QStringLiteral("KTextEditor Document"));
372 readConfig(cg);
373
374 // avoid updateConfig effects like config write in constructor, see bug 377067
375 Q_ASSERT(configSessionNumber == 1);
377}
378
379KateDocumentConfig::KateDocumentConfig(KTextEditor::DocumentPrivate *doc)
380 : KateConfig(s_global)
381 , m_doc(doc)
382{
383 // per document config doesn't read stuff per default
384}
385
386void KateDocumentConfig::readConfig(const KConfigGroup &config)
387{
388 // start config update group
389 configStart();
390
391 // read generic entries
392 readConfigEntries(config);
393
394 // fixup sonnet config, see KateSpellCheckConfigTab::apply(), too
395 // WARNING: this is slightly hackish, but it's currently the only way to
396 // do it, see also the KTextEdit class
397 if (isGlobal()) {
398 const QSettings settings(QStringLiteral("KDE"), QStringLiteral("Sonnet"));
399 const bool onTheFlyChecking = settings.value(QStringLiteral("checkerEnabledByDefault"), false).toBool();
400 setOnTheFlySpellCheck(onTheFlyChecking);
401
402 // ensure we load the default dictionary speller + trigrams early
403 // this avoids hangs for auto-spellchecking on first edits
404 // do this if we have on the fly spellchecking on only
405 if (onTheFlyChecking) {
406 Sonnet::Speller speller;
407 speller.setLanguage(Sonnet::Speller().defaultLanguage());
408 Sonnet::GuessLanguage languageGuesser;
409 languageGuesser.identify(QStringLiteral("dummy to trigger identify"));
410 }
411 }
412
413 // backwards compatibility mappings
414 // convert stuff, old entries deleted in writeConfig
415 if (const int backupFlags = config.readEntry("Backup Flags", 0)) {
416 setBackupOnSaveLocal(backupFlags & 0x1);
417 setBackupOnSaveRemote(backupFlags & 0x2);
418 }
419
420 // end config update group, might trigger updateConfig()
421 configEnd();
422}
423
424void KateDocumentConfig::writeConfig(KConfigGroup &config)
425{
426 // write generic entries
427 writeConfigEntries(config);
428
429 // backwards compatibility mappings
430 // here we remove old entries we converted on readConfig
431 config.deleteEntry("Backup Flags");
432}
433
434void KateDocumentConfig::updateConfig()
435{
436 if (m_doc) {
437 m_doc->updateConfig();
438 return;
439 }
440
441 if (isGlobal()) {
442 const auto docs = KTextEditor::EditorPrivate::self()->documents();
443 for (auto doc : docs) {
444 static_cast<KTextEditor::DocumentPrivate *>(doc)->updateConfig();
445 }
446
447 // write config
448 KConfigGroup cg(KTextEditor::EditorPrivate::config(), QStringLiteral("KTextEditor Document"));
449 writeConfig(cg);
451
452 // trigger emission of KTextEditor::Editor::configChanged
454 }
455}
456
457QString KateDocumentConfig::eolString() const
458{
459 switch (eol()) {
460 case KateDocumentConfig::eolDos:
461 return QStringLiteral("\r\n");
462
463 case KateDocumentConfig::eolMac:
464 return QStringLiteral("\r");
465
466 default:
467 return QStringLiteral("\n");
468 }
469}
470// END
471
472// BEGIN KateViewConfig
473KateViewConfig::KateViewConfig()
474{
475 // register this as our global instance
476 Q_ASSERT(isGlobal());
477 s_global = this;
478
479 // avoid updateConfig effects like config write in constructor, see bug 377067
480 Q_ASSERT(configSessionNumber == 0);
482
483 // Init all known config entries
484 // NOTE: Ensure to keep the same order as listed in enum ConfigEntryTypes or it will later assert!
485 // addConfigEntry(ConfigEntry(<EnumKey>, <ConfigKey>, <CommandName>, <DefaultValue>, [<ValidatorFunction>]))
486 addConfigEntry(ConfigEntry(AllowMarkMenu, "Allow Mark Menu", QStringLiteral("allow-mark-menu"), true));
487 addConfigEntry(ConfigEntry(AutoBrackets, "Auto Brackets", QStringLiteral("auto-brackets"), true));
488 addConfigEntry(ConfigEntry(AutoCenterLines, "Auto Center Lines", QStringLiteral("auto-center-lines"), 0));
489 addConfigEntry(ConfigEntry(AutomaticCompletionInvocation, "Auto Completion", QString(), true));
490 addConfigEntry(ConfigEntry(AutomaticCompletionPreselectFirst, "Auto Completion Preselect First Entry", QString(), true));
491 addConfigEntry(ConfigEntry(BackspaceRemoveComposedCharacters, "Backspace Remove Composed Characters", QString(), false));
492 addConfigEntry(ConfigEntry(BookmarkSorting, "Bookmark Menu Sorting", QString(), 0));
493 addConfigEntry(ConfigEntry(CharsToEncloseSelection, "Chars To Enclose Selection", QStringLiteral("enclose-selection"), QStringLiteral("<>(){}[]'\"")));
494 addConfigEntry(ConfigEntry(ClipboardHistoryEntries, "Max Clipboard History Entries", QString(), 20, [](const QVariant &value) {
495 return inBounds(1, value, 999);
496 }));
498 ConfigEntry(DefaultMarkType, "Default Mark Type", QStringLiteral("default-mark-type"), KTextEditor::Document::markType01, [](const QVariant &value) {
499 return isPositive(value);
500 }));
501 addConfigEntry(ConfigEntry(DynWordWrapAlignIndent, "Dynamic Word Wrap Align Indent", QString(), 80, [](const QVariant &value) {
502 return inBounds(0, value, 100);
503 }));
504 addConfigEntry(ConfigEntry(DynWordWrapIndicators, "Dynamic Word Wrap Indicators", QString(), 1, [](const QVariant &value) {
505 return inBounds(0, value, 2);
506 }));
507 addConfigEntry(ConfigEntry(DynWrapAnywhere, "Dynamic Wrap not at word boundaries", QStringLiteral("dynamic-word-wrap-anywhere"), false));
508 addConfigEntry(ConfigEntry(DynWrapAtStaticMarker, "Dynamic Word Wrap At Static Marker", QString(), false));
509 addConfigEntry(ConfigEntry(DynamicWordWrap, "Dynamic Word Wrap", QStringLiteral("dynamic-word-wrap"), true));
510 addConfigEntry(ConfigEntry(EnterToInsertCompletion, "Enter To Insert Completion", QStringLiteral("enter-to-insert-completion"), true));
511 addConfigEntry(ConfigEntry(FoldFirstLine, "Fold First Line", QString(), false));
512 addConfigEntry(ConfigEntry(InputMode, "Input Mode", QString(), 0, [](const QVariant &value) {
513 return isPositive(value);
514 }));
515 addConfigEntry(ConfigEntry(KeywordCompletion, "Keyword Completion", QStringLiteral("keyword-completion"), true));
516 addConfigEntry(ConfigEntry(MaxHistorySize, "Maximum Search History Size", QString(), 100, [](const QVariant &value) {
517 return inBounds(0, value, 999);
518 }));
519 addConfigEntry(ConfigEntry(MousePasteAtCursorPosition, "Mouse Paste At Cursor Position", QString(), false));
520 addConfigEntry(ConfigEntry(PersistentSelection, "Persistent Selection", QStringLiteral("persistent-selectionq"), false));
521 addConfigEntry(ConfigEntry(ScrollBarMiniMapWidth, "Scroll Bar Mini Map Width", QString(), 60, [](const QVariant &value) {
522 return inBounds(0, value, 999);
523 }));
524 addConfigEntry(ConfigEntry(ScrollPastEnd, "Scroll Past End", QString(), false));
525 addConfigEntry(ConfigEntry(SearchFlags, "Search/Replace Flags", QString(), IncFromCursor | PowerMatchCase | PowerModePlainText));
526 addConfigEntry(ConfigEntry(TabCompletion, "Enable Tab completion", QString(), false));
527 addConfigEntry(ConfigEntry(ShowBracketMatchPreview, "Bracket Match Preview", QStringLiteral("bracket-match-preview"), false));
528 addConfigEntry(ConfigEntry(ShowFoldingBar, "Folding Bar", QStringLiteral("folding-bar"), true));
529 addConfigEntry(ConfigEntry(ShowFoldingPreview, "Folding Preview", QStringLiteral("folding-preview"), true));
530 addConfigEntry(ConfigEntry(ShowIconBar, "Icon Bar", QStringLiteral("icon-bar"), false));
531 addConfigEntry(ConfigEntry(ShowLineCount, "Show Line Count", QString(), false));
532 addConfigEntry(ConfigEntry(ShowLineModification, "Line Modification", QStringLiteral("modification-markers"), true));
533 addConfigEntry(ConfigEntry(ShowLineNumbers, "Line Numbers", QStringLiteral("line-numbers"), true));
534 addConfigEntry(ConfigEntry(ShowScrollBarMarks, "Scroll Bar Marks", QString(), false));
535 addConfigEntry(ConfigEntry(ShowScrollBarMiniMap, "Scroll Bar MiniMap", QStringLiteral("scrollbar-minimap"), true));
536 addConfigEntry(ConfigEntry(ShowScrollBarMiniMapAll, "Scroll Bar Mini Map All", QString(), true));
537 addConfigEntry(ConfigEntry(ShowScrollBarPreview, "Scroll Bar Preview", QStringLiteral("scrollbar-preview"), true));
538 addConfigEntry(ConfigEntry(ShowScrollbars, "Show Scrollbars", QString(), AlwaysOn, [](const QVariant &value) {
539 return inBounds(0, value, 2);
540 }));
541 addConfigEntry(ConfigEntry(ShowWordCount, "Show Word Count", QString(), false));
542 addConfigEntry(ConfigEntry(TextDragAndDrop, "Text Drag And Drop", QString(), true));
543 addConfigEntry(ConfigEntry(SmartCopyCut, "Smart Copy Cut", QString(), true));
544 addConfigEntry(ConfigEntry(UserSetsOfCharsToEncloseSelection, "User Sets Of Chars To Enclose Selection", QString(), QStringList()));
545 addConfigEntry(ConfigEntry(ViInputModeStealKeys, "Vi Input Mode Steal Keys", QString(), false));
546 addConfigEntry(ConfigEntry(ViRelativeLineNumbers, "Vi Relative Line Numbers", QString(), false));
547 addConfigEntry(ConfigEntry(WordCompletion, "Word Completion", QString(), true));
548 addConfigEntry(ConfigEntry(WordCompletionMinimalWordLength,
549 "Word Completion Minimal Word Length",
550 QStringLiteral("word-completion-minimal-word-length"),
551 3,
552 [](const QVariant &value) {
553 return inBounds(0, value, 99);
554 }));
555 addConfigEntry(ConfigEntry(WordCompletionRemoveTail, "Word Completion Remove Tail", QString(), true));
556 addConfigEntry(ConfigEntry(ShowDocWithCompletion, "Show Documentation With Completion", QString(), true));
557 addConfigEntry(ConfigEntry(MultiCursorModifier, "Multiple Cursor Modifier", QString(), (int)Qt::AltModifier));
558 addConfigEntry(ConfigEntry(ShowFoldingOnHoverOnly, "Show Folding Icons On Hover Only", QString(), true));
559
560 // Statusbar stuff
561 addConfigEntry(ConfigEntry(ShowStatusbarLineColumn, "Show Statusbar Line Column", QString(), true));
562 addConfigEntry(ConfigEntry(ShowStatusbarDictionary, "Show Statusbar Dictionary", QString(), true));
563 addConfigEntry(ConfigEntry(ShowStatusbarInputMode, "Show Statusbar Input Mode", QString(), true));
564 addConfigEntry(ConfigEntry(ShowStatusbarHighlightingMode, "Show Statusbar Highlighting Mode", QString(), true));
565 addConfigEntry(ConfigEntry(ShowStatusbarTabSettings, "Show Statusbar Tab Settings", QString(), true));
566 addConfigEntry(ConfigEntry(ShowStatusbarFileEncoding, "Show File Encoding", QString(), true));
567 addConfigEntry(ConfigEntry(StatusbarLineColumnCompact, "Statusbar Line Column Compact Mode", QString(), true));
568 addConfigEntry(ConfigEntry(ShowStatusbarEOL, "Shoe Line Ending Type in Statusbar", QString(), false));
569 addConfigEntry(ConfigEntry(EnableAccessibility, "Enable Accessibility", QString(), true));
570 addConfigEntry(ConfigEntry(CycleThroughBookmarks, "Cycle Through Bookmarks", QString(), true));
571
572 // Never forget to finalize or the <CommandName> becomes not available
574
575 // init with defaults from config or really hardcoded ones
576 KConfigGroup config(KTextEditor::EditorPrivate::config(), QStringLiteral("KTextEditor View"));
577 readConfig(config);
578
579 // avoid updateConfig effects like config write in constructor, see bug 377067
580 Q_ASSERT(configSessionNumber == 1);
582}
583
584KateViewConfig::KateViewConfig(KTextEditor::ViewPrivate *view)
585 : KateConfig(s_global)
586 , m_view(view)
587{
588}
589
590KateViewConfig::~KateViewConfig() = default;
591
592void KateViewConfig::readConfig(const KConfigGroup &config)
593{
594 configStart();
595
596 // read generic entries
597 readConfigEntries(config);
598
599 configEnd();
600}
601
602void KateViewConfig::writeConfig(KConfigGroup &config)
603{
604 // write generic entries
605 writeConfigEntries(config);
606}
607
608void KateViewConfig::updateConfig()
609{
610 if (m_view) {
611 m_view->updateConfig();
612 return;
613 }
614
615 if (isGlobal()) {
616 for (KTextEditor::ViewPrivate *view : KTextEditor::EditorPrivate::self()->views()) {
617 view->updateConfig();
618 }
619
620 // write config
621 KConfigGroup cg(KTextEditor::EditorPrivate::config(), QStringLiteral("KTextEditor View"));
622 writeConfig(cg);
624
625 // trigger emission of KTextEditor::Editor::configChanged
627 }
628}
629// END
630
631// BEGIN KateRendererConfig
632KateRendererConfig::KateRendererConfig()
633 : m_lineMarkerColor(KTextEditor::Document::reservedMarkersCount())
634 , m_schemaSet(false)
635 , m_fontSet(false)
636 , m_wordWrapMarkerSet(false)
637 , m_showIndentationLinesSet(false)
638 , m_showWholeBracketExpressionSet(false)
639 , m_backgroundColorSet(false)
640 , m_selectionColorSet(false)
641 , m_highlightedLineColorSet(false)
642 , m_highlightedBracketColorSet(false)
643 , m_wordWrapMarkerColorSet(false)
644 , m_tabMarkerColorSet(false)
645 , m_indentationLineColorSet(false)
646 , m_iconBarColorSet(false)
647 , m_foldingColorSet(false)
648 , m_lineNumberColorSet(false)
649 , m_currentLineNumberColorSet(false)
650 , m_separatorColorSet(false)
651 , m_spellingMistakeLineColorSet(false)
652 , m_templateColorsSet(false)
653 , m_modifiedLineColorSet(false)
654 , m_savedLineColorSet(false)
655 , m_searchHighlightColorSet(false)
656 , m_replaceHighlightColorSet(false)
657 , m_lineMarkerColorSet(m_lineMarkerColor.size())
658
659{
660 // init bitarray
661 m_lineMarkerColorSet.fill(true);
662
663 // register this as our global instance
664 Q_ASSERT(isGlobal());
665 s_global = this;
666
667 // avoid updateConfig effects like config write in constructor, see bug 377067
668 Q_ASSERT(configSessionNumber == 0);
670
671 // Init all known config entries
672 addConfigEntry(ConfigEntry(AutoColorThemeSelection, "Auto Color Theme Selection", QString(), true));
673
674 // Never forget to finalize or the <CommandName> becomes not available
676
677 // init with defaults from config or really hardcoded ones
678 KConfigGroup config(KTextEditor::EditorPrivate::config(), QStringLiteral("KTextEditor Renderer"));
679 readConfig(config);
680
681 // avoid updateConfig effects like config write in constructor, see bug 377067
682 Q_ASSERT(configSessionNumber == 1);
684}
685
686KateRendererConfig::KateRendererConfig(KateRenderer *renderer)
687 : KateConfig(s_global)
688 , m_lineMarkerColor(KTextEditor::Document::reservedMarkersCount())
689 , m_schemaSet(false)
690 , m_fontSet(false)
691 , m_wordWrapMarkerSet(false)
692 , m_showIndentationLinesSet(false)
693 , m_showWholeBracketExpressionSet(false)
694 , m_backgroundColorSet(false)
695 , m_selectionColorSet(false)
696 , m_highlightedLineColorSet(false)
697 , m_highlightedBracketColorSet(false)
698 , m_wordWrapMarkerColorSet(false)
699 , m_tabMarkerColorSet(false)
700 , m_indentationLineColorSet(false)
701 , m_iconBarColorSet(false)
702 , m_foldingColorSet(false)
703 , m_lineNumberColorSet(false)
704 , m_currentLineNumberColorSet(false)
705 , m_separatorColorSet(false)
706 , m_spellingMistakeLineColorSet(false)
707 , m_templateColorsSet(false)
708 , m_modifiedLineColorSet(false)
709 , m_savedLineColorSet(false)
710 , m_searchHighlightColorSet(false)
711 , m_replaceHighlightColorSet(false)
712 , m_lineMarkerColorSet(m_lineMarkerColor.size())
713 , m_renderer(renderer)
714{
715 // init bitarray
716 m_lineMarkerColorSet.fill(false);
717}
718
719KateRendererConfig::~KateRendererConfig() = default;
720
721namespace
722{
723const char KEY_FONT[] = "Text Font";
724const char KEY_FONT_FEATURES[] = "Text Font Features";
725const char KEY_COLOR_THEME[] = "Color Theme";
726const char KEY_WORD_WRAP_MARKER[] = "Word Wrap Marker";
727const char KEY_SHOW_INDENTATION_LINES[] = "Show Indentation Lines";
728const char KEY_SHOW_WHOLE_BRACKET_EXPRESSION[] = "Show Whole Bracket Expression";
729const char KEY_ANIMATE_BRACKET_MATCHING[] = "Animate Bracket Matching";
730const char KEY_LINE_HEIGHT_MULTIPLIER[] = "Line Height Multiplier";
731}
732
733void KateRendererConfig::readConfig(const KConfigGroup &config)
734{
735 configStart();
736
737 // read generic entries
738 readConfigEntries(config);
739
740 // read font, including font features
741 auto font = config.readEntry(KEY_FONT, QFontDatabase::systemFont(QFontDatabase::FixedFont));
742#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
743 const QStringList rawFeaturesList = config.readEntry(KEY_FONT_FEATURES, QStringList());
744 for (const QString &feature : rawFeaturesList) {
745 const auto parts = feature.split(QStringLiteral("="), Qt::SkipEmptyParts);
746 if (parts.length() == 2) {
747 const auto tag = QFont::Tag::fromString(parts[0]);
748 bool ok = false;
749 const int number = parts[1].toInt(&ok);
750 if (tag.has_value() && ok) {
751 font.setFeature(tag.value(), number);
752 }
753 }
754 }
755#endif
756 setFont(font);
757
758 // setSchema will default to right theme
759 setSchema(config.readEntry(KEY_COLOR_THEME, QString()));
760
761 setWordWrapMarker(config.readEntry(KEY_WORD_WRAP_MARKER, false));
762
763 setShowIndentationLines(config.readEntry(KEY_SHOW_INDENTATION_LINES, false));
764
765 setShowWholeBracketExpression(config.readEntry(KEY_SHOW_WHOLE_BRACKET_EXPRESSION, false));
766
767 setAnimateBracketMatching(config.readEntry(KEY_ANIMATE_BRACKET_MATCHING, false));
768
769 setLineHeightMultiplier(config.readEntry<qreal>(KEY_LINE_HEIGHT_MULTIPLIER, 1.0));
770
771 configEnd();
772}
773
774void KateRendererConfig::writeConfig(KConfigGroup &config)
775{
776 // write generic entries
777 writeConfigEntries(config);
778
779 // write font, including font features
780 const auto font = baseFont();
781 config.writeEntry(KEY_FONT, font);
782#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
783 const auto tags = font.featureTags();
784 QStringList features;
785 for (const auto &tag : tags) {
786 const QString name = QString::fromUtf8(tag.toString());
787 const quint32 value = font.featureValue(tag);
788 features.push_back(QStringLiteral("%1=%2").arg(name, QString::number(value)));
789 }
790 config.writeEntry(KEY_FONT_FEATURES, features);
791#endif
792
793 config.writeEntry(KEY_COLOR_THEME, schema());
794
795 config.writeEntry(KEY_WORD_WRAP_MARKER, wordWrapMarker());
796
797 config.writeEntry(KEY_SHOW_INDENTATION_LINES, showIndentationLines());
798
799 config.writeEntry(KEY_SHOW_WHOLE_BRACKET_EXPRESSION, showWholeBracketExpression());
800
801 config.writeEntry(KEY_ANIMATE_BRACKET_MATCHING, animateBracketMatching());
802
803 config.writeEntry<qreal>(KEY_LINE_HEIGHT_MULTIPLIER, lineHeightMultiplier());
804}
805
806void KateRendererConfig::updateConfig()
807{
808 if (m_renderer) {
809 m_renderer->updateConfig();
810 return;
811 }
812
813 if (isGlobal()) {
814 for (auto view : KTextEditor::EditorPrivate::self()->views()) {
815 view->renderer()->updateConfig();
816 }
817
818 // write config
819 KConfigGroup cg(KTextEditor::EditorPrivate::config(), QStringLiteral("KTextEditor Renderer"));
820 writeConfig(cg);
822
823 // trigger emission of KTextEditor::Editor::configChanged
825 }
826}
827
828const QString &KateRendererConfig::schema() const
829{
830 if (m_schemaSet || isGlobal()) {
831 return m_schema;
832 }
833
834 return s_global->schema();
835}
836
837void KateRendererConfig::setSchema(QString schema)
838{
839 // check if we have some matching theme, else fallback to best theme for current palette
840 // same behavior as for the "Automatic Color Theme Selection"
841 if (!KateHlManager::self()->repository().theme(schema).isValid()) {
842 schema = KateHlManager::self()->repository().themeForPalette(qGuiApp->palette()).name();
843 }
844
845 if (m_schemaSet && m_schema == schema) {
846 return;
847 }
848
849 configStart();
850 m_schemaSet = true;
851 m_schema = schema;
852 setSchemaInternal(m_schema);
853 configEnd();
854}
855
856void KateRendererConfig::reloadSchema()
857{
858 if (isGlobal()) {
859 setSchemaInternal(m_schema);
860 for (KTextEditor::ViewPrivate *view : KTextEditor::EditorPrivate::self()->views()) {
861 view->rendererConfig()->reloadSchema();
862 }
863 }
864
865 else if (m_renderer && m_schemaSet) {
866 setSchemaInternal(m_schema);
867 }
868
869 // trigger renderer/view update
870 if (m_renderer) {
871 m_renderer->updateConfig();
872 }
873}
874
875void KateRendererConfig::setSchemaInternal(const QString &schema)
876{
877 // we always set the theme if we arrive here!
878 m_schemaSet = true;
879
880 // for the global config, we honor the auto selection based on the palette
881 // do the same if the set theme really doesn't exist, we need a valid theme or the rendering will be broken in bad ways!
882 if ((isGlobal() && value(AutoColorThemeSelection).toBool()) || !KateHlManager::self()->repository().theme(schema).isValid()) {
883 // always choose some theme matching the current application palette
884 // we will arrive here after palette changed signals, too!
885 m_schema = KateHlManager::self()->repository().themeForPalette(qGuiApp->palette()).name();
886 } else {
887 // take user given theme 1:1
888 m_schema = schema;
889 }
890
891 const auto theme = KateHlManager::self()->repository().theme(m_schema);
892
893 m_backgroundColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::BackgroundColor));
894 m_backgroundColorSet = true;
895
896 m_selectionColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::TextSelection));
897 m_selectionColorSet = true;
898
899 m_highlightedLineColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::CurrentLine));
900 m_highlightedLineColorSet = true;
901
902 m_highlightedBracketColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::BracketMatching));
903 m_highlightedBracketColorSet = true;
904
905 m_wordWrapMarkerColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::WordWrapMarker));
906 m_wordWrapMarkerColorSet = true;
907
908 m_tabMarkerColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::TabMarker));
909 m_tabMarkerColorSet = true;
910
911 m_indentationLineColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::IndentationLine));
912 m_indentationLineColorSet = true;
913
914 m_iconBarColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::IconBorder));
915 m_iconBarColorSet = true;
916
917 m_foldingColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::CodeFolding));
918 m_foldingColorSet = true;
919
920 m_lineNumberColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::LineNumbers));
921 m_lineNumberColorSet = true;
922
923 m_currentLineNumberColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::CurrentLineNumber));
924 m_currentLineNumberColorSet = true;
925
926 m_separatorColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::Separator));
927 m_separatorColorSet = true;
928
929 m_spellingMistakeLineColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::SpellChecking));
930 m_spellingMistakeLineColorSet = true;
931
932 m_modifiedLineColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::ModifiedLines));
933 m_modifiedLineColorSet = true;
934
935 m_savedLineColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::SavedLines));
936 m_savedLineColorSet = true;
937
938 m_searchHighlightColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::SearchHighlight));
939 m_searchHighlightColorSet = true;
940
941 m_replaceHighlightColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::ReplaceHighlight));
942 m_replaceHighlightColorSet = true;
943
945 QColor col =
947 m_lineMarkerColorSet[i] = true;
948 m_lineMarkerColor[i] = col;
949 }
950
951 m_templateBackgroundColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::TemplateBackground));
952
953 m_templateFocusedEditablePlaceholderColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::TemplateFocusedPlaceholder));
954
955 m_templateEditablePlaceholderColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::TemplatePlaceholder));
956
957 m_templateNotEditablePlaceholderColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::TemplateReadOnlyPlaceholder));
958
959 m_templateColorsSet = true;
960}
961
962const QFont &KateRendererConfig::baseFont() const
963{
964 if (m_fontSet || isGlobal()) {
965 return m_font;
966 }
967
968 return s_global->baseFont();
969}
970
971void KateRendererConfig::setFont(const QFont &font)
972{
973 if (m_fontSet && m_font == font) {
974 return;
975 }
976
977 configStart();
978 m_font = font;
979 m_fontSet = true;
980 configEnd();
981}
982
983bool KateRendererConfig::wordWrapMarker() const
984{
985 if (m_wordWrapMarkerSet || isGlobal()) {
986 return m_wordWrapMarker;
987 }
988
989 return s_global->wordWrapMarker();
990}
991
992void KateRendererConfig::setWordWrapMarker(bool on)
993{
994 if (m_wordWrapMarkerSet && m_wordWrapMarker == on) {
995 return;
996 }
997
998 configStart();
999
1000 m_wordWrapMarkerSet = true;
1001 m_wordWrapMarker = on;
1002
1003 configEnd();
1004}
1005
1006const QColor &KateRendererConfig::backgroundColor() const
1007{
1008 if (m_backgroundColorSet || isGlobal()) {
1009 return m_backgroundColor;
1010 }
1011
1012 return s_global->backgroundColor();
1013}
1014
1015void KateRendererConfig::setBackgroundColor(const QColor &col)
1016{
1017 if (m_backgroundColorSet && m_backgroundColor == col) {
1018 return;
1019 }
1020
1021 configStart();
1022
1023 m_backgroundColorSet = true;
1024 m_backgroundColor = col;
1025
1026 configEnd();
1027}
1028
1029const QColor &KateRendererConfig::selectionColor() const
1030{
1031 if (m_selectionColorSet || isGlobal()) {
1032 return m_selectionColor;
1033 }
1034
1035 return s_global->selectionColor();
1036}
1037
1038void KateRendererConfig::setSelectionColor(const QColor &col)
1039{
1040 if (m_selectionColorSet && m_selectionColor == col) {
1041 return;
1042 }
1043
1044 configStart();
1045
1046 m_selectionColorSet = true;
1047 m_selectionColor = col;
1048
1049 configEnd();
1050}
1051
1052const QColor &KateRendererConfig::highlightedLineColor() const
1053{
1054 if (m_highlightedLineColorSet || isGlobal()) {
1055 return m_highlightedLineColor;
1056 }
1057
1058 return s_global->highlightedLineColor();
1059}
1060
1061void KateRendererConfig::setHighlightedLineColor(const QColor &col)
1062{
1063 if (m_highlightedLineColorSet && m_highlightedLineColor == col) {
1064 return;
1065 }
1066
1067 configStart();
1068
1069 m_highlightedLineColorSet = true;
1070 m_highlightedLineColor = col;
1071
1072 configEnd();
1073}
1074
1075const QColor &KateRendererConfig::lineMarkerColor(KTextEditor::Document::MarkTypes type) const
1076{
1077 int index = 0;
1078 if (type > 0) {
1079 while ((type >> index++) ^ 1) { }
1080 }
1081 index -= 1;
1082
1083 if (index < 0 || index >= KTextEditor::Document::reservedMarkersCount()) {
1084 static QColor dummy;
1085 return dummy;
1086 }
1087
1088 if (m_lineMarkerColorSet[index] || isGlobal()) {
1089 return m_lineMarkerColor[index];
1090 }
1091
1092 return s_global->lineMarkerColor(type);
1093}
1094
1095const QColor &KateRendererConfig::highlightedBracketColor() const
1096{
1097 if (m_highlightedBracketColorSet || isGlobal()) {
1098 return m_highlightedBracketColor;
1099 }
1100
1101 return s_global->highlightedBracketColor();
1102}
1103
1104void KateRendererConfig::setHighlightedBracketColor(const QColor &col)
1105{
1106 if (m_highlightedBracketColorSet && m_highlightedBracketColor == col) {
1107 return;
1108 }
1109
1110 configStart();
1111
1112 m_highlightedBracketColorSet = true;
1113 m_highlightedBracketColor = col;
1114
1115 configEnd();
1116}
1117
1118const QColor &KateRendererConfig::wordWrapMarkerColor() const
1119{
1120 if (m_wordWrapMarkerColorSet || isGlobal()) {
1121 return m_wordWrapMarkerColor;
1122 }
1123
1124 return s_global->wordWrapMarkerColor();
1125}
1126
1127void KateRendererConfig::setWordWrapMarkerColor(const QColor &col)
1128{
1129 if (m_wordWrapMarkerColorSet && m_wordWrapMarkerColor == col) {
1130 return;
1131 }
1132
1133 configStart();
1134
1135 m_wordWrapMarkerColorSet = true;
1136 m_wordWrapMarkerColor = col;
1137
1138 configEnd();
1139}
1140
1141const QColor &KateRendererConfig::tabMarkerColor() const
1142{
1143 if (m_tabMarkerColorSet || isGlobal()) {
1144 return m_tabMarkerColor;
1145 }
1146
1147 return s_global->tabMarkerColor();
1148}
1149
1150void KateRendererConfig::setTabMarkerColor(const QColor &col)
1151{
1152 if (m_tabMarkerColorSet && m_tabMarkerColor == col) {
1153 return;
1154 }
1155
1156 configStart();
1157
1158 m_tabMarkerColorSet = true;
1159 m_tabMarkerColor = col;
1160
1161 configEnd();
1162}
1163
1164const QColor &KateRendererConfig::indentationLineColor() const
1165{
1166 if (m_indentationLineColorSet || isGlobal()) {
1167 return m_indentationLineColor;
1168 }
1169
1170 return s_global->indentationLineColor();
1171}
1172
1173void KateRendererConfig::setIndentationLineColor(const QColor &col)
1174{
1175 if (m_indentationLineColorSet && m_indentationLineColor == col) {
1176 return;
1177 }
1178
1179 configStart();
1180
1181 m_indentationLineColorSet = true;
1182 m_indentationLineColor = col;
1183
1184 configEnd();
1185}
1186
1187const QColor &KateRendererConfig::iconBarColor() const
1188{
1189 if (m_iconBarColorSet || isGlobal()) {
1190 return m_iconBarColor;
1191 }
1192
1193 return s_global->iconBarColor();
1194}
1195
1196void KateRendererConfig::setIconBarColor(const QColor &col)
1197{
1198 if (m_iconBarColorSet && m_iconBarColor == col) {
1199 return;
1200 }
1201
1202 configStart();
1203
1204 m_iconBarColorSet = true;
1205 m_iconBarColor = col;
1206
1207 configEnd();
1208}
1209
1210const QColor &KateRendererConfig::foldingColor() const
1211{
1212 if (m_foldingColorSet || isGlobal()) {
1213 return m_foldingColor;
1214 }
1215
1216 return s_global->foldingColor();
1217}
1218
1219void KateRendererConfig::setFoldingColor(const QColor &col)
1220{
1221 if (m_foldingColorSet && m_foldingColor == col) {
1222 return;
1223 }
1224
1225 configStart();
1226
1227 m_foldingColorSet = true;
1228 m_foldingColor = col;
1229
1230 configEnd();
1231}
1232
1233const QColor &KateRendererConfig::templateBackgroundColor() const
1234{
1235 if (m_templateColorsSet || isGlobal()) {
1236 return m_templateBackgroundColor;
1237 }
1238
1239 return s_global->templateBackgroundColor();
1240}
1241
1242const QColor &KateRendererConfig::templateEditablePlaceholderColor() const
1243{
1244 if (m_templateColorsSet || isGlobal()) {
1245 return m_templateEditablePlaceholderColor;
1246 }
1247
1248 return s_global->templateEditablePlaceholderColor();
1249}
1250
1251const QColor &KateRendererConfig::templateFocusedEditablePlaceholderColor() const
1252{
1253 if (m_templateColorsSet || isGlobal()) {
1254 return m_templateFocusedEditablePlaceholderColor;
1255 }
1256
1257 return s_global->templateFocusedEditablePlaceholderColor();
1258}
1259
1260const QColor &KateRendererConfig::templateNotEditablePlaceholderColor() const
1261{
1262 if (m_templateColorsSet || isGlobal()) {
1263 return m_templateNotEditablePlaceholderColor;
1264 }
1265
1266 return s_global->templateNotEditablePlaceholderColor();
1267}
1268
1269const QColor &KateRendererConfig::lineNumberColor() const
1270{
1271 if (m_lineNumberColorSet || isGlobal()) {
1272 return m_lineNumberColor;
1273 }
1274
1275 return s_global->lineNumberColor();
1276}
1277
1278void KateRendererConfig::setLineNumberColor(const QColor &col)
1279{
1280 if (m_lineNumberColorSet && m_lineNumberColor == col) {
1281 return;
1282 }
1283
1284 configStart();
1285
1286 m_lineNumberColorSet = true;
1287 m_lineNumberColor = col;
1288
1289 configEnd();
1290}
1291
1292const QColor &KateRendererConfig::currentLineNumberColor() const
1293{
1294 if (m_currentLineNumberColorSet || isGlobal()) {
1295 return m_currentLineNumberColor;
1296 }
1297
1298 return s_global->currentLineNumberColor();
1299}
1300
1301void KateRendererConfig::setCurrentLineNumberColor(const QColor &col)
1302{
1303 if (m_currentLineNumberColorSet && m_currentLineNumberColor == col) {
1304 return;
1305 }
1306
1307 configStart();
1308
1309 m_currentLineNumberColorSet = true;
1310 m_currentLineNumberColor = col;
1311
1312 configEnd();
1313}
1314
1315const QColor &KateRendererConfig::separatorColor() const
1316{
1317 if (m_separatorColorSet || isGlobal()) {
1318 return m_separatorColor;
1319 }
1320
1321 return s_global->separatorColor();
1322}
1323
1324void KateRendererConfig::setSeparatorColor(const QColor &col)
1325{
1326 if (m_separatorColorSet && m_separatorColor == col) {
1327 return;
1328 }
1329
1330 configStart();
1331
1332 m_separatorColorSet = true;
1333 m_separatorColor = col;
1334
1335 configEnd();
1336}
1337
1338const QColor &KateRendererConfig::spellingMistakeLineColor() const
1339{
1340 if (m_spellingMistakeLineColorSet || isGlobal()) {
1341 return m_spellingMistakeLineColor;
1342 }
1343
1344 return s_global->spellingMistakeLineColor();
1345}
1346
1347void KateRendererConfig::setSpellingMistakeLineColor(const QColor &col)
1348{
1349 if (m_spellingMistakeLineColorSet && m_spellingMistakeLineColor == col) {
1350 return;
1351 }
1352
1353 configStart();
1354
1355 m_spellingMistakeLineColorSet = true;
1356 m_spellingMistakeLineColor = col;
1357
1358 configEnd();
1359}
1360
1361const QColor &KateRendererConfig::modifiedLineColor() const
1362{
1363 if (m_modifiedLineColorSet || isGlobal()) {
1364 return m_modifiedLineColor;
1365 }
1366
1367 return s_global->modifiedLineColor();
1368}
1369
1370void KateRendererConfig::setModifiedLineColor(const QColor &col)
1371{
1372 if (m_modifiedLineColorSet && m_modifiedLineColor == col) {
1373 return;
1374 }
1375
1376 configStart();
1377
1378 m_modifiedLineColorSet = true;
1379 m_modifiedLineColor = col;
1380
1381 configEnd();
1382}
1383
1384const QColor &KateRendererConfig::savedLineColor() const
1385{
1386 if (m_savedLineColorSet || isGlobal()) {
1387 return m_savedLineColor;
1388 }
1389
1390 return s_global->savedLineColor();
1391}
1392
1393void KateRendererConfig::setSavedLineColor(const QColor &col)
1394{
1395 if (m_savedLineColorSet && m_savedLineColor == col) {
1396 return;
1397 }
1398
1399 configStart();
1400
1401 m_savedLineColorSet = true;
1402 m_savedLineColor = col;
1403
1404 configEnd();
1405}
1406
1407const QColor &KateRendererConfig::searchHighlightColor() const
1408{
1409 if (m_searchHighlightColorSet || isGlobal()) {
1410 return m_searchHighlightColor;
1411 }
1412
1413 return s_global->searchHighlightColor();
1414}
1415
1416void KateRendererConfig::setSearchHighlightColor(const QColor &col)
1417{
1418 if (m_searchHighlightColorSet && m_searchHighlightColor == col) {
1419 return;
1420 }
1421
1422 configStart();
1423
1424 m_searchHighlightColorSet = true;
1425 m_searchHighlightColor = col;
1426
1427 configEnd();
1428}
1429
1430const QColor &KateRendererConfig::replaceHighlightColor() const
1431{
1432 if (m_replaceHighlightColorSet || isGlobal()) {
1433 return m_replaceHighlightColor;
1434 }
1435
1436 return s_global->replaceHighlightColor();
1437}
1438
1439void KateRendererConfig::setReplaceHighlightColor(const QColor &col)
1440{
1441 if (m_replaceHighlightColorSet && m_replaceHighlightColor == col) {
1442 return;
1443 }
1444
1445 configStart();
1446
1447 m_replaceHighlightColorSet = true;
1448 m_replaceHighlightColor = col;
1449
1450 configEnd();
1451}
1452
1453void KateRendererConfig::setLineHeightMultiplier(qreal value)
1454{
1455 configStart();
1456 m_lineHeightMultiplier = value;
1457 configEnd();
1458}
1459
1460bool KateRendererConfig::showIndentationLines() const
1461{
1462 if (m_showIndentationLinesSet || isGlobal()) {
1463 return m_showIndentationLines;
1464 }
1465
1466 return s_global->showIndentationLines();
1467}
1468
1469void KateRendererConfig::setShowIndentationLines(bool on)
1470{
1471 if (m_showIndentationLinesSet && m_showIndentationLines == on) {
1472 return;
1473 }
1474
1475 configStart();
1476
1477 m_showIndentationLinesSet = true;
1478 m_showIndentationLines = on;
1479
1480 configEnd();
1481}
1482
1483bool KateRendererConfig::showWholeBracketExpression() const
1484{
1485 if (m_showWholeBracketExpressionSet || isGlobal()) {
1486 return m_showWholeBracketExpression;
1487 }
1488
1489 return s_global->showWholeBracketExpression();
1490}
1491
1492void KateRendererConfig::setShowWholeBracketExpression(bool on)
1493{
1494 if (m_showWholeBracketExpressionSet && m_showWholeBracketExpression == on) {
1495 return;
1496 }
1497
1498 configStart();
1499
1500 m_showWholeBracketExpressionSet = true;
1501 m_showWholeBracketExpression = on;
1502
1503 configEnd();
1504}
1505
1506bool KateRendererConfig::animateBracketMatching()
1507{
1508 return s_global->m_animateBracketMatching;
1509}
1510
1511void KateRendererConfig::setAnimateBracketMatching(bool on)
1512{
1513 if (!isGlobal()) {
1514 s_global->setAnimateBracketMatching(on);
1515 } else if (on != m_animateBracketMatching) {
1516 configStart();
1517 m_animateBracketMatching = on;
1518 configEnd();
1519 }
1520}
1521
1522// END
void deleteEntry(const char *key, WriteConfigFlags pFlags=Normal)
void writeEntry(const char *key, const char *value, WriteConfigFlags pFlags=Normal)
QString readEntry(const char *key, const char *aDefault=nullptr) const
Theme themeForPalette(const QPalette &palette) const
Q_INVOKABLE KSyntaxHighlighting::Theme theme(const QString &themeName) const
Backend of KTextEditor::Document related public KTextEditor interfaces.
MarkTypes
Predefined mark types.
Definition document.h:1557
@ markType01
Bookmark.
Definition document.h:1559
static int reservedMarkersCount()
Get the number of predefined mark types we have so far.
Definition document.h:1546
static KSharedConfigPtr config()
The global configuration of katepart, e.g.
void triggerConfigChanged()
Trigger delayed emission of config changed.
static KTextEditor::EditorPrivate * self()
Kate Part Internal stuff ;)
QList< KTextEditor::Document * > documents() override
Returns a list of all documents of this editor.
Definition kateglobal.h:99
One config entry.
Definition kateconfig.h:140
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
KateConfig(const KateConfig *parent=nullptr)
Construct a KateConfig.
virtual ~KateConfig()
Virtual Destructor.
int configSessionNumber
recursion depth
Definition kateconfig.h:272
void writeConfigEntries(KConfigGroup &config) const
Write all config entries to given config group.
void configEnd()
End a config change transaction, update the concerned KateDocumentConfig/KateDocumentConfig/KateDocum...
void readConfigEntries(const KConfigGroup &config)
Read all config entries from given config group.
void finalizeConfigEntries()
Finalize the config entries.
void configStart()
Start some config changes.
bool setValue(const int key, const QVariant &value)
Set a config value.
QVariant value(const int key) const
Get a config value.
virtual void updateConfig()=0
do the real update
void addConfigEntry(ConfigEntry &&entry)
Register a new config entry.
Handles all of the work of rendering the text (used for the views and printing)
QString identify(const QString &text, const QStringList &suggestions=QStringList()) const
void setLanguage(const QString &lang)
KIOCORE_EXPORT QString number(KIO::filesize_t size)
QString name(const QVariant &location)
bool isValid(QStringView ifopt)
std::vector< Feature > features(QStringView coachNumber, QStringView coachClassification)
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
const char * constData() const const
QColor fromRgba(QRgb rgba)
QFont systemFont(SystemFont type)
QString fromUtf8(QByteArrayView str)
QString number(double n, char format, int precision)
int toInt(bool *ok, int base) const const
QByteArray toUtf8() const const
bool isValid() const const
const char * nameForEncoding(Encoding e)
AltModifier
SkipEmptyParts
int toInt(bool *ok) const const
uint toUInt(bool *ok) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 21 2025 11:52:52 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.