Changeset View
Changeset View
Standalone View
Standalone View
src/syntax/katehighlight.cpp
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | 58 | { | |||
---|---|---|---|---|---|
63 | if (textStyle == KSyntaxHighlighting::Theme::Others) { | 63 | if (textStyle == KSyntaxHighlighting::Theme::Others) { | ||
64 | return KTextEditor::dsOthers; | 64 | return KTextEditor::dsOthers; | ||
65 | } | 65 | } | ||
66 | 66 | | |||
67 | // else: simple cast | 67 | // else: simple cast | ||
68 | return static_cast<KTextEditor::DefaultStyle>(textStyle); | 68 | return static_cast<KTextEditor::DefaultStyle>(textStyle); | ||
69 | } | 69 | } | ||
70 | 70 | | |||
71 | /** | ||||
72 | * convert the theme/schema name from KTextEditor => KSyntaxHighlighting. | ||||
73 | * NOTE: some themes of KTextEditor don't exist in KSyntaxHighlighting | ||||
74 | */ | ||||
75 | inline QString convertThemeName(const QString &schema) | ||||
76 | { | ||||
77 | if (schema == QLatin1String("Normal")) { | ||||
78 | return QStringLiteral("Default"); | ||||
mwolff: return QStringLiteral, otherwise you allocate on every function call (also below) | |||||
79 | } else if (schema == QLatin1String("Solarized (light)")) { | ||||
80 | return QStringLiteral("Solarized Light"); | ||||
81 | } else if (schema == QLatin1String("Solarized (dark)")) { | ||||
82 | return QStringLiteral("Solarized Dark"); | ||||
83 | } | ||||
84 | return schema; | ||||
85 | } | ||||
86 | | ||||
71 | } | 87 | } | ||
72 | //END | 88 | //END | ||
73 | 89 | | |||
74 | //BEGIN KateHighlighting | 90 | //BEGIN KateHighlighting | ||
75 | KateHighlighting::KateHighlighting(const KSyntaxHighlighting::Definition &def) | 91 | KateHighlighting::KateHighlighting(const KSyntaxHighlighting::Definition &def) | ||
76 | { | 92 | { | ||
77 | /** | 93 | /** | ||
78 | * get name and section, always works | 94 | * get name and section, always works | ||
▲ Show 20 Lines • Show All 215 Lines • ▼ Show 20 Line(s) | 284 | { | |||
294 | } | 310 | } | ||
295 | } | 311 | } | ||
296 | 312 | | |||
297 | void KateHighlighting::getKateExtendedAttributeList(const QString &schema, QVector<KTextEditor::Attribute::Ptr> &list, KConfig *cfg) | 313 | void KateHighlighting::getKateExtendedAttributeList(const QString &schema, QVector<KTextEditor::Attribute::Ptr> &list, KConfig *cfg) | ||
298 | { | 314 | { | ||
299 | KConfigGroup config(cfg ? cfg : KateHlManager::self()->getKConfig(), | 315 | KConfigGroup config(cfg ? cfg : KateHlManager::self()->getKConfig(), | ||
300 | QLatin1String("Highlighting ") + iName + QLatin1String(" - Schema ") + schema); | 316 | QLatin1String("Highlighting ") + iName + QLatin1String(" - Schema ") + schema); | ||
301 | 317 | | |||
302 | list = attributesForDefinition(); | 318 | list = attributesForDefinition(schema); | ||
303 | 319 | | |||
304 | foreach (KTextEditor::Attribute::Ptr p, list) { | 320 | foreach (KTextEditor::Attribute::Ptr p, list) { | ||
305 | Q_ASSERT(p); | 321 | Q_ASSERT(p); | ||
306 | 322 | | |||
307 | QStringList s = config.readEntry(p->name(), QStringList()); | 323 | QStringList s = config.readEntry(p->name(), QStringList()); | ||
308 | 324 | | |||
309 | // qCDebug(LOG_KTE)<<p->name<<s.count(); | 325 | // qCDebug(LOG_KTE)<<p->name<<s.count(); | ||
310 | if (!s.isEmpty()) { | 326 | if (!s.isEmpty()) { | ||
▲ Show 20 Lines • Show All 189 Lines • ▼ Show 20 Line(s) | |||||
500 | } | 516 | } | ||
501 | 517 | | |||
502 | void KateHighlighting::clearAttributeArrays() | 518 | void KateHighlighting::clearAttributeArrays() | ||
503 | { | 519 | { | ||
504 | // just clear the hashed attributes, we create them lazy again | 520 | // just clear the hashed attributes, we create them lazy again | ||
505 | m_attributeArrays.clear(); | 521 | m_attributeArrays.clear(); | ||
506 | } | 522 | } | ||
507 | 523 | | |||
508 | QVector<KTextEditor::Attribute::Ptr> KateHighlighting::attributesForDefinition() | 524 | QVector<KTextEditor::Attribute::Ptr> KateHighlighting::attributesForDefinition(const QString &schema) | ||
509 | { | 525 | { | ||
510 | /** | 526 | /** | ||
527 | * get the KSyntaxHighlighting theme from the chosen schema. | ||||
528 | * NOTE: if the theme isn't valid for KSyntaxHighlighting, an empty/invalid theme will be used. | ||||
529 | * For example, the "KDE" and "Vim (dark)" themes don't exist in KSyntaxHighlighting. | ||||
530 | */ | ||||
531 | KSyntaxHighlighting::Theme currentTheme = KateHlManager::self()->repository().theme(convertThemeName(schema)); | ||||
532 | | ||||
533 | /** | ||||
511 | * create list of all known things | 534 | * create list of all known things | ||
512 | */ | 535 | */ | ||
513 | QVector<KTextEditor::Attribute::Ptr> array; | 536 | QVector<KTextEditor::Attribute::Ptr> array; | ||
514 | for (const auto &format : m_formats) { | 537 | for (const auto &format : m_formats) { | ||
515 | /** | 538 | /** | ||
516 | * FIXME: atm we just set some theme here for later color generation | 539 | * atm we just set the current chosen theme here for later color generation | ||
517 | */ | 540 | */ | ||
518 | setTheme(KateHlManager::self()->repository().defaultTheme(KSyntaxHighlighting::Repository::LightTheme)); | 541 | setTheme(currentTheme); | ||
519 | 542 | | |||
520 | /** | 543 | /** | ||
521 | * create a KTextEditor attribute matching the given format | 544 | * create a KTextEditor attribute matching the given format | ||
522 | */ | 545 | */ | ||
523 | KTextEditor::Attribute::Ptr newAttribute(new KTextEditor::Attribute(nameForAttrib(array.size()), textStyleToDefaultStyle(format.textStyle()))); | 546 | KTextEditor::Attribute::Ptr newAttribute(new KTextEditor::Attribute(nameForAttrib(array.size()), textStyleToDefaultStyle(format.textStyle()))); | ||
524 | 547 | | |||
548 | /** | ||||
549 | * NOTE: if "theme()" returns an empty theme, only the | ||||
550 | * attribute styles set in the XML files will be applied here | ||||
551 | */ | ||||
525 | if (format.hasTextColor(theme())) { | 552 | if (format.hasTextColor(theme())) { | ||
526 | newAttribute->setForeground(format.textColor(theme())); | 553 | newAttribute->setForeground(format.textColor(theme())); | ||
527 | newAttribute->setSelectedForeground(format.selectedTextColor(theme())); | 554 | newAttribute->setSelectedForeground(format.selectedTextColor(theme())); | ||
528 | } | 555 | } | ||
529 | 556 | | |||
530 | if (format.hasBackgroundColor(theme())) { | 557 | if (format.hasBackgroundColor(theme())) { | ||
531 | newAttribute->setBackground(format.backgroundColor(theme())); | 558 | newAttribute->setBackground(format.backgroundColor(theme())); | ||
532 | newAttribute->setSelectedBackground(format.selectedBackgroundColor(theme())); | 559 | newAttribute->setSelectedBackground(format.selectedBackgroundColor(theme())); | ||
▲ Show 20 Lines • Show All 136 Lines • Show Last 20 Lines |
return QStringLiteral, otherwise you allocate on every function call (also below)