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{
218 return QStringDecoder(name.toUtf8().constData()).isValid() && QStringEncoder(name.toUtf8().constData()).isValid();
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(),
251 QString::fromUtf8(QStringConverter::nameForEncoding(QStringConverter::Latin1)),
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", QString(), 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));
337 addConfigEntry(ConfigEntry(RemoveSpacesMode, "Remove Spaces", QString(), 1 /* on modified lines per default */, [](const QVariant &value) {
338 return inBounds(0, value, 2);
339 }));
340 addConfigEntry(ConfigEntry(NewlineAtEOF, "Newline at End of File", QString(), true));
341 addConfigEntry(ConfigEntry(OverwriteMode, "Overwrite Mode", QString(), false));
343 ConfigEntry(Encoding, "Encoding", QString(), QString::fromUtf8(QStringConverter::nameForEncoding(QStringConverter::Utf8)), [](const QVariant &value) {
344 return isEncodingOk(value.toString());
345 }));
346 addConfigEntry(ConfigEntry(EndOfLine, "End of Line", QString(), 0));
347 addConfigEntry(ConfigEntry(AllowEndOfLineDetection, "Allow End of Line Detection", QString(), true));
348 addConfigEntry(ConfigEntry(ByteOrderMark, "BOM", QString(), false));
349 addConfigEntry(ConfigEntry(SwapFile, "Swap File Mode", QString(), KateDocumentConfig::EnableSwapFile));
350 addConfigEntry(ConfigEntry(SwapFileDirectory, "Swap Directory", QString(), QString()));
351 addConfigEntry(ConfigEntry(SwapFileSyncInterval, "Swap Sync Interval", QString(), 15));
352 addConfigEntry(ConfigEntry(LineLengthLimit, "Line Length Limit", QString(), 10000));
353 addConfigEntry(ConfigEntry(CamelCursor, "Camel Cursor", QString(), true));
354 addConfigEntry(ConfigEntry(AutoDetectIndent, "Auto Detect Indent", QString(), true));
355
356 // Auto save and co.
357 addConfigEntry(ConfigEntry(AutoSave, "Auto Save", QString(), false));
358 addConfigEntry(ConfigEntry(AutoSaveOnFocusOut, "Auto Save On Focus Out", QString(), false));
359 addConfigEntry(ConfigEntry(AutoSaveInteral, "Auto Save Interval", QString(), 0));
360
361 // Shall we do auto reloading for stuff e.g. in Git?
362 addConfigEntry(ConfigEntry(AutoReloadIfStateIsInVersionControl, "Auto Reload If State Is In Version Control", QString(), true));
363
364 // finalize the entries, e.g. hashs them
366
367 // init with defaults from config or really hardcoded ones
368 KConfigGroup cg(KTextEditor::EditorPrivate::config(), QStringLiteral("KTextEditor Document"));
369 readConfig(cg);
370
371 // avoid updateConfig effects like config write in constructor, see bug 377067
372 Q_ASSERT(configSessionNumber == 1);
374}
375
376KateDocumentConfig::KateDocumentConfig(KTextEditor::DocumentPrivate *doc)
377 : KateConfig(s_global)
378 , m_doc(doc)
379{
380 // per document config doesn't read stuff per default
381}
382
383void KateDocumentConfig::readConfig(const KConfigGroup &config)
384{
385 // start config update group
386 configStart();
387
388 // read generic entries
389 readConfigEntries(config);
390
391 // fixup sonnet config, see KateSpellCheckConfigTab::apply(), too
392 // WARNING: this is slightly hackish, but it's currently the only way to
393 // do it, see also the KTextEdit class
394 if (isGlobal()) {
395 const QSettings settings(QStringLiteral("KDE"), QStringLiteral("Sonnet"));
396 const bool onTheFlyChecking = settings.value(QStringLiteral("checkerEnabledByDefault"), false).toBool();
397 setOnTheFlySpellCheck(onTheFlyChecking);
398
399 // ensure we load the default dictionary speller + trigrams early
400 // this avoids hangs for auto-spellchecking on first edits
401 // do this if we have on the fly spellchecking on only
402 if (onTheFlyChecking) {
403 Sonnet::Speller speller;
404 speller.setLanguage(Sonnet::Speller().defaultLanguage());
405 Sonnet::GuessLanguage languageGuesser;
406 languageGuesser.identify(QStringLiteral("dummy to trigger identify"));
407 }
408 }
409
410 // backwards compatibility mappings
411 // convert stuff, old entries deleted in writeConfig
412 if (const int backupFlags = config.readEntry("Backup Flags", 0)) {
413 setBackupOnSaveLocal(backupFlags & 0x1);
414 setBackupOnSaveRemote(backupFlags & 0x2);
415 }
416
417 // end config update group, might trigger updateConfig()
418 configEnd();
419}
420
421void KateDocumentConfig::writeConfig(KConfigGroup &config)
422{
423 // write generic entries
424 writeConfigEntries(config);
425
426 // backwards compatibility mappings
427 // here we remove old entries we converted on readConfig
428 config.deleteEntry("Backup Flags");
429}
430
431void KateDocumentConfig::updateConfig()
432{
433 if (m_doc) {
434 m_doc->updateConfig();
435 return;
436 }
437
438 if (isGlobal()) {
439 const auto docs = KTextEditor::EditorPrivate::self()->documents();
440 for (auto doc : docs) {
441 static_cast<KTextEditor::DocumentPrivate *>(doc)->updateConfig();
442 }
443
444 // write config
445 KConfigGroup cg(KTextEditor::EditorPrivate::config(), QStringLiteral("KTextEditor Document"));
446 writeConfig(cg);
448
449 // trigger emission of KTextEditor::Editor::configChanged
451 }
452}
453
454QString KateDocumentConfig::eolString() const
455{
456 switch (eol()) {
457 case KateDocumentConfig::eolDos:
458 return QStringLiteral("\r\n");
459
460 case KateDocumentConfig::eolMac:
461 return QStringLiteral("\r");
462
463 default:
464 return QStringLiteral("\n");
465 }
466}
467// END
468
469// BEGIN KateViewConfig
470KateViewConfig::KateViewConfig()
471{
472 // register this as our global instance
473 Q_ASSERT(isGlobal());
474 s_global = this;
475
476 // avoid updateConfig effects like config write in constructor, see bug 377067
477 Q_ASSERT(configSessionNumber == 0);
479
480 // Init all known config entries
481 // NOTE: Ensure to keep the same order as listed in enum ConfigEntryTypes or it will later assert!
482 // addConfigEntry(ConfigEntry(<EnumKey>, <ConfigKey>, <CommandName>, <DefaultValue>, [<ValidatorFunction>]))
483 addConfigEntry(ConfigEntry(AllowMarkMenu, "Allow Mark Menu", QStringLiteral("allow-mark-menu"), true));
484 addConfigEntry(ConfigEntry(AutoBrackets, "Auto Brackets", QStringLiteral("auto-brackets"), true));
485 addConfigEntry(ConfigEntry(AutoCenterLines, "Auto Center Lines", QStringLiteral("auto-center-lines"), 0));
486 addConfigEntry(ConfigEntry(AutomaticCompletionInvocation, "Auto Completion", QString(), true));
487 addConfigEntry(ConfigEntry(AutomaticCompletionPreselectFirst, "Auto Completion Preselect First Entry", QString(), true));
488 addConfigEntry(ConfigEntry(BackspaceRemoveComposedCharacters, "Backspace Remove Composed Characters", QString(), false));
489 addConfigEntry(ConfigEntry(BookmarkSorting, "Bookmark Menu Sorting", QString(), 0));
490 addConfigEntry(ConfigEntry(CharsToEncloseSelection, "Chars To Enclose Selection", QStringLiteral("enclose-selection"), QStringLiteral("<>(){}[]'\"")));
491 addConfigEntry(ConfigEntry(ClipboardHistoryEntries, "Max Clipboard History Entries", QString(), 20, [](const QVariant &value) {
492 return inBounds(1, value, 999);
493 }));
495 ConfigEntry(DefaultMarkType, "Default Mark Type", QStringLiteral("default-mark-type"), KTextEditor::Document::markType01, [](const QVariant &value) {
496 return isPositive(value);
497 }));
498 addConfigEntry(ConfigEntry(DynWordWrapAlignIndent, "Dynamic Word Wrap Align Indent", QString(), 80, [](const QVariant &value) {
499 return inBounds(0, value, 100);
500 }));
501 addConfigEntry(ConfigEntry(DynWordWrapIndicators, "Dynamic Word Wrap Indicators", QString(), 1, [](const QVariant &value) {
502 return inBounds(0, value, 2);
503 }));
504 addConfigEntry(ConfigEntry(DynWrapAnywhere, "Dynamic Wrap not at word boundaries", QStringLiteral("dynamic-word-wrap-anywhere"), false));
505 addConfigEntry(ConfigEntry(DynWrapAtStaticMarker, "Dynamic Word Wrap At Static Marker", QString(), false));
506 addConfigEntry(ConfigEntry(DynamicWordWrap, "Dynamic Word Wrap", QStringLiteral("dynamic-word-wrap"), true));
507 addConfigEntry(ConfigEntry(EnterToInsertCompletion, "Enter To Insert Completion", QStringLiteral("enter-to-insert-completion"), true));
508 addConfigEntry(ConfigEntry(FoldFirstLine, "Fold First Line", QString(), false));
509 addConfigEntry(ConfigEntry(InputMode, "Input Mode", QString(), 0, [](const QVariant &value) {
510 return isPositive(value);
511 }));
512 addConfigEntry(ConfigEntry(KeywordCompletion, "Keyword Completion", QStringLiteral("keyword-completion"), true));
513 addConfigEntry(ConfigEntry(MaxHistorySize, "Maximum Search History Size", QString(), 100, [](const QVariant &value) {
514 return inBounds(0, value, 999);
515 }));
516 addConfigEntry(ConfigEntry(MousePasteAtCursorPosition, "Mouse Paste At Cursor Position", QString(), false));
517 addConfigEntry(ConfigEntry(PersistentSelection, "Persistent Selection", QStringLiteral("persistent-selectionq"), false));
518 addConfigEntry(ConfigEntry(ScrollBarMiniMapWidth, "Scroll Bar Mini Map Width", QString(), 60, [](const QVariant &value) {
519 return inBounds(0, value, 999);
520 }));
521 addConfigEntry(ConfigEntry(ScrollPastEnd, "Scroll Past End", QString(), false));
522 addConfigEntry(ConfigEntry(SearchFlags, "Search/Replace Flags", QString(), IncFromCursor | PowerMatchCase | PowerModePlainText));
523 addConfigEntry(ConfigEntry(TabCompletion, "Enable Tab completion", QString(), false));
524 addConfigEntry(ConfigEntry(ShowBracketMatchPreview, "Bracket Match Preview", QStringLiteral("bracket-match-preview"), false));
525 addConfigEntry(ConfigEntry(ShowFoldingBar, "Folding Bar", QStringLiteral("folding-bar"), true));
526 addConfigEntry(ConfigEntry(ShowFoldingPreview, "Folding Preview", QStringLiteral("folding-preview"), true));
527 addConfigEntry(ConfigEntry(ShowIconBar, "Icon Bar", QStringLiteral("icon-bar"), false));
528 addConfigEntry(ConfigEntry(ShowLineCount, "Show Line Count", QString(), false));
529 addConfigEntry(ConfigEntry(ShowLineModification, "Line Modification", QStringLiteral("modification-markers"), true));
530 addConfigEntry(ConfigEntry(ShowLineNumbers, "Line Numbers", QStringLiteral("line-numbers"), true));
531 addConfigEntry(ConfigEntry(ShowScrollBarMarks, "Scroll Bar Marks", QString(), false));
532 addConfigEntry(ConfigEntry(ShowScrollBarMiniMap, "Scroll Bar MiniMap", QStringLiteral("scrollbar-minimap"), true));
533 addConfigEntry(ConfigEntry(ShowScrollBarMiniMapAll, "Scroll Bar Mini Map All", QString(), true));
534 addConfigEntry(ConfigEntry(ShowScrollBarPreview, "Scroll Bar Preview", QStringLiteral("scrollbar-preview"), true));
535 addConfigEntry(ConfigEntry(ShowScrollbars, "Show Scrollbars", QString(), AlwaysOn, [](const QVariant &value) {
536 return inBounds(0, value, 2);
537 }));
538 addConfigEntry(ConfigEntry(ShowWordCount, "Show Word Count", QString(), false));
539 addConfigEntry(ConfigEntry(TextDragAndDrop, "Text Drag And Drop", QString(), true));
540 addConfigEntry(ConfigEntry(SmartCopyCut, "Smart Copy Cut", QString(), true));
541 addConfigEntry(ConfigEntry(UserSetsOfCharsToEncloseSelection, "User Sets Of Chars To Enclose Selection", QString(), QStringList()));
542 addConfigEntry(ConfigEntry(ViInputModeStealKeys, "Vi Input Mode Steal Keys", QString(), false));
543 addConfigEntry(ConfigEntry(ViRelativeLineNumbers, "Vi Relative Line Numbers", QString(), false));
544 addConfigEntry(ConfigEntry(WordCompletion, "Word Completion", QString(), true));
545 addConfigEntry(ConfigEntry(WordCompletionMinimalWordLength,
546 "Word Completion Minimal Word Length",
547 QStringLiteral("word-completion-minimal-word-length"),
548 3,
549 [](const QVariant &value) {
550 return inBounds(0, value, 99);
551 }));
552 addConfigEntry(ConfigEntry(WordCompletionRemoveTail, "Word Completion Remove Tail", QString(), true));
553 addConfigEntry(ConfigEntry(ShowFocusFrame, "Show Focus Frame Around Editor", 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_COLOR_THEME[] = "Color Theme";
722const char KEY_WORD_WRAP_MARKER[] = "Word Wrap Marker";
723const char KEY_SHOW_INDENTATION_LINES[] = "Show Indentation Lines";
724const char KEY_SHOW_WHOLE_BRACKET_EXPRESSION[] = "Show Whole Bracket Expression";
725const char KEY_ANIMATE_BRACKET_MATCHING[] = "Animate Bracket Matching";
726const char KEY_LINE_HEIGHT_MULTIPLIER[] = "Line Height Multiplier";
727}
728
729void KateRendererConfig::readConfig(const KConfigGroup &config)
730{
731 configStart();
732
733 // read generic entries
734 readConfigEntries(config);
735
736 // read font
738
739 // setSchema will default to right theme
740 setSchema(config.readEntry(KEY_COLOR_THEME, QString()));
741
742 setWordWrapMarker(config.readEntry(KEY_WORD_WRAP_MARKER, false));
743
744 setShowIndentationLines(config.readEntry(KEY_SHOW_INDENTATION_LINES, false));
745
746 setShowWholeBracketExpression(config.readEntry(KEY_SHOW_WHOLE_BRACKET_EXPRESSION, false));
747
748 setAnimateBracketMatching(config.readEntry(KEY_ANIMATE_BRACKET_MATCHING, false));
749
750 setLineHeightMultiplier(config.readEntry<qreal>(KEY_LINE_HEIGHT_MULTIPLIER, 1.0));
751
752 configEnd();
753}
754
755void KateRendererConfig::writeConfig(KConfigGroup &config)
756{
757 // write generic entries
758 writeConfigEntries(config);
759
760 config.writeEntry(KEY_FONT, baseFont());
761
762 config.writeEntry(KEY_COLOR_THEME, schema());
763
764 config.writeEntry(KEY_WORD_WRAP_MARKER, wordWrapMarker());
765
766 config.writeEntry(KEY_SHOW_INDENTATION_LINES, showIndentationLines());
767
768 config.writeEntry(KEY_SHOW_WHOLE_BRACKET_EXPRESSION, showWholeBracketExpression());
769
770 config.writeEntry(KEY_ANIMATE_BRACKET_MATCHING, animateBracketMatching());
771
772 config.writeEntry<qreal>(KEY_LINE_HEIGHT_MULTIPLIER, lineHeightMultiplier());
773}
774
775void KateRendererConfig::updateConfig()
776{
777 if (m_renderer) {
778 m_renderer->updateConfig();
779 return;
780 }
781
782 if (isGlobal()) {
783 for (auto view : KTextEditor::EditorPrivate::self()->views()) {
784 view->renderer()->updateConfig();
785 }
786
787 // write config
788 KConfigGroup cg(KTextEditor::EditorPrivate::config(), QStringLiteral("KTextEditor Renderer"));
789 writeConfig(cg);
791
792 // trigger emission of KTextEditor::Editor::configChanged
794 }
795}
796
797const QString &KateRendererConfig::schema() const
798{
799 if (m_schemaSet || isGlobal()) {
800 return m_schema;
801 }
802
803 return s_global->schema();
804}
805
806void KateRendererConfig::setSchema(QString schema)
807{
808 // check if we have some matching theme, else fallback to best theme for current palette
809 // same behavior as for the "Automatic Color Theme Selection"
810 if (!KateHlManager::self()->repository().theme(schema).isValid()) {
811 schema = KateHlManager::self()->repository().themeForPalette(qGuiApp->palette()).name();
812 }
813
814 if (m_schemaSet && m_schema == schema) {
815 return;
816 }
817
818 configStart();
819 m_schemaSet = true;
820 m_schema = schema;
821 setSchemaInternal(m_schema);
822 configEnd();
823}
824
825void KateRendererConfig::reloadSchema()
826{
827 if (isGlobal()) {
828 setSchemaInternal(m_schema);
829 for (KTextEditor::ViewPrivate *view : KTextEditor::EditorPrivate::self()->views()) {
830 view->rendererConfig()->reloadSchema();
831 }
832 }
833
834 else if (m_renderer && m_schemaSet) {
835 setSchemaInternal(m_schema);
836 }
837
838 // trigger renderer/view update
839 if (m_renderer) {
840 m_renderer->updateConfig();
841 }
842}
843
844void KateRendererConfig::setSchemaInternal(const QString &schema)
845{
846 // we always set the theme if we arrive here!
847 m_schemaSet = true;
848
849 // for the global config, we honor the auto selection based on the palette
850 // 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!
851 if ((isGlobal() && value(AutoColorThemeSelection).toBool()) || !KateHlManager::self()->repository().theme(schema).isValid()) {
852 // always choose some theme matching the current application palette
853 // we will arrive here after palette changed signals, too!
854 m_schema = KateHlManager::self()->repository().themeForPalette(qGuiApp->palette()).name();
855 } else {
856 // take user given theme 1:1
857 m_schema = schema;
858 }
859
860 const auto theme = KateHlManager::self()->repository().theme(m_schema);
861
862 m_backgroundColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::BackgroundColor));
863 m_backgroundColorSet = true;
864
865 m_selectionColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::TextSelection));
866 m_selectionColorSet = true;
867
868 m_highlightedLineColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::CurrentLine));
869 m_highlightedLineColorSet = true;
870
871 m_highlightedBracketColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::BracketMatching));
872 m_highlightedBracketColorSet = true;
873
874 m_wordWrapMarkerColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::WordWrapMarker));
875 m_wordWrapMarkerColorSet = true;
876
877 m_tabMarkerColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::TabMarker));
878 m_tabMarkerColorSet = true;
879
880 m_indentationLineColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::IndentationLine));
881 m_indentationLineColorSet = true;
882
883 m_iconBarColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::IconBorder));
884 m_iconBarColorSet = true;
885
886 m_foldingColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::CodeFolding));
887 m_foldingColorSet = true;
888
889 m_lineNumberColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::LineNumbers));
890 m_lineNumberColorSet = true;
891
892 m_currentLineNumberColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::CurrentLineNumber));
893 m_currentLineNumberColorSet = true;
894
895 m_separatorColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::Separator));
896 m_separatorColorSet = true;
897
898 m_spellingMistakeLineColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::SpellChecking));
899 m_spellingMistakeLineColorSet = true;
900
901 m_modifiedLineColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::ModifiedLines));
902 m_modifiedLineColorSet = true;
903
904 m_savedLineColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::SavedLines));
905 m_savedLineColorSet = true;
906
907 m_searchHighlightColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::SearchHighlight));
908 m_searchHighlightColorSet = true;
909
910 m_replaceHighlightColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::ReplaceHighlight));
911 m_replaceHighlightColorSet = true;
912
914 QColor col =
916 m_lineMarkerColorSet[i] = true;
917 m_lineMarkerColor[i] = col;
918 }
919
920 m_templateBackgroundColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::TemplateBackground));
921
922 m_templateFocusedEditablePlaceholderColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::TemplateFocusedPlaceholder));
923
924 m_templateEditablePlaceholderColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::TemplatePlaceholder));
925
926 m_templateNotEditablePlaceholderColor = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::TemplateReadOnlyPlaceholder));
927
928 m_templateColorsSet = true;
929}
930
931const QFont &KateRendererConfig::baseFont() const
932{
933 if (m_fontSet || isGlobal()) {
934 return m_font;
935 }
936
937 return s_global->baseFont();
938}
939
940void KateRendererConfig::setFont(const QFont &font)
941{
942 if (m_fontSet && m_font == font) {
943 return;
944 }
945
946 configStart();
947 m_font = font;
948 m_fontSet = true;
949 configEnd();
950}
951
952bool KateRendererConfig::wordWrapMarker() const
953{
954 if (m_wordWrapMarkerSet || isGlobal()) {
955 return m_wordWrapMarker;
956 }
957
958 return s_global->wordWrapMarker();
959}
960
961void KateRendererConfig::setWordWrapMarker(bool on)
962{
963 if (m_wordWrapMarkerSet && m_wordWrapMarker == on) {
964 return;
965 }
966
967 configStart();
968
969 m_wordWrapMarkerSet = true;
970 m_wordWrapMarker = on;
971
972 configEnd();
973}
974
975const QColor &KateRendererConfig::backgroundColor() const
976{
977 if (m_backgroundColorSet || isGlobal()) {
978 return m_backgroundColor;
979 }
980
981 return s_global->backgroundColor();
982}
983
984void KateRendererConfig::setBackgroundColor(const QColor &col)
985{
986 if (m_backgroundColorSet && m_backgroundColor == col) {
987 return;
988 }
989
990 configStart();
991
992 m_backgroundColorSet = true;
993 m_backgroundColor = col;
994
995 configEnd();
996}
997
998const QColor &KateRendererConfig::selectionColor() const
999{
1000 if (m_selectionColorSet || isGlobal()) {
1001 return m_selectionColor;
1002 }
1003
1004 return s_global->selectionColor();
1005}
1006
1007void KateRendererConfig::setSelectionColor(const QColor &col)
1008{
1009 if (m_selectionColorSet && m_selectionColor == col) {
1010 return;
1011 }
1012
1013 configStart();
1014
1015 m_selectionColorSet = true;
1016 m_selectionColor = col;
1017
1018 configEnd();
1019}
1020
1021const QColor &KateRendererConfig::highlightedLineColor() const
1022{
1023 if (m_highlightedLineColorSet || isGlobal()) {
1024 return m_highlightedLineColor;
1025 }
1026
1027 return s_global->highlightedLineColor();
1028}
1029
1030void KateRendererConfig::setHighlightedLineColor(const QColor &col)
1031{
1032 if (m_highlightedLineColorSet && m_highlightedLineColor == col) {
1033 return;
1034 }
1035
1036 configStart();
1037
1038 m_highlightedLineColorSet = true;
1039 m_highlightedLineColor = col;
1040
1041 configEnd();
1042}
1043
1044const QColor &KateRendererConfig::lineMarkerColor(KTextEditor::Document::MarkTypes type) const
1045{
1046 int index = 0;
1047 if (type > 0) {
1048 while ((type >> index++) ^ 1) { }
1049 }
1050 index -= 1;
1051
1052 if (index < 0 || index >= KTextEditor::Document::reservedMarkersCount()) {
1053 static QColor dummy;
1054 return dummy;
1055 }
1056
1057 if (m_lineMarkerColorSet[index] || isGlobal()) {
1058 return m_lineMarkerColor[index];
1059 }
1060
1061 return s_global->lineMarkerColor(type);
1062}
1063
1064const QColor &KateRendererConfig::highlightedBracketColor() const
1065{
1066 if (m_highlightedBracketColorSet || isGlobal()) {
1067 return m_highlightedBracketColor;
1068 }
1069
1070 return s_global->highlightedBracketColor();
1071}
1072
1073void KateRendererConfig::setHighlightedBracketColor(const QColor &col)
1074{
1075 if (m_highlightedBracketColorSet && m_highlightedBracketColor == col) {
1076 return;
1077 }
1078
1079 configStart();
1080
1081 m_highlightedBracketColorSet = true;
1082 m_highlightedBracketColor = col;
1083
1084 configEnd();
1085}
1086
1087const QColor &KateRendererConfig::wordWrapMarkerColor() const
1088{
1089 if (m_wordWrapMarkerColorSet || isGlobal()) {
1090 return m_wordWrapMarkerColor;
1091 }
1092
1093 return s_global->wordWrapMarkerColor();
1094}
1095
1096void KateRendererConfig::setWordWrapMarkerColor(const QColor &col)
1097{
1098 if (m_wordWrapMarkerColorSet && m_wordWrapMarkerColor == col) {
1099 return;
1100 }
1101
1102 configStart();
1103
1104 m_wordWrapMarkerColorSet = true;
1105 m_wordWrapMarkerColor = col;
1106
1107 configEnd();
1108}
1109
1110const QColor &KateRendererConfig::tabMarkerColor() const
1111{
1112 if (m_tabMarkerColorSet || isGlobal()) {
1113 return m_tabMarkerColor;
1114 }
1115
1116 return s_global->tabMarkerColor();
1117}
1118
1119void KateRendererConfig::setTabMarkerColor(const QColor &col)
1120{
1121 if (m_tabMarkerColorSet && m_tabMarkerColor == col) {
1122 return;
1123 }
1124
1125 configStart();
1126
1127 m_tabMarkerColorSet = true;
1128 m_tabMarkerColor = col;
1129
1130 configEnd();
1131}
1132
1133const QColor &KateRendererConfig::indentationLineColor() const
1134{
1135 if (m_indentationLineColorSet || isGlobal()) {
1136 return m_indentationLineColor;
1137 }
1138
1139 return s_global->indentationLineColor();
1140}
1141
1142void KateRendererConfig::setIndentationLineColor(const QColor &col)
1143{
1144 if (m_indentationLineColorSet && m_indentationLineColor == col) {
1145 return;
1146 }
1147
1148 configStart();
1149
1150 m_indentationLineColorSet = true;
1151 m_indentationLineColor = col;
1152
1153 configEnd();
1154}
1155
1156const QColor &KateRendererConfig::iconBarColor() const
1157{
1158 if (m_iconBarColorSet || isGlobal()) {
1159 return m_iconBarColor;
1160 }
1161
1162 return s_global->iconBarColor();
1163}
1164
1165void KateRendererConfig::setIconBarColor(const QColor &col)
1166{
1167 if (m_iconBarColorSet && m_iconBarColor == col) {
1168 return;
1169 }
1170
1171 configStart();
1172
1173 m_iconBarColorSet = true;
1174 m_iconBarColor = col;
1175
1176 configEnd();
1177}
1178
1179const QColor &KateRendererConfig::foldingColor() const
1180{
1181 if (m_foldingColorSet || isGlobal()) {
1182 return m_foldingColor;
1183 }
1184
1185 return s_global->foldingColor();
1186}
1187
1188void KateRendererConfig::setFoldingColor(const QColor &col)
1189{
1190 if (m_foldingColorSet && m_foldingColor == col) {
1191 return;
1192 }
1193
1194 configStart();
1195
1196 m_foldingColorSet = true;
1197 m_foldingColor = col;
1198
1199 configEnd();
1200}
1201
1202const QColor &KateRendererConfig::templateBackgroundColor() const
1203{
1204 if (m_templateColorsSet || isGlobal()) {
1205 return m_templateBackgroundColor;
1206 }
1207
1208 return s_global->templateBackgroundColor();
1209}
1210
1211const QColor &KateRendererConfig::templateEditablePlaceholderColor() const
1212{
1213 if (m_templateColorsSet || isGlobal()) {
1214 return m_templateEditablePlaceholderColor;
1215 }
1216
1217 return s_global->templateEditablePlaceholderColor();
1218}
1219
1220const QColor &KateRendererConfig::templateFocusedEditablePlaceholderColor() const
1221{
1222 if (m_templateColorsSet || isGlobal()) {
1223 return m_templateFocusedEditablePlaceholderColor;
1224 }
1225
1226 return s_global->templateFocusedEditablePlaceholderColor();
1227}
1228
1229const QColor &KateRendererConfig::templateNotEditablePlaceholderColor() const
1230{
1231 if (m_templateColorsSet || isGlobal()) {
1232 return m_templateNotEditablePlaceholderColor;
1233 }
1234
1235 return s_global->templateNotEditablePlaceholderColor();
1236}
1237
1238const QColor &KateRendererConfig::lineNumberColor() const
1239{
1240 if (m_lineNumberColorSet || isGlobal()) {
1241 return m_lineNumberColor;
1242 }
1243
1244 return s_global->lineNumberColor();
1245}
1246
1247void KateRendererConfig::setLineNumberColor(const QColor &col)
1248{
1249 if (m_lineNumberColorSet && m_lineNumberColor == col) {
1250 return;
1251 }
1252
1253 configStart();
1254
1255 m_lineNumberColorSet = true;
1256 m_lineNumberColor = col;
1257
1258 configEnd();
1259}
1260
1261const QColor &KateRendererConfig::currentLineNumberColor() const
1262{
1263 if (m_currentLineNumberColorSet || isGlobal()) {
1264 return m_currentLineNumberColor;
1265 }
1266
1267 return s_global->currentLineNumberColor();
1268}
1269
1270void KateRendererConfig::setCurrentLineNumberColor(const QColor &col)
1271{
1272 if (m_currentLineNumberColorSet && m_currentLineNumberColor == col) {
1273 return;
1274 }
1275
1276 configStart();
1277
1278 m_currentLineNumberColorSet = true;
1279 m_currentLineNumberColor = col;
1280
1281 configEnd();
1282}
1283
1284const QColor &KateRendererConfig::separatorColor() const
1285{
1286 if (m_separatorColorSet || isGlobal()) {
1287 return m_separatorColor;
1288 }
1289
1290 return s_global->separatorColor();
1291}
1292
1293void KateRendererConfig::setSeparatorColor(const QColor &col)
1294{
1295 if (m_separatorColorSet && m_separatorColor == col) {
1296 return;
1297 }
1298
1299 configStart();
1300
1301 m_separatorColorSet = true;
1302 m_separatorColor = col;
1303
1304 configEnd();
1305}
1306
1307const QColor &KateRendererConfig::spellingMistakeLineColor() const
1308{
1309 if (m_spellingMistakeLineColorSet || isGlobal()) {
1310 return m_spellingMistakeLineColor;
1311 }
1312
1313 return s_global->spellingMistakeLineColor();
1314}
1315
1316void KateRendererConfig::setSpellingMistakeLineColor(const QColor &col)
1317{
1318 if (m_spellingMistakeLineColorSet && m_spellingMistakeLineColor == col) {
1319 return;
1320 }
1321
1322 configStart();
1323
1324 m_spellingMistakeLineColorSet = true;
1325 m_spellingMistakeLineColor = col;
1326
1327 configEnd();
1328}
1329
1330const QColor &KateRendererConfig::modifiedLineColor() const
1331{
1332 if (m_modifiedLineColorSet || isGlobal()) {
1333 return m_modifiedLineColor;
1334 }
1335
1336 return s_global->modifiedLineColor();
1337}
1338
1339void KateRendererConfig::setModifiedLineColor(const QColor &col)
1340{
1341 if (m_modifiedLineColorSet && m_modifiedLineColor == col) {
1342 return;
1343 }
1344
1345 configStart();
1346
1347 m_modifiedLineColorSet = true;
1348 m_modifiedLineColor = col;
1349
1350 configEnd();
1351}
1352
1353const QColor &KateRendererConfig::savedLineColor() const
1354{
1355 if (m_savedLineColorSet || isGlobal()) {
1356 return m_savedLineColor;
1357 }
1358
1359 return s_global->savedLineColor();
1360}
1361
1362void KateRendererConfig::setSavedLineColor(const QColor &col)
1363{
1364 if (m_savedLineColorSet && m_savedLineColor == col) {
1365 return;
1366 }
1367
1368 configStart();
1369
1370 m_savedLineColorSet = true;
1371 m_savedLineColor = col;
1372
1373 configEnd();
1374}
1375
1376const QColor &KateRendererConfig::searchHighlightColor() const
1377{
1378 if (m_searchHighlightColorSet || isGlobal()) {
1379 return m_searchHighlightColor;
1380 }
1381
1382 return s_global->searchHighlightColor();
1383}
1384
1385void KateRendererConfig::setSearchHighlightColor(const QColor &col)
1386{
1387 if (m_searchHighlightColorSet && m_searchHighlightColor == col) {
1388 return;
1389 }
1390
1391 configStart();
1392
1393 m_searchHighlightColorSet = true;
1394 m_searchHighlightColor = col;
1395
1396 configEnd();
1397}
1398
1399const QColor &KateRendererConfig::replaceHighlightColor() const
1400{
1401 if (m_replaceHighlightColorSet || isGlobal()) {
1402 return m_replaceHighlightColor;
1403 }
1404
1405 return s_global->replaceHighlightColor();
1406}
1407
1408void KateRendererConfig::setReplaceHighlightColor(const QColor &col)
1409{
1410 if (m_replaceHighlightColorSet && m_replaceHighlightColor == col) {
1411 return;
1412 }
1413
1414 configStart();
1415
1416 m_replaceHighlightColorSet = true;
1417 m_replaceHighlightColor = col;
1418
1419 configEnd();
1420}
1421
1422void KateRendererConfig::setLineHeightMultiplier(qreal value)
1423{
1424 configStart();
1425 m_lineHeightMultiplier = value;
1426 configEnd();
1427}
1428
1429bool KateRendererConfig::showIndentationLines() const
1430{
1431 if (m_showIndentationLinesSet || isGlobal()) {
1432 return m_showIndentationLines;
1433 }
1434
1435 return s_global->showIndentationLines();
1436}
1437
1438void KateRendererConfig::setShowIndentationLines(bool on)
1439{
1440 if (m_showIndentationLinesSet && m_showIndentationLines == on) {
1441 return;
1442 }
1443
1444 configStart();
1445
1446 m_showIndentationLinesSet = true;
1447 m_showIndentationLines = on;
1448
1449 configEnd();
1450}
1451
1452bool KateRendererConfig::showWholeBracketExpression() const
1453{
1454 if (m_showWholeBracketExpressionSet || isGlobal()) {
1455 return m_showWholeBracketExpression;
1456 }
1457
1458 return s_global->showWholeBracketExpression();
1459}
1460
1461void KateRendererConfig::setShowWholeBracketExpression(bool on)
1462{
1463 if (m_showWholeBracketExpressionSet && m_showWholeBracketExpression == on) {
1464 return;
1465 }
1466
1467 configStart();
1468
1469 m_showWholeBracketExpressionSet = true;
1470 m_showWholeBracketExpression = on;
1471
1472 configEnd();
1473}
1474
1475bool KateRendererConfig::animateBracketMatching()
1476{
1477 return s_global->m_animateBracketMatching;
1478}
1479
1480void KateRendererConfig::setAnimateBracketMatching(bool on)
1481{
1482 if (!isGlobal()) {
1483 s_global->setAnimateBracketMatching(on);
1484 } else if (on != m_animateBracketMatching) {
1485 configStart();
1486 m_animateBracketMatching = on;
1487 configEnd();
1488 }
1489}
1490
1491// 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
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:112
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)
bool isValid(QStringView ifopt)
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(QFontDatabase::SystemFont type)
QString fromUtf8(const char *str, int size)
QByteArray toUtf8() const const
AltModifier
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 Sat Feb 24 2024 20:00:58 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.