Commit e03a0cb1 authored by Volker Krause's avatar Volker Krause

Port template highlighting to KF5::SyntaxHighlighter

Summary:
Besides a better highlighting and more accurate spell-checking areas, this
also removes the last user of the old highlighting framework in KDE PIM.

Reviewers: #kde_pim, mlaurent

Reviewed By: #kde_pim, mlaurent

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D7674
parent dcb755be
......@@ -38,7 +38,7 @@ set(KLDAP_LIB_VERSION "5.6.40")
set(KMAILTRANSPORT_LIB_VERSION "5.6.40")
set(KMBOX_LIB_VERSION "5.6.40")
set(KMIME_LIB_VERSION "5.6.40")
set(KPIMTEXTEDIT_LIB_VERSION "5.6.40")
set(KPIMTEXTEDIT_LIB_VERSION "5.6.41")
set(LIBKDEPIM_LIB_VERSION "5.6.40")
set(LIBKLEO_LIB_VERSION "5.6.40")
set(PIMCOMMON_LIB_VERSION "5.6.41")
......
......@@ -15,7 +15,6 @@ set(templateparser_LIB_SRCS
templatesinsertcommand.cpp
templatestextedit.cpp
templatestexteditor.cpp
templatessyntaxhighlighterrules.cpp
templatewebengineview.cpp
templatewebenginepage.cpp
templateextracthtmlelementwebengineview.cpp
......@@ -57,6 +56,7 @@ target_link_libraries(KF5TemplateParser
KF5::Libkleo
KF5::I18n
KF5::SonnetUi
KF5::SyntaxHighlighting
Qt5::WebEngineWidgets
)
set_target_properties(KF5TemplateParser PROPERTIES
......@@ -120,4 +120,4 @@ install(FILES
${PRI_FILENAME}
DESTINATION ${ECM_MKSPECS_INSTALL_DIR})
install(FILES syntax/kmail-template.xml DESTINATION ${KDE_INSTALL_DATADIR}/org.kde.syntax-highlighting/syntax)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd">
<language
name="KMail Template"
version="1"
kateversion="5.0"
section="Other"
extensions=""
author="Volker Krause (vkrause@kde.org)"
license="MIT"
hidden="true">
<highlighting>
<list name="keyword-list">
<item>%QUOTE</item>
<item>%FORCEDPLAIN</item>
<item>%FORCEDHTML</item>
<item>%QHEADERS</item>
<item>%HEADERS</item>
<item>%TEXT</item>
<item>%OTEXTSIZE</item>
<item>%OTEXT</item>
<item>%OADDRESSEESADDR</item>
<item>%CCADDR</item>
<item>%CCNAME</item>
<item>%CCFNAME</item>
<item>%CCLNAME</item>
<item>%TOADDR</item>
<item>%TONAME</item>
<item>%TOFNAME</item>
<item>%TOLNAME</item>
<item>%TOLIST</item>
<item>%FROMADDR</item>
<item>%FROMNAME</item>
<item>%FROMFNAME</item>
<item>%FROMLNAME</item>
<item>%FULLSUBJECT</item>
<item>%MSGID</item>
<item>%HEADER\\( </item>
<item>%OCCADDR</item>
<item>%OCCNAME</item>
<item>%OCCFNAME</item>
<item>%OCCLNAME</item>
<item>%OTOADDR</item>
<item>%OTONAME</item>
<item>%OTOFNAME</item>
<item>%OTOLNAME</item>
<item>%OTOLIST</item>
<item>%OTO</item>
<item>%OFROMADDR</item>
<item>%OFROMNAME</item>
<item>%OFROMFNAME</item>
<item>%OFROMLNAME</item>
<item>%OFULLSUBJECT</item>
<item>%OFULLSUBJ</item>
<item>%OMSGID</item>
<item>%DATEEN</item>
<item>%DATESHORT</item>
<item>%DATE</item>
<item>%DOW</item>
<item>%TIMELONGEN</item>
<item>%TIMELONG</item>
<item>%TIME</item>
<item>%ODATEEN</item>
<item>%ODATESHORT</item>
<item>%ODATE</item>
<item>%ODOW</item>
<item>%OTIMELONGEN</item>
<item>%OTIMELONG</item>
<item>%OTIME</item>
<item>%BLANK</item>
<item>%NOP</item>
<item>%CLEAR</item>
<item>%DEBUGOFF</item>
<item>%DEBUG</item>
<item>%CURSOR</item>
<item>%SIGNATURE</item>
</list>
<list name="function-list">
<item>%INSERT=</item>
<item>%SYSTEM=</item>
<item>%QUOTEPIPE=</item>
<item>%MSGPIPE=</item>
<item>%BODYPIPE=</item>
<item>%CLEARPIPE=</item>
<item>%TEXTPIPE=</item>
<item>%OHEADER=</item>
<item>%HEADER=</item>
<item>%DICTIONARYLANGUAGE=</item>
<item>%LANGUAGE=</item>;
</list>
<contexts>
<context name="normal-context" attribute="Normal Text" lineEndContext="#stay">
<StringDetect String="%REM=&quot;" context="comment-context" attribute="Comment"/>
<keyword attribute="Keyword" context="#stay" String="keyword-list"/>
<keyword attribute="Function" context="argument-context1" String="function-list"/>
</context>
<context name="argument-context1" attribute="Function" lineEndContext="#pop" fallThroughContext="#pop">
<DetectChar char="&quot;" context="argument-context2" attribute="String"/>
</context>
<context name="argument-context2" attribute="String" lineEndContext="#pop">
<HlCStringChar attribute="Special Character" context="#stay"/>
<DetectChar attribute="String" context="#pop" char="&quot;"/>
<LineContinue attribute="String" context="#stay"/>
</context>
<context name="comment-context" lineEndContext="#stay" attribute="Comment">
<StringDetect String="&quot;%-" attribute="Comment" context="#pop"/>
<IncludeRules context="##Alerts"/>
</context>
</contexts>
<itemDatas>
<itemData name="Normal Text" defStyleNum="dsNormal"/>
<itemData name="Keyword" defStyleNum="dsVariable" spellChecking="false"/>
<itemData name="String" defStyleNum="dsString"/>
<itemData name="Special Character" defStyleNum="dsChar" spellChecking="false"/>
<itemData name="Comment" defStyleNum="dsComment"/>
<itemData name="Function" defStyleNum="dsFunction" spellChecking="false"/>
</itemDatas>
</highlighting>
<general>
<comments>
<comment name="singleLine" start="#"/>
</comments>
<keywords casesensitive="1" weakDeliminator="%=" additionalDeliminator="&quot;"/>
</general>
</language>
/*
Copyright (c) 2015-2017 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "templatessyntaxhighlighterrules.h"
#include <QTextListFormat>
#include "templatesutil_p.h"
#include <QPalette>
#include <KPIMTextEdit/SyntaxHighlighterBase>
using namespace TemplateParser;
TemplatesSyntaxHighlighterRules::TemplatesSyntaxHighlighterRules()
{
init();
}
void TemplatesSyntaxHighlighterRules::init()
{
QTextCharFormat keywordFormat;
QPalette palette;
keywordFormat.setForeground(palette.link());
const QStringList keywords = QStringList() << Util::keywords();
for (const QString &s : keywords) {
const QRegularExpression regex(s, QRegularExpression::CaseInsensitiveOption);
mRules.append(KPIMTextEdit::Rule(regex, keywordFormat));
}
QTextCharFormat keywordWithArgsFormat;
keywordWithArgsFormat.setForeground(palette.link());
const QStringList keywordsWithArgs = Util::keywordsWithArgsForCompleter();
for (const QString &s : keywordsWithArgs) {
const QRegularExpression regex(s, QRegularExpression::CaseInsensitiveOption);
mRules.append(KPIMTextEdit::Rule(regex, keywordWithArgsFormat));
}
}
QVector<KPIMTextEdit::Rule> TemplatesSyntaxHighlighterRules::rules() const
{
return mRules;
}
/*
Copyright (c) 2015-2017 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef TEMPLATESSYNTAXHIGHLIGHTERRULES_H
#define TEMPLATESSYNTAXHIGHLIGHTERRULES_H
#include <QVector>
namespace KPIMTextEdit
{
class Rule;
}
namespace TemplateParser
{
class TemplatesSyntaxHighlighterRules
{
public:
TemplatesSyntaxHighlighterRules();
QVector<KPIMTextEdit::Rule> rules() const;
private:
void init();
QVector<KPIMTextEdit::Rule> mRules;
};
}
#endif // TEMPLATESSYNTAXHIGHLIGHTERRULES_H
......@@ -17,9 +17,12 @@
#include "templatestexteditor.h"
#include "templatesutil_p.h"
#include "templatessyntaxhighlighterrules.h"
#include <KPIMTextEdit/TextEditorCompleter>
#include <KPIMTextEdit/SyntaxHighlighterBase>
#include <KPIMTextEdit/PlainTextSyntaxSpellCheckingHighlighter>
#include <KSyntaxHighlighting/Definition>
#include <KSyntaxHighlighting/Theme>
#include <QCompleter>
#include <QKeyEvent>
......@@ -28,8 +31,6 @@
#include <QAbstractItemView>
#include <QFontDatabase>
#include <kpimtextedit/plaintextsyntaxspellcheckinghighlighter.h>
using namespace TemplateParser;
TemplatesTextEditor::TemplatesTextEditor(QWidget *parent)
......@@ -73,8 +74,10 @@ void TemplatesTextEditor::createHighlighter()
KPIMTextEdit::PlainTextSyntaxSpellCheckingHighlighter *highlighter = new KPIMTextEdit::PlainTextSyntaxSpellCheckingHighlighter(this);
highlighter->toggleSpellHighlighting(checkSpellingEnabled());
highlighter->setCurrentLanguage(spellCheckingLanguage());
TemplatesSyntaxHighlighterRules rules;
highlighter->setSyntaxHighlighterRules(rules.rules());
highlighter->setDefinition(mSyntaxRepo.definitionForName(QStringLiteral("KMail Template")));
highlighter->setTheme((palette().color(QPalette::Base).lightness() < 128)
? mSyntaxRepo.defaultTheme(KSyntaxHighlighting::Repository::DarkTheme)
: mSyntaxRepo.defaultTheme(KSyntaxHighlighting::Repository::LightTheme));
setHighlighter(highlighter);
}
......
......@@ -17,7 +17,11 @@
#ifndef TEMPLATESTEXTEDITOR_H
#define TEMPLATESTEXTEDITOR_H
#include "kpimtextedit/plaintexteditor.h"
#include <KSyntaxHighlighting/Repository>
class QKeyEvent;
namespace KPIMTextEdit
{
......@@ -42,6 +46,7 @@ protected:
void createHighlighter() override;
private:
KPIMTextEdit::TextEditorCompleter *mTextEditorCompleter = nullptr;
KSyntaxHighlighting::Repository mSyntaxRepo;
};
}
#endif // TEMPLATESTEXTEDITOR_H
......@@ -54,24 +54,6 @@ QStringList TemplateParser::Util::keywordsWithArgs()
return keywordsWithArgs;
}
QStringList TemplateParser::Util::keywordsWithArgsForCompleter()
{
const QStringList keywordsWithArgs = QStringList()
<< QStringLiteral("%REM=\".*\"%-")
<< QStringLiteral("%INSERT=\".*\"")
<< QStringLiteral("%SYSTEM=\".*\"")
<< QStringLiteral("%QUOTEPIPE=\".*\"")
<< QStringLiteral("%MSGPIPE=\".*\"")
<< QStringLiteral("%BODYPIPE=\".*\"")
<< QStringLiteral("%CLEARPIPE=\".*\"")
<< QStringLiteral("%TEXTPIPE=\".*\"")
<< QStringLiteral("%OHEADER=\".*\"")
<< QStringLiteral("%HEADER=\".*\"")
<< QStringLiteral("%DICTIONARYLANGUAGE=\".*\"")
<< QStringLiteral("%LANGUAGE=\".*\"");
return keywordsWithArgs;
}
QStringList TemplateParser::Util::keywords()
{
const QStringList keywords = QStringList()
......
......@@ -29,7 +29,6 @@ namespace Util
{
QStringList keywords();
QStringList keywordsWithArgs();
QStringList keywordsWithArgsForCompleter();
}
}
......
%REM="Default new message template"%-
%BLANK
%REM="Default reply template"%-
On %ODATE %OTIMELONG you wrote:
%QUOTE
%CURSOR
%REM="Default reply all template"%-
On %ODATE %OTIMELONG %OFROMNAME wrote:
%QUOTE
%CURSOR
%REM="Default forward template"%-
---------- Forwarded Message ----------
Subject: %OFULLSUBJECT
Date: %ODATE, %OTIMELONG
From: %OFROMADDR
%OADDRESSEESADDR
%TEXT "quoted" speling error
-----------------------------------------
%REM="Comment with alert TODO and speling error"%-
%MSGPIPE="argument \
continued"
%OHEADER="X-KMail"
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