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

KDE's Doxygen guidelines are available online.