Commit 039d12eb authored by Christoph Cullmann's avatar Christoph Cullmann 🐮
Browse files

show default settings JSON with proper highlighting

parent 3ecd6c28
find_package(KF5ItemModels ${KF5_DEP_VERSION} QUIET)
set_package_properties(KF5ItemModels PROPERTIES PURPOSE "Required to build the lspclient addon")
if(NOT KF5ItemModels_FOUND)
find_package(KF5SyntaxHighlighting ${KF5_DEP_VERSION} QUIET)
set_package_properties(KF5SyntaxHighlighting PROPERTIES PURPOSE "Required to build the lspclient addon")
if(NOT KF5ItemModels_FOUND OR NOT KF5SyntaxHighlighting_FOUND)
return()
endif()
......@@ -11,10 +14,11 @@ target_compile_definitions(lspclientplugin PRIVATE TRANSLATION_DOMAIN="lspclient
ki18n_wrap_ui(UI_SOURCES lspconfigwidget.ui)
target_link_libraries(
lspclientplugin
PRIVATE
lspclientplugin
PRIVATE
KF5::ItemModels
KF5::TextEditor
KF5::SyntaxHighlighting
)
include(ECMQtDeclareLoggingCategory)
......
......@@ -28,6 +28,12 @@
#include <KLocalizedString>
#include <KSyntaxHighlighting/Definition>
#include <KSyntaxHighlighting/SyntaxHighlighter>
#include <KSyntaxHighlighting/Theme>
#include <QPalette>
LSPClientConfigPage::LSPClientConfigPage(QWidget *parent, LSPClientPlugin *plugin)
: KTextEditor::ConfigPage(parent)
, m_plugin(plugin)
......@@ -35,6 +41,23 @@ LSPClientConfigPage::LSPClientConfigPage(QWidget *parent, LSPClientPlugin *plugi
ui = new Ui::LspConfigWidget();
ui->setupUi(this);
// setup JSON highlighter for the default json stuff
auto highlighter = new KSyntaxHighlighting::SyntaxHighlighter(ui->defaultConfig->document());
highlighter->setDefinition(m_repository.definitionForFileName(QStringLiteral("settings.json")));
// we want mono-spaced font
ui->defaultConfig->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
// we want to have the proper theme for the current palette
const auto theme = (palette().color(QPalette::Base).lightness() < 128) ? m_repository.defaultTheme(KSyntaxHighlighting::Repository::DarkTheme) : m_repository.defaultTheme(KSyntaxHighlighting::Repository::LightTheme);
auto pal = qApp->palette();
if (theme.isValid()) {
pal.setColor(QPalette::Base, theme.editorColor(KSyntaxHighlighting::Theme::BackgroundColor));
pal.setColor(QPalette::Highlight, theme.editorColor(KSyntaxHighlighting::Theme::TextSelection));
}
ui->defaultConfig->setPalette(pal);
highlighter->setTheme(theme);
// setup default json settings
QFile defaultConfigFile(QStringLiteral(":/lspclient/settings.json"));
defaultConfigFile.open(QIODevice::ReadOnly);
......
......@@ -26,6 +26,7 @@
#define LSPCLIENTCONFIGPAGE_H
#include <KTextEditor/ConfigPage>
#include <KSyntaxHighlighting/Repository>
class LSPClientPlugin;
......@@ -54,6 +55,7 @@ public Q_SLOTS:
private:
Ui::LspConfigWidget *ui;
LSPClientPlugin *m_plugin;
KSyntaxHighlighting::Repository m_repository;
};
#endif
......@@ -189,7 +189,14 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<widget class="QTextBrowser" name="defaultConfig"/>
<widget class="QTextBrowser" name="defaultConfig">
<property name="lineWrapMode">
<enum>QTextEdit::NoWrap</enum>
</property>
<property name="acceptRichText">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment