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 speller.isMisspelled(QStringLiteral("dummy to trigger dictionary load"));
409 Sonnet::GuessLanguage languageGuesser;
410 languageGuesser.identify(QStringLiteral("dummy to trigger identify"));
411 }
412 }
413
414 // backwards compatibility mappings
415 // convert stuff, old entries deleted in writeConfig
416 if (const int backupFlags = config.readEntry("Backup Flags", 0)) {
417 setBackupOnSaveLocal(backupFlags & 0x1);
418 setBackupOnSaveRemote(backupFlags & 0x2);
419 }
420
421 // end config update group, might trigger updateConfig()
422 configEnd();
423}
424
425void KateDocumentConfig::writeConfig(KConfigGroup &config)
426{
427 // write generic entries
428 writeConfigEntries(config);
429
430 // backwards compatibility mappings
431 // here we remove old entries we converted on readConfig
432 config.deleteEntry("Backup Flags");
433}
434
435void KateDocumentConfig::updateConfig()
436{
437 if (m_doc) {
438 m_doc->updateConfig();
439 return;
440 }
441
442 if (isGlobal()) {
443 const auto docs = KTextEditor::EditorPrivate::self()->documents();
444 for (auto doc : docs) {
445 static_cast<KTextEditor::DocumentPrivate *>(doc)->updateConfig();
446 }
447
448 // write config
449 KConfigGroup cg(KTextEditor::EditorPrivate::config(), QStringLiteral("KTextEditor Document"));
450 writeConfig(cg);
452
453 // trigger emission of KTextEditor::Editor::configChanged
455 }
456}
457
458QString KateDocumentConfig::eolString() const
459{
460 switch (eol()) {
461 case KateDocumentConfig::eolDos:
462 return QStringLiteral("\r\n");
463
464 case KateDocumentConfig::eolMac:
465 return QStringLiteral("\r");
466
467 default:
468 return QStringLiteral("\n");
469 }
470}
471// END
472
473// BEGIN KateViewConfig
474KateViewConfig::KateViewConfig()
475{
476 // register this as our global instance
477 Q_ASSERT(isGlobal());
478 s_global = this;
479
480 // avoid updateConfig effects like config write in constructor, see bug 377067
481 Q_ASSERT(configSessionNumber == 0);
483
484 // Init all known config entries
485 // NOTE: Ensure to keep the same order as listed in enum ConfigEntryTypes or it will later assert!
486 // addConfigEntry(ConfigEntry(<EnumKey>, <ConfigKey>, <CommandName>, <DefaultValue>, [<ValidatorFunction>]))
487 addConfigEntry(ConfigEntry(AllowMarkMenu, "Allow Mark Menu", QStringLiteral("allow-mark-menu"), true));
488 addConfigEntry(ConfigEntry(AutoBrackets, "Auto Brackets", QStringLiteral("auto-brackets"), true));
489 addConfigEntry(ConfigEntry(AutoCenterLines, "Auto Center Lines", QStringLiteral("auto-center-lines"), 0));
490 addConfigEntry(ConfigEntry(AutomaticCompletionInvocation, "Auto Completion", QString(), true));
491 addConfigEntry(ConfigEntry(AutomaticCompletionPreselectFirst, "Auto Completion Preselect First Entry", QString(), true));
492 addConfigEntry(ConfigEntry(BackspaceRemoveComposedCharacters, "Backspace Remove Composed Characters", QString(), false));
493 addConfigEntry(ConfigEntry(BookmarkSorting, "Bookmark Menu Sorting", QString(), 0));
494 addConfigEntry(ConfigEntry(CharsToEncloseSelection, "Chars To Enclose Selection", QStringLiteral("enclose-selection"), QStringLiteral("<>(){}[]'\"")));
495 addConfigEntry(ConfigEntry(ClipboardHistoryEntries, "Max Clipboard History Entries", QString(), 20, [](const QVariant &value) {
496 return inBounds(1, value, 999);
497 }));
499 ConfigEntry(DefaultMarkType, "Default Mark Type", QStringLiteral("default-mark-type"), KTextEditor::Document::markType01, [](const QVariant &value) {
500 return isPositive(value);
501 }));
502 addConfigEntry(ConfigEntry(DynWordWrapAlignIndent, "Dynamic Word Wrap Align Indent", QString(), 80, [](const QVariant &value) {
503 return inBounds(0, value, 100);
504 }));
505 addConfigEntry(ConfigEntry(DynWordWrapIndicators, "Dynamic Word Wrap Indicators", QString(), 1, [](const QVariant &value) {
506 return inBounds(0, value, 2);
507 }));
508 addConfigEntry(ConfigEntry(DynWrapAnywhere, "Dynamic Wrap not at word boundaries", QStringLiteral("dynamic-word-wrap-anywhere"), false));
509 addConfigEntry(ConfigEntry(DynWrapAtStaticMarker, "Dynamic Word Wrap At Static Marker", QString(), false));
510 addConfigEntry(ConfigEntry(DynamicWordWrap, "Dynamic Word Wrap", QStringLiteral("dynamic-word-wrap"), true));
511 addConfigEntry(ConfigEntry(EnterToInsertCompletion, "Enter To Insert Completion", QStringLiteral("enter-to-insert-completion"), true));
512 addConfigEntry(ConfigEntry(FoldFirstLine, "Fold First Line", QString(), false));
513 addConfigEntry(ConfigEntry(InputMode, "Input Mode", QString(), 0, [](const QVariant &value) {
514 return isPositive(value);
515 }));
516 addConfigEntry(ConfigEntry(KeywordCompletion, "Keyword Completion", QStringLiteral("keyword-completion"), true));
517 addConfigEntry(ConfigEntry(MaxHistorySize, "Maximum Search History Size", QString(), 100, [](const QVariant &value) {
518 return inBounds(0, value, 999);
519 }));
520 addConfigEntry(ConfigEntry(MousePasteAtCursorPosition, "Mouse Paste At Cursor Position", QString(), false));
521 addConfigEntry(ConfigEntry(PersistentSelection, "Persistent Selection", QStringLiteral("persistent-selectionq"), false));
522 addConfigEntry(ConfigEntry(ScrollBarMiniMapWidth, "Scroll Bar Mini Map Width", QString(), 60, [](const QVariant &value) {
523 return inBounds(0, value, 999);
524 }));
525 addConfigEntry(ConfigEntry(ScrollPastEnd, "Scroll Past End", QString(), false));
526 addConfigEntry(ConfigEntry(SearchFlags, "Search/Replace Flags", QString(), IncFromCursor | PowerMatchCase | PowerModePlainText));
527 addConfigEntry(ConfigEntry(TabCompletion, "Enable Tab completion", QString(), false));
528 addConfigEntry(ConfigEntry(ShowBracketMatchPreview, "Bracket Match Preview", QStringLiteral("bracket-match-preview"), false));
529 addConfigEntry(ConfigEntry(ShowFoldingBar, "Folding Bar", QStringLiteral("folding-bar"), true));
530 addConfigEntry(ConfigEntry(ShowFoldingPreview, "Folding Preview", QStringLiteral("folding-preview"), true));
531 addConfigEntry(ConfigEntry(ShowIconBar, "Icon Bar", QStringLiteral("icon-bar"), false));
532 addConfigEntry(ConfigEntry(ShowLineCount, "Show Line Count", QString(), false));
533 addConfigEntry(ConfigEntry(ShowLineModification, "Line Modification", QStringLiteral("modification-markers"), true));
534 addConfigEntry(ConfigEntry(ShowLineNumbers, "Line Numbers", QStringLiteral("line-numbers"), true));
535 addConfigEntry(ConfigEntry(ShowScrollBarMarks, "Scroll Bar Marks", QString(), false));
536 addConfigEntry(ConfigEntry(ShowScrollBarMiniMap, "Scroll Bar MiniMap", QStringLiteral("scrollbar-minimap"), true));
537 addConfigEntry(ConfigEntry(ShowScrollBarMiniMapAll, "Scroll Bar Mini Map All", QString(), true));
538 addConfigEntry(ConfigEntry(ShowScrollBarPreview, "Scroll Bar Preview", QStringLiteral("scrollbar-preview"), true));
539 addConfigEntry(ConfigEntry(ShowScrollbars, "Show Scrollbars", QString(), AlwaysOn, [](const QVariant &value) {
540 return inBounds(0, value, 2);
541 }));
542 addConfigEntry(ConfigEntry(ShowWordCount, "Show Word Count", QString(), false));
543 addConfigEntry(ConfigEntry(TextDragAndDrop, "Text Drag And Drop", QString(), true));
544 addConfigEntry(ConfigEntry(SmartCopyCut, "Smart Copy Cut", QString(), true));
545 addConfigEntry(ConfigEntry(UserSetsOfCharsToEncloseSelection, "User Sets Of Chars To Enclose Selection", QString(), QStringList()));
546 addConfigEntry(ConfigEntry(ViInputModeStealKeys, "Vi Input Mode Steal Keys", QString(), false));
547 addConfigEntry(ConfigEntry(ViRelativeLineNumbers, "Vi Relative Line Numbers", QString(), false));
548 addConfigEntry(ConfigEntry(WordCompletion, "Word Completion", QString(), true));
549 addConfigEntry(ConfigEntry(WordCompletionMinimalWordLength,
550 "Word Completion Minimal Word Length",
551 QStringLiteral("word-completion-minimal-word-length"),
552 3,
553 [](const QVariant &value) {
554 return inBounds(0, value, 99);
555 }));
556 addConfigEntry(ConfigEntry(WordCompletionRemoveTail, "Word Completion Remove Tail", QString(), true));
557 addConfigEntry(ConfigEntry(ShowDocWithCompletion, "Show Documentation With Completion", QString(), true));
558 addConfigEntry(ConfigEntry(MultiCursorModifier, "Multiple Cursor Modifier", QString(), (int)Qt::AltModifier));
559 addConfigEntry(ConfigEntry(ShowFoldingOnHoverOnly, "Show Folding Icons On Hover Only", QString(), true));
560
561 // Statusbar stuff
562 addConfigEntry(ConfigEntry(ShowStatusbarLineColumn, "Show Statusbar Line Column", QString(), true));
563 addConfigEntry(ConfigEntry(ShowStatusbarDictionary, "Show Statusbar Dictionary", QString(), true));
564 addConfigEntry(ConfigEntry(ShowStatusbarInputMode, "Show Statusbar Input Mode", QString(), true));
565 addConfigEntry(ConfigEntry(ShowStatusbarHighlightingMode, "Show Statusbar Highlighting Mode", QString(), true));
566 addConfigEntry(ConfigEntry(ShowStatusbarTabSettings, "Show Statusbar Tab Settings", QString(), true));
567 addConfigEntry(ConfigEntry(ShowStatusbarFileEncoding, "Show File Encoding", QString(), true));
568 addConfigEntry(ConfigEntry(StatusbarLineColumnCompact, "Statusbar Line Column Compact Mode", QString(), true));
569 addConfigEntry(ConfigEntry(ShowStatusbarEOL, "Shoe Line Ending Type in Statusbar", QString(), false));
570 addConfigEntry(ConfigEntry(EnableAccessibility, "Enable Accessibility", QString(), true));
571 addConfigEntry(ConfigEntry(CycleThroughBookmarks, "Cycle Through Bookmarks", QString(), true));
572
573 // Never forget to finalize or the <CommandName> becomes not available
575
576 // init with defaults from config or really hardcoded ones
577 KConfigGroup config(KTextEditor::EditorPrivate::config(), QStringLiteral("KTextEditor View"));
578 readConfig(config);
579
580 // avoid updateConfig effects like config write in constructor, see bug 377067
581 Q_ASSERT(configSessionNumber == 1);
583}
584
585KateViewConfig::KateViewConfig(KTextEditor::ViewPrivate *view)
586 : KateConfig(s_global)
587 , m_view(view)
588{
589}
590
591KateViewConfig::~KateViewConfig() = default;
592
593void KateViewConfig::readConfig(const KConfigGroup &config)
594{
595 configStart();
596
597 // read generic entries
598 readConfigEntries(config);
599
600 configEnd();
601}
602
603void KateViewConfig::writeConfig(KConfigGroup &config)
604{
605 // write generic entries
606 writeConfigEntries(config);
607}
608
609void KateViewConfig::updateConfig()
610{
611 if (m_view) {
612 m_view->updateConfig();
613 return;
614 }
615
616 if (isGlobal()) {
617 for (KTextEditor::ViewPrivate *view : KTextEditor::EditorPrivate::self()->views()) {
618 view->updateConfig();
619 }
620
621 // write config
622 KConfigGroup cg(KTextEditor::EditorPrivate::config(), QStringLiteral("KTextEditor View"));
623 writeConfig(cg);
625
626 // trigger emission of KTextEditor::Editor::configChanged
628 }
629}
630// END
631
632// BEGIN KateRendererConfig
633KateRendererConfig::KateRendererConfig()
634 : m_lineMarkerColor(KTextEditor::Document::reservedMarkersCount())
635 , m_schemaSet(false)
636 , m_fontSet(false)
637 , m_wordWrapMarkerSet(false)
638 , m_showIndentationLinesSet(false)
639 , m_showWholeBracketExpressionSet(false)
640 , m_backgroundColorSet(false)
641 , m_selectionColorSet(false)
642 , m_highlightedLineColorSet(false)
643 , m_highlightedBracketColorSet(false)
644 , m_wordWrapMarkerColorSet(false)
645 , m_tabMarkerColorSet(false)
646 , m_indentationLineColorSet(false)
647 , m_iconBarColorSet(false)
648 , m_foldingColorSet(false)
649 , m_lineNumberColorSet(false)
650 , m_currentLineNumberColorSet(false)
651 , m_separatorColorSet(false)
652 , m_spellingMistakeLineColorSet(false)
653 , m_templateColorsSet(false)
654 , m_modifiedLineColorSet(false)
655 , m_savedLineColorSet(false)
656 , m_searchHighlightColorSet(false)
657 , m_replaceHighlightColorSet(false)
658 , m_lineMarkerColorSet(m_lineMarkerColor.size())
659
660{
661 // init bitarray
662 m_lineMarkerColorSet.fill(true);
663
664 // register this as our global instance
665 Q_ASSERT(isGlobal());
666 s_global = this;
667
668 // avoid updateConfig effects like config write in constructor, see bug 377067
669 Q_ASSERT(configSessionNumber == 0);
671
672 // Init all known config entries
673 addConfigEntry(ConfigEntry(AutoColorThemeSelection, "Auto Color Theme Selection", QString(), true));
674
675 // Never forget to finalize or the <CommandName> becomes not available
677
678 // init with defaults from config or really hardcoded ones
679 KConfigGroup config(KTextEditor::EditorPrivate::config(), QStringLiteral("KTextEditor Renderer"));
680 readConfig(config);
681
682 // avoid updateConfig effects like config write in constructor, see bug 377067
683 Q_ASSERT(configSessionNumber == 1);
685}
686
687KateRendererConfig::KateRendererConfig(KateRenderer *renderer)
688 : KateConfig(s_global)
689 , m_lineMarkerColor(KTextEditor::Document::reservedMarkersCount())
690 , m_schemaSet(false)
691 , m_fontSet(false)
692 , m_wordWrapMarkerSet(false)
693 , m_showIndentationLinesSet(false)
694 , m_showWholeBracketExpressionSet(false)
695 , m_backgroundColorSet(false)
696 , m_selectionColorSet(false)
697 , m_highlightedLineColorSet(false)
698 , m_highlightedBracketColorSet(false)
699 , m_wordWrapMarkerColorSet(false)
700 , m_tabMarkerColorSet(false)
701 , m_indentationLineColorSet(false)
702 , m_iconBarColorSet(false)
703 , m_foldingColorSet(false)
704 , m_lineNumberColorSet(false)
705 , m_currentLineNumberColorSet(false)
706 , m_separatorColorSet(false)
707 , m_spellingMistakeLineColorSet(false)
708 , m_templateColorsSet(false)
709 , m_modifiedLineColorSet(false)
710 , m_savedLineColorSet(false)
711 , m_searchHighlightColorSet(false)
712 , m_replaceHighlightColorSet(false)
713 , m_lineMarkerColorSet(m_lineMarkerColor.size())
714 , m_renderer(renderer)
715{
716 // init bitarray
717 m_lineMarkerColorSet.fill(false);
718}
719
720KateRendererConfig::~KateRendererConfig() = default;
721
722namespace
723{
724const char KEY_FONT[] = "Text Font";
725const char KEY_FONT_FEATURES[] = "Text Font Features";
726const char KEY_COLOR_THEME[] = "Color Theme";
727const char KEY_WORD_WRAP_MARKER[] = "Word Wrap Marker";
728const char KEY_SHOW_INDENTATION_LINES[] = "Show Indentation Lines";
729const char KEY_SHOW_WHOLE_BRACKET_EXPRESSION[] = "Show Whole Bracket Expression";
730const char KEY_ANIMATE_BRACKET_MATCHING[] = "Animate Bracket Matching";
731const char KEY_LINE_HEIGHT_MULTIPLIER[] = "Line Height Multiplier";
732}
733
734void KateRendererConfig::readConfig(const KConfigGroup &config)
735{
736 configStart();
737
738 // read generic entries
739 readConfigEntries(config);
740
741 // read font, including font features
742 auto font = config.readEntry(KEY_FONT, QFontDatabase::systemFont(QFontDatabase::FixedFont));
743#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
744 const QStringList rawFeaturesList = config.readEntry(KEY_FONT_FEATURES, QStringList());
745 for (const QString &feature : rawFeaturesList) {
746 const auto parts = feature.split(QStringLiteral("="), Qt::SkipEmptyParts);
747 if (parts.length() == 2) {
748 const auto tag = QFont::Tag::fromString(parts[0]);
749 bool ok = false;
750 const int number = parts[1].toInt(&ok);
751 if (tag.has_value() && ok) {
752 font.setFeature(tag.value(), number);
753 }
754 }
755 }
756#endif
757 setFont(font);
758
759 // setSchema will default to right theme
760 setSchema(config.readEntry(KEY_COLOR_THEME, QString()));
761
762 setWordWrapMarker(config.readEntry(KEY_WORD_WRAP_MARKER, false));
763
764 setShowIndentationLines(config.readEntry(KEY_SHOW_INDENTATION_LINES, false));
765
766 setShowWholeBracketExpression(config.readEntry(KEY_SHOW_WHOLE_BRACKET_EXPRESSION, false));
767
768 setAnimateBracketMatching(config.readEntry(KEY_ANIMATE_BRACKET_MATCHING, false));
769
770 setLineHeightMultiplier(config.readEntry<qreal>(KEY_LINE_HEIGHT_MULTIPLIER, 1.0));
771
772 configEnd();
773}
774
775void KateRendererConfig::writeConfig(KConfigGroup &config)
776{
777 // write generic entries
778 writeConfigEntries(config);
779
780 // write font, including font features
781 const auto font = baseFont();
782 config.writeEntry(KEY_FONT, font);
783#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
784 const auto tags = font.featureTags();
785 QStringList features;
786 for (const auto &tag : tags) {
787 const QString name = QString::fromUtf8(tag.toString());
788 const quint32 value = font.featureValue(tag);
789 features.push_back(QStringLiteral("%1=%2").arg(name, QString::number(value)));
790 }
791 config.writeEntry(KEY_FONT_FEATURES, features);
792#endif
793
794 config.writeEntry(KEY_COLOR_THEME, schema());
795
796 config.writeEntry(KEY_WORD_WRAP_MARKER, wordWrapMarker());
797
798 config.writeEntry(KEY_SHOW_INDENTATION_LINES, showIndentationLines());
799
800 config.writeEntry(KEY_SHOW_WHOLE_BRACKET_EXPRESSION, showWholeBracketExpression());
801
802 config.writeEntry(KEY_ANIMATE_BRACKET_MATCHING, animateBracketMatching());
803
804 config.writeEntry<qreal>(KEY_LINE_HEIGHT_MULTIPLIER, lineHeightMultiplier());
805}
806
807void KateRendererConfig::updateConfig()
808{
809 if (m_renderer) {
810 m_renderer->updateConfig();
811 return;
812 }
813
814 if (isGlobal()) {
815 for (auto view : KTextEditor::EditorPrivate::self()->views()) {
816 view->renderer()->updateConfig();
817 }
818
819 // write config
820 KConfigGroup cg(KTextEditor::EditorPrivate::config(), QStringLiteral("KTextEditor Renderer"));
821 writeConfig(cg);
823
824 // trigger emission of KTextEditor::Editor::configChanged
826 }
827}
828
829const QString &KateRendererConfig::schema() const
830{
831 if (m_schemaSet || isGlobal()) {
832 return m_schema;
833 }
834
835 return s_global->schema();
836}
837
838void KateRendererConfig::setSchema(QString schema)
839{
840 // check if we have some matching theme, else fallback to best theme for current palette
841 // same behavior as for the "Automatic Color Theme Selection"
842 if (!KateHlManager::self()->repository().theme(schema).isValid()) {
843 schema = KateHlManager::self()->repository().themeForPalette(qGuiApp->palette()).name();
844 }
845
846 if (m_schemaSet && m_schema == schema) {
847 return;
848 }
849
850 configStart();
851 m_schemaSet = true;
852 m_schema = schema;
853 setSchemaInternal(m_schema);
854 configEnd();
855}
856
857void KateRendererConfig::reloadSchema()
858{
859 if (isGlobal()) {
860 setSchemaInternal(m_schema);
861 for (KTextEditor::ViewPrivate *view : KTextEditor::EditorPrivate::self()->views()) {
862 view->rendererConfig()->reloadSchema();
863 }
864 }
865
866 else if (m_renderer && m_schemaSet) {
867 setSchemaInternal(m_schema);
868 }
869
870 // trigger renderer/view update
871 if (m_renderer) {
872 m_renderer->updateConfig();
873 }
874}
875
876void KateRendererConfig::setSchemaInternal(const QString &schema)
877{
878 // we always set the theme if we arrive here!
879 m_schemaSet = true;
880
881 // for the global config, we honor the auto selection based on the palette
882 // 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!
883 if ((isGlobal() && value(AutoColorThemeSelection).toBool()) || !KateHlManager::self()->repository().theme(schema).isValid()) {
884 // always choose some theme matching the current application palette
885 // we will arrive here after palette changed signals, too!
886 m_schema = KateHlManager::self()->repository().themeForPalette(qGuiApp->palette()).name();
887 } else {
888 // take user given theme 1:1
889 m_schema = schema;
890 }
891
892 const auto theme = KateHlManager::self()->repository().theme(m_schema);
893
894 m_backgroundColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::BackgroundColor));
895 m_backgroundColorSet = true;
896
897 m_selectionColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::TextSelection));
898 m_selectionColorSet = true;
899
900 m_highlightedLineColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::CurrentLine));
901 m_highlightedLineColorSet = true;
902
903 m_highlightedBracketColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::BracketMatching));
904 m_highlightedBracketColorSet = true;
905
906 m_wordWrapMarkerColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::WordWrapMarker));
907 m_wordWrapMarkerColorSet = true;
908
909 m_tabMarkerColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::TabMarker));
910 m_tabMarkerColorSet = true;
911
912 m_indentationLineColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::IndentationLine));
913 m_indentationLineColorSet = true;
914
915 m_iconBarColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::IconBorder));
916 m_iconBarColorSet = true;
917
918 m_foldingColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::CodeFolding));
919 m_foldingColorSet = true;
920
921 m_lineNumberColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::LineNumbers));
922 m_lineNumberColorSet = true;
923
924 m_currentLineNumberColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::CurrentLineNumber));
925 m_currentLineNumberColorSet = true;
926
927 m_separatorColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::Separator));
928 m_separatorColorSet = true;
929
930 m_spellingMistakeLineColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::SpellChecking));
931 m_spellingMistakeLineColorSet = true;
932
933 m_modifiedLineColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::ModifiedLines));
934 m_modifiedLineColorSet = true;
935
936 m_savedLineColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::SavedLines));
937 m_savedLineColorSet = true;
938
939 m_searchHighlightColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::SearchHighlight));
940 m_searchHighlightColorSet = true;
941
942 m_replaceHighlightColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::ReplaceHighlight));
943 m_replaceHighlightColorSet = true;
944
946 QColor col =
948 m_lineMarkerColorSet[i] = true;
949 m_lineMarkerColor[i] = col;
950 }
951
952 m_templateBackgroundColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::TemplateBackground));
953
954 m_templateFocusedEditablePlaceholderColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::TemplateFocusedPlaceholder));
955
956 m_templateEditablePlaceholderColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::TemplatePlaceholder));
957
958 m_templateNotEditablePlaceholderColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::TemplateReadOnlyPlaceholder));
959
960 m_templateColorsSet = true;
961}
962
963const QFont &KateRendererConfig::baseFont() const
964{
965 if (m_fontSet || isGlobal()) {
966 return m_font;
967 }
968
969 return s_global->baseFont();
970}
971
972void KateRendererConfig::setFont(const QFont &font)
973{
974 if (m_fontSet && m_font == font) {
975 return;
976 }
977
978 configStart();
979 m_font = font;
980 m_fontSet = true;
981 configEnd();
982}
983
984bool KateRendererConfig::wordWrapMarker() const
985{
986 if (m_wordWrapMarkerSet || isGlobal()) {
987 return m_wordWrapMarker;
988 }
989
990 return s_global->wordWrapMarker();
991}
992
993void KateRendererConfig::setWordWrapMarker(bool on)
994{
995 if (m_wordWrapMarkerSet && m_wordWrapMarker == on) {
996 return;
997 }
998
999 configStart();
1000
1001 m_wordWrapMarkerSet = true;
1002 m_wordWrapMarker = on;
1003
1004 configEnd();
1005}
1006
1007const QColor &KateRendererConfig::backgroundColor() const
1008{
1009 if (m_backgroundColorSet || isGlobal()) {
1010 return m_backgroundColor;
1011 }
1012
1013 return s_global->backgroundColor();
1014}
1015
1016void KateRendererConfig::setBackgroundColor(const QColor &col)
1017{
1018 if (m_backgroundColorSet && m_backgroundColor == col) {
1019 return;
1020 }
1021
1022 configStart();
1023
1024 m_backgroundColorSet = true;
1025 m_backgroundColor = col;
1026
1027 configEnd();
1028}
1029
1030const QColor &KateRendererConfig::selectionColor() const
1031{
1032 if (m_selectionColorSet || isGlobal()) {
1033 return m_selectionColor;
1034 }
1035
1036 return s_global->selectionColor();
1037}
1038
1039void KateRendererConfig::setSelectionColor(const QColor &col)
1040{
1041 if (m_selectionColorSet && m_selectionColor == col) {
1042 return;
1043 }
1044
1045 configStart();
1046
1047 m_selectionColorSet = true;
1048 m_selectionColor = col;
1049
1050 configEnd();
1051}
1052
1053const QColor &KateRendererConfig::highlightedLineColor() const
1054{
1055 if (m_highlightedLineColorSet || isGlobal()) {
1056 return m_highlightedLineColor;
1057 }
1058
1059 return s_global->highlightedLineColor();
1060}
1061
1062void KateRendererConfig::setHighlightedLineColor(const QColor &col)
1063{
1064 if (m_highlightedLineColorSet && m_highlightedLineColor == col) {
1065 return;
1066 }
1067
1068 configStart();
1069
1070 m_highlightedLineColorSet = true;
1071 m_highlightedLineColor = col;
1072
1073 configEnd();
1074}
1075
1076const QColor &KateRendererConfig::lineMarkerColor(KTextEditor::Document::MarkTypes type) const
1077{
1078 int index = 0;
1079 if (type > 0) {
1080 while ((type >> index++) ^ 1) { }
1081 }
1082 index -= 1;
1083
1084 if (index < 0 || index >= KTextEditor::Document::reservedMarkersCount()) {
1085 static QColor dummy;
1086 return dummy;
1087 }
1088
1089 if (m_lineMarkerColorSet[index] || isGlobal()) {
1090 return m_lineMarkerColor[index];
1091 }
1092
1093 return s_global->lineMarkerColor(type);
1094}
1095
1096const QColor &KateRendererConfig::highlightedBracketColor() const
1097{
1098 if (m_highlightedBracketColorSet || isGlobal()) {
1099 return m_highlightedBracketColor;
1100 }
1101
1102 return s_global->highlightedBracketColor();
1103}
1104
1105void KateRendererConfig::setHighlightedBracketColor(const QColor &col)
1106{
1107 if (m_highlightedBracketColorSet && m_highlightedBracketColor == col) {
1108 return;
1109 }
1110
1111 configStart();
1112
1113 m_highlightedBracketColorSet = true;
1114 m_highlightedBracketColor = col;
1115
1116 configEnd();
1117}
1118
1119const QColor &KateRendererConfig::wordWrapMarkerColor() const
1120{
1121 if (m_wordWrapMarkerColorSet || isGlobal()) {
1122 return m_wordWrapMarkerColor;
1123 }
1124
1125 return s_global->wordWrapMarkerColor();
1126}
1127
1128void KateRendererConfig::setWordWrapMarkerColor(const QColor &col)
1129{
1130 if (m_wordWrapMarkerColorSet && m_wordWrapMarkerColor == col) {
1131 return;
1132 }
1133
1134 configStart();
1135
1136 m_wordWrapMarkerColorSet = true;
1137 m_wordWrapMarkerColor = col;
1138
1139 configEnd();
1140}
1141
1142const QColor &KateRendererConfig::tabMarkerColor() const
1143{
1144 if (m_tabMarkerColorSet || isGlobal()) {
1145 return m_tabMarkerColor;
1146 }
1147
1148 return s_global->tabMarkerColor();
1149}
1150
1151void KateRendererConfig::setTabMarkerColor(const QColor &col)
1152{
1153 if (m_tabMarkerColorSet && m_tabMarkerColor == col) {
1154 return;
1155 }
1156
1157 configStart();
1158
1159 m_tabMarkerColorSet = true;
1160 m_tabMarkerColor = col;
1161
1162 configEnd();
1163}
1164
1165const QColor &KateRendererConfig::indentationLineColor() const
1166{
1167 if (m_indentationLineColorSet || isGlobal()) {
1168 return m_indentationLineColor;
1169 }
1170
1171 return s_global->indentationLineColor();
1172}
1173
1174void KateRendererConfig::setIndentationLineColor(const QColor &col)
1175{
1176 if (m_indentationLineColorSet && m_indentationLineColor == col) {
1177 return;
1178 }
1179
1180 configStart();
1181
1182 m_indentationLineColorSet = true;
1183 m_indentationLineColor = col;
1184
1185 configEnd();
1186}
1187
1188const QColor &KateRendererConfig::iconBarColor() const
1189{
1190 if (m_iconBarColorSet || isGlobal()) {
1191 return m_iconBarColor;
1192 }
1193
1194 return s_global->iconBarColor();
1195}
1196
1197void KateRendererConfig::setIconBarColor(const QColor &col)
1198{
1199 if (m_iconBarColorSet && m_iconBarColor == col) {
1200 return;
1201 }
1202
1203 configStart();
1204
1205 m_iconBarColorSet = true;
1206 m_iconBarColor = col;
1207
1208 configEnd();
1209}
1210
1211const QColor &KateRendererConfig::foldingColor() const
1212{
1213 if (m_foldingColorSet || isGlobal()) {
1214 return m_foldingColor;
1215 }
1216
1217 return s_global->foldingColor();
1218}
1219
1220void KateRendererConfig::setFoldingColor(const QColor &col)
1221{
1222 if (m_foldingColorSet && m_foldingColor == col) {
1223 return;
1224 }
1225
1226 configStart();
1227
1228 m_foldingColorSet = true;
1229 m_foldingColor = col;
1230
1231 configEnd();
1232}
1233
1234const QColor &KateRendererConfig::templateBackgroundColor() const
1235{
1236 if (m_templateColorsSet || isGlobal()) {
1237 return m_templateBackgroundColor;
1238 }
1239
1240 return s_global->templateBackgroundColor();
1241}
1242
1243const QColor &KateRendererConfig::templateEditablePlaceholderColor() const
1244{
1245 if (m_templateColorsSet || isGlobal()) {
1246 return m_templateEditablePlaceholderColor;
1247 }
1248
1249 return s_global->templateEditablePlaceholderColor();
1250}
1251
1252const QColor &KateRendererConfig::templateFocusedEditablePlaceholderColor() const
1253{
1254 if (m_templateColorsSet || isGlobal()) {
1255 return m_templateFocusedEditablePlaceholderColor;
1256 }
1257
1258 return s_global->templateFocusedEditablePlaceholderColor();
1259}
1260
1261const QColor &KateRendererConfig::templateNotEditablePlaceholderColor() const
1262{
1263 if (m_templateColorsSet || isGlobal()) {
1264 return m_templateNotEditablePlaceholderColor;
1265 }
1266
1267 return s_global->templateNotEditablePlaceholderColor();
1268}
1269
1270const QColor &KateRendererConfig::lineNumberColor() const
1271{
1272 if (m_lineNumberColorSet || isGlobal()) {
1273 return m_lineNumberColor;
1274 }
1275
1276 return s_global->lineNumberColor();
1277}
1278
1279void KateRendererConfig::setLineNumberColor(const QColor &col)
1280{
1281 if (m_lineNumberColorSet && m_lineNumberColor == col) {
1282 return;
1283 }
1284
1285 configStart();
1286
1287 m_lineNumberColorSet = true;
1288 m_lineNumberColor = col;
1289
1290 configEnd();
1291}
1292
1293const QColor &KateRendererConfig::currentLineNumberColor() const
1294{
1295 if (m_currentLineNumberColorSet || isGlobal()) {
1296 return m_currentLineNumberColor;
1297 }
1298
1299 return s_global->currentLineNumberColor();
1300}
1301
1302void KateRendererConfig::setCurrentLineNumberColor(const QColor &col)
1303{
1304 if (m_currentLineNumberColorSet && m_currentLineNumberColor == col) {
1305 return;
1306 }
1307
1308 configStart();
1309
1310 m_currentLineNumberColorSet = true;
1311 m_currentLineNumberColor = col;
1312
1313 configEnd();
1314}
1315
1316const QColor &KateRendererConfig::separatorColor() const
1317{
1318 if (m_separatorColorSet || isGlobal()) {
1319 return m_separatorColor;
1320 }
1321
1322 return s_global->separatorColor();
1323}
1324
1325void KateRendererConfig::setSeparatorColor(const QColor &col)
1326{
1327 if (m_separatorColorSet && m_separatorColor == col) {
1328 return;
1329 }
1330
1331 configStart();
1332
1333 m_separatorColorSet = true;
1334 m_separatorColor = col;
1335
1336 configEnd();
1337}
1338
1339const QColor &KateRendererConfig::spellingMistakeLineColor() const
1340{
1341 if (m_spellingMistakeLineColorSet || isGlobal()) {
1342 return m_spellingMistakeLineColor;
1343 }
1344
1345 return s_global->spellingMistakeLineColor();
1346}
1347
1348void KateRendererConfig::setSpellingMistakeLineColor(const QColor &col)
1349{
1350 if (m_spellingMistakeLineColorSet && m_spellingMistakeLineColor == col) {
1351 return;
1352 }
1353
1354 configStart();
1355
1356 m_spellingMistakeLineColorSet = true;
1357 m_spellingMistakeLineColor = col;
1358
1359 configEnd();
1360}
1361
1362const QColor &KateRendererConfig::modifiedLineColor() const
1363{
1364 if (m_modifiedLineColorSet || isGlobal()) {
1365 return m_modifiedLineColor;
1366 }
1367
1368 return s_global->modifiedLineColor();
1369}
1370
1371void KateRendererConfig::setModifiedLineColor(const QColor &col)
1372{
1373 if (m_modifiedLineColorSet && m_modifiedLineColor == col) {
1374 return;
1375 }
1376
1377 configStart();
1378
1379 m_modifiedLineColorSet = true;
1380 m_modifiedLineColor = col;
1381
1382 configEnd();
1383}
1384
1385const QColor &KateRendererConfig::savedLineColor() const
1386{
1387 if (m_savedLineColorSet || isGlobal()) {
1388 return m_savedLineColor;
1389 }
1390
1391 return s_global->savedLineColor();
1392}
1393
1394void KateRendererConfig::setSavedLineColor(const QColor &col)
1395{
1396 if (m_savedLineColorSet && m_savedLineColor == col) {
1397 return;
1398 }
1399
1400 configStart();
1401
1402 m_savedLineColorSet = true;
1403 m_savedLineColor = col;
1404
1405 configEnd();
1406}
1407
1408const QColor &KateRendererConfig::searchHighlightColor() const
1409{
1410 if (m_searchHighlightColorSet || isGlobal()) {
1411 return m_searchHighlightColor;
1412 }
1413
1414 return s_global->searchHighlightColor();
1415}
1416
1417void KateRendererConfig::setSearchHighlightColor(const QColor &col)
1418{
1419 if (m_searchHighlightColorSet && m_searchHighlightColor == col) {
1420 return;
1421 }
1422
1423 configStart();
1424
1425 m_searchHighlightColorSet = true;
1426 m_searchHighlightColor = col;
1427
1428 configEnd();
1429}
1430
1431const QColor &KateRendererConfig::replaceHighlightColor() const
1432{
1433 if (m_replaceHighlightColorSet || isGlobal()) {
1434 return m_replaceHighlightColor;
1435 }
1436
1437 return s_global->replaceHighlightColor();
1438}
1439
1440void KateRendererConfig::setReplaceHighlightColor(const QColor &col)
1441{
1442 if (m_replaceHighlightColorSet && m_replaceHighlightColor == col) {
1443 return;
1444 }
1445
1446 configStart();
1447
1448 m_replaceHighlightColorSet = true;
1449 m_replaceHighlightColor = col;
1450
1451 configEnd();
1452}
1453
1454void KateRendererConfig::setLineHeightMultiplier(qreal value)
1455{
1456 configStart();
1457 m_lineHeightMultiplier = value;
1458 configEnd();
1459}
1460
1461bool KateRendererConfig::showIndentationLines() const
1462{
1463 if (m_showIndentationLinesSet || isGlobal()) {
1464 return m_showIndentationLines;
1465 }
1466
1467 return s_global->showIndentationLines();
1468}
1469
1470void KateRendererConfig::setShowIndentationLines(bool on)
1471{
1472 if (m_showIndentationLinesSet && m_showIndentationLines == on) {
1473 return;
1474 }
1475
1476 configStart();
1477
1478 m_showIndentationLinesSet = true;
1479 m_showIndentationLines = on;
1480
1481 configEnd();
1482}
1483
1484bool KateRendererConfig::showWholeBracketExpression() const
1485{
1486 if (m_showWholeBracketExpressionSet || isGlobal()) {
1487 return m_showWholeBracketExpression;
1488 }
1489
1490 return s_global->showWholeBracketExpression();
1491}
1492
1493void KateRendererConfig::setShowWholeBracketExpression(bool on)
1494{
1495 if (m_showWholeBracketExpressionSet && m_showWholeBracketExpression == on) {
1496 return;
1497 }
1498
1499 configStart();
1500
1501 m_showWholeBracketExpressionSet = true;
1502 m_showWholeBracketExpression = on;
1503
1504 configEnd();
1505}
1506
1507bool KateRendererConfig::animateBracketMatching()
1508{
1509 return s_global->m_animateBracketMatching;
1510}
1511
1512void KateRendererConfig::setAnimateBracketMatching(bool on)
1513{
1514 if (!isGlobal()) {
1515 s_global->setAnimateBracketMatching(on);
1516 } else if (on != m_animateBracketMatching) {
1517 configStart();
1518 m_animateBracketMatching = on;
1519 configEnd();
1520 }
1521}
1522
1523// 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
bool isMisspelled(const QString &word) 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 Mar 28 2025 11:55:39 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.