diff --git a/src/syntax/katehighlight.h b/src/syntax/katehighlight.h --- a/src/syntax/katehighlight.h +++ b/src/syntax/katehighlight.h @@ -261,9 +261,10 @@ private: /** * create list of attributes from internal formats with properties as defined in syntax file + * @param schema The id of the chosen schema * @return attributes list with attributes as defined in syntax file */ - QVector attributesForDefinition(); + QVector attributesForDefinition(const QString &schema); int sanitizeFormatIndex(int attrib) const; diff --git a/src/syntax/katehighlight.cpp b/src/syntax/katehighlight.cpp --- a/src/syntax/katehighlight.cpp +++ b/src/syntax/katehighlight.cpp @@ -68,6 +68,22 @@ return static_cast(textStyle); } +/** + * convert the theme/schema name from KTextEditor => KSyntaxHighlighting. + * NOTE: some themes of KTextEditor don't exist in KSyntaxHighlighting + */ +inline QString convertThemeName(const QString &schema) +{ + if (schema == QLatin1String("Normal")) { + return QStringLiteral("Default"); + } else if (schema == QLatin1String("Solarized (light)")) { + return QStringLiteral("Solarized Light"); + } else if (schema == QLatin1String("Solarized (dark)")) { + return QStringLiteral("Solarized Dark"); + } + return schema; +} + } //END @@ -299,7 +315,7 @@ KConfigGroup config(cfg ? cfg : KateHlManager::self()->getKConfig(), QLatin1String("Highlighting ") + iName + QLatin1String(" - Schema ") + schema); - list = attributesForDefinition(); + list = attributesForDefinition(schema); foreach (KTextEditor::Attribute::Ptr p, list) { Q_ASSERT(p); @@ -505,47 +521,64 @@ m_attributeArrays.clear(); } -QVector KateHighlighting::attributesForDefinition() +QVector KateHighlighting::attributesForDefinition(const QString &schema) { - /** + /** + * get the KSyntaxHighlighting theme from the chosen schema + */ + KSyntaxHighlighting::Theme currentTheme = KateHlManager::self()->repository().theme(convertThemeName(schema)); + + /** * create list of all known things */ QVector array; for (const auto &format : m_formats) { /** - * FIXME: atm we just set some theme here for later color generation + * atm we just set the current chosen theme here for later color generation. + * NOTE: if the theme isn't valid for KSyntaxHighlighting, the default light theme will be used. + * For example, the "KDE" and "Vim (dark)" themes don't exist in KSyntaxHighlighting. */ - setTheme(KateHlManager::self()->repository().defaultTheme(KSyntaxHighlighting::Repository::LightTheme)); + if (currentTheme.isValid()) { + setTheme(currentTheme); + } else { + setTheme(KateHlManager::self()->repository().defaultTheme(KSyntaxHighlighting::Repository::LightTheme)); + } /** * create a KTextEditor attribute matching the given format */ KTextEditor::Attribute::Ptr newAttribute(new KTextEditor::Attribute(nameForAttrib(array.size()), textStyleToDefaultStyle(format.textStyle()))); - if (format.hasTextColor(theme())) { - newAttribute->setForeground(format.textColor(theme())); - newAttribute->setSelectedForeground(format.selectedTextColor(theme())); - } + /** + * don't apply attribute styles for schemas/themes that don't exist in KSyntaxHighlighting, + * but exist in KTextEditor + */ + if (currentTheme.isValid()) { + if (format.hasTextColor(theme())) { + newAttribute->setForeground(format.textColor(theme())); + newAttribute->setSelectedForeground(format.selectedTextColor(theme())); + } - if (format.hasBackgroundColor(theme())) { - newAttribute->setBackground(format.backgroundColor(theme())); - newAttribute->setSelectedBackground(format.selectedBackgroundColor(theme())); - } + if (format.hasBackgroundColor(theme())) { + newAttribute->setBackground(format.backgroundColor(theme())); + newAttribute->setSelectedBackground(format.selectedBackgroundColor(theme())); + } - if (format.isBold(theme())) { - newAttribute->setFontBold(true); - } + if (format.isBold(theme())) { + newAttribute->setFontBold(true); + } - if (format.isItalic(theme())) { - newAttribute->setFontItalic(true); - } + if (format.isItalic(theme())) { + newAttribute->setFontItalic(true); + } - if (format.isUnderline(theme())) { - newAttribute->setFontUnderline(true); - } + if (format.isUnderline(theme())) { + newAttribute->setFontUnderline(true); + } - if (format.isStrikeThrough(theme())) { - newAttribute->setFontStrikeOut(true); + if (format.isStrikeThrough(theme())) { + newAttribute->setFontStrikeOut(true); + } } newAttribute->setSkipSpellChecking(format.spellCheck());