diff --git a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -38,7 +38,7 @@
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")
diff --git a/templateparser/src/CMakeLists.txt b/templateparser/src/CMakeLists.txt
--- a/templateparser/src/CMakeLists.txt
+++ b/templateparser/src/CMakeLists.txt
@@ -15,7 +15,6 @@
templatesinsertcommand.cpp
templatestextedit.cpp
templatestexteditor.cpp
- templatessyntaxhighlighterrules.cpp
templatewebengineview.cpp
templatewebenginepage.cpp
templateextracthtmlelementwebengineview.cpp
@@ -57,6 +56,7 @@
KF5::Libkleo
KF5::I18n
KF5::SonnetUi
+ KF5::SyntaxHighlighting
Qt5::WebEngineWidgets
)
set_target_properties(KF5TemplateParser PROPERTIES
@@ -120,4 +120,4 @@
${PRI_FILENAME}
DESTINATION ${ECM_MKSPECS_INSTALL_DIR})
-
+install(FILES syntax/kmail-template.xml DESTINATION ${KDE_INSTALL_DATADIR}/org.kde.syntax-highlighting/syntax)
diff --git a/templateparser/src/syntax/kmail-template.xml b/templateparser/src/syntax/kmail-template.xml
new file mode 100644
--- /dev/null
+++ b/templateparser/src/syntax/kmail-template.xml
@@ -0,0 +1,130 @@
+
+
+
+
+
+ - %QUOTE
+ - %FORCEDPLAIN
+ - %FORCEDHTML
+ - %QHEADERS
+ - %HEADERS
+ - %TEXT
+ - %OTEXTSIZE
+ - %OTEXT
+ - %OADDRESSEESADDR
+ - %CCADDR
+ - %CCNAME
+ - %CCFNAME
+ - %CCLNAME
+ - %TOADDR
+ - %TONAME
+ - %TOFNAME
+ - %TOLNAME
+ - %TOLIST
+ - %FROMADDR
+ - %FROMNAME
+ - %FROMFNAME
+ - %FROMLNAME
+ - %FULLSUBJECT
+ - %MSGID
+ - %HEADER\\(
+ - %OCCADDR
+ - %OCCNAME
+ - %OCCFNAME
+ - %OCCLNAME
+ - %OTOADDR
+ - %OTONAME
+ - %OTOFNAME
+ - %OTOLNAME
+ - %OTOLIST
+ - %OTO
+ - %OFROMADDR
+ - %OFROMNAME
+ - %OFROMFNAME
+ - %OFROMLNAME
+ - %OFULLSUBJECT
+ - %OFULLSUBJ
+ - %OMSGID
+ - %DATEEN
+ - %DATESHORT
+ - %DATE
+ - %DOW
+ - %TIMELONGEN
+ - %TIMELONG
+ - %TIME
+ - %ODATEEN
+ - %ODATESHORT
+ - %ODATE
+ - %ODOW
+ - %OTIMELONGEN
+ - %OTIMELONG
+ - %OTIME
+ - %BLANK
+ - %NOP
+ - %CLEAR
+ - %DEBUGOFF
+ - %DEBUG
+ - %CURSOR
+ - %SIGNATURE
+
+
+ - %INSERT=
+ - %SYSTEM=
+ - %QUOTEPIPE=
+ - %MSGPIPE=
+ - %BODYPIPE=
+ - %CLEARPIPE=
+ - %TEXTPIPE=
+ - %OHEADER=
+ - %HEADER=
+ - %DICTIONARYLANGUAGE=
+ - %LANGUAGE=
;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/templateparser/src/templatessyntaxhighlighterrules.h b/templateparser/src/templatessyntaxhighlighterrules.h
deleted file mode 100644
--- a/templateparser/src/templatessyntaxhighlighterrules.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- Copyright (c) 2015-2017 Montel Laurent
-
- 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
-namespace KPIMTextEdit
-{
-class Rule;
-}
-
-namespace TemplateParser
-{
-class TemplatesSyntaxHighlighterRules
-{
-public:
- TemplatesSyntaxHighlighterRules();
- QVector rules() const;
-
-private:
- void init();
- QVector mRules;
-};
-}
-
-#endif // TEMPLATESSYNTAXHIGHLIGHTERRULES_H
diff --git a/templateparser/src/templatessyntaxhighlighterrules.cpp b/templateparser/src/templatessyntaxhighlighterrules.cpp
deleted file mode 100644
--- a/templateparser/src/templatessyntaxhighlighterrules.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- Copyright (c) 2015-2017 Montel Laurent
-
- 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
-#include "templatesutil_p.h"
-#include
-#include
-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 TemplatesSyntaxHighlighterRules::rules() const
-{
- return mRules;
-}
-
diff --git a/templateparser/src/templatestexteditor.h b/templateparser/src/templatestexteditor.h
--- a/templateparser/src/templatestexteditor.h
+++ b/templateparser/src/templatestexteditor.h
@@ -17,7 +17,11 @@
#ifndef TEMPLATESTEXTEDITOR_H
#define TEMPLATESTEXTEDITOR_H
+
#include "kpimtextedit/plaintexteditor.h"
+
+#include
+
class QKeyEvent;
namespace KPIMTextEdit
{
@@ -42,6 +46,7 @@
void createHighlighter() override;
private:
KPIMTextEdit::TextEditorCompleter *mTextEditorCompleter = nullptr;
+ KSyntaxHighlighting::Repository mSyntaxRepo;
};
}
#endif // TEMPLATESTEXTEDITOR_H
diff --git a/templateparser/src/templatestexteditor.cpp b/templateparser/src/templatestexteditor.cpp
--- a/templateparser/src/templatestexteditor.cpp
+++ b/templateparser/src/templatestexteditor.cpp
@@ -17,19 +17,20 @@
#include "templatestexteditor.h"
#include "templatesutil_p.h"
-#include "templatessyntaxhighlighterrules.h"
+
#include
-#include
+#include
+
+#include
+#include
#include
#include
#include
#include
#include
#include
-#include
-
using namespace TemplateParser;
TemplatesTextEditor::TemplatesTextEditor(QWidget *parent)
@@ -73,8 +74,10 @@
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);
}
diff --git a/templateparser/src/templatesutil.cpp b/templateparser/src/templatesutil.cpp
--- a/templateparser/src/templatesutil.cpp
+++ b/templateparser/src/templatesutil.cpp
@@ -54,24 +54,6 @@
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()
diff --git a/templateparser/src/templatesutil_p.h b/templateparser/src/templatesutil_p.h
--- a/templateparser/src/templatesutil_p.h
+++ b/templateparser/src/templatesutil_p.h
@@ -29,7 +29,6 @@
{
QStringList keywords();
QStringList keywordsWithArgs();
-QStringList keywordsWithArgsForCompleter();
}
}
diff --git a/templateparser/tests/syntax-test.template b/templateparser/tests/syntax-test.template
new file mode 100644
--- /dev/null
+++ b/templateparser/tests/syntax-test.template
@@ -0,0 +1,31 @@
+%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"