Commit 17d441b6 authored by Laurent Montel's avatar Laurent Montel 😁

Fix comment after true/false condition

parent 52b8bbea
#SCRIPTNAME: Script part 0
if false # allof(not header :contains "X-Spam-Flag" "YES")
{
}
#SCRIPTNAME: Script part 1
if true # allof(not header :contains "X-Spam-Flag" "YES")
{
}
\ No newline at end of file
if false # allof(not header :contains "X-Spam-Flag" "YES")
{
}
if true # allof(not header :contains "X-Spam-Flag" "YES")
{
}
......@@ -208,6 +208,7 @@ void SieveEditorGraphicalModeWidgetTest::shouldLoadScripts_data()
QTest::newRow("test-comment6") << QStringLiteral("test-comment6") << false << true;
QTest::newRow("test-comment7") << QStringLiteral("test-comment7") << false << true;
QTest::newRow("test-comment8") << QStringLiteral("test-comment8") << false << true;
QTest::newRow("test-comment9") << QStringLiteral("test-comment9") << false << true;
}
QTEST_MAIN(SieveEditorGraphicalModeWidgetTest)
......@@ -18,11 +18,14 @@
*/
#include "sieveconditionfalse.h"
#include "editor/sieveeditorutil.h"
#include "libksieve_debug.h"
#include "autocreatescripts/autocreatescriptutil_p.h"
#include <KLocalizedString>
#include <QHBoxLayout>
#include <QLabel>
#include <QDomNode>
using namespace KSieveUi;
......@@ -45,7 +48,7 @@ QWidget *SieveConditionFalse::createParamWidget(QWidget *parent) const
QString SieveConditionFalse::code(QWidget *) const
{
return QStringLiteral("false");
return QStringLiteral("false") + AutoCreateScriptUtil::generateConditionComment(comment());
}
QString SieveConditionFalse::help() const
......@@ -53,9 +56,29 @@ QString SieveConditionFalse::help() const
return i18n("The \"false\" test always evaluates to false.");
}
bool SieveConditionFalse::setParamWidgetValue(const QDomElement &, QWidget *, bool, QString &)
bool SieveConditionFalse::setParamWidgetValue(const QDomElement &element, QWidget *, bool, QString &error)
{
//Nothing
QDomNode node = element.firstChild();
QString commentStr;
while (!node.isNull()) {
QDomElement e = node.toElement();
if (!e.isNull()) {
const QString tagName = e.tagName();
if (tagName == QLatin1String("comment")) {
commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, e.text());
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else {
unknownTag(tagName, error);
qCDebug(LIBKSIEVE_LOG) << " SieveConditionFalse::setParamWidgetValue unknown tagName " << tagName;
}
}
node = node.nextSibling();
}
if (!commentStr.isEmpty()) {
setComment(commentStr);
}
return true;
}
......
......@@ -18,8 +18,12 @@
*/
#include "sieveconditiontrue.h"
#include "editor/sieveeditorutil.h"
#include "libksieve_debug.h"
#include "autocreatescripts/autocreatescriptutil_p.h"
#include <KLocalizedString>
#include <QDomNode>
#include <QHBoxLayout>
#include <QLabel>
......@@ -44,7 +48,7 @@ QWidget *SieveConditionTrue::createParamWidget(QWidget *parent) const
QString SieveConditionTrue::code(QWidget *) const
{
return QStringLiteral("true");
return QStringLiteral("true") + AutoCreateScriptUtil::generateConditionComment(comment());
}
QString SieveConditionTrue::help() const
......@@ -52,9 +56,29 @@ QString SieveConditionTrue::help() const
return i18n("The \"true\" test always evaluates to true.");
}
bool SieveConditionTrue::setParamWidgetValue(const QDomElement &, QWidget *, bool, QString &)
bool SieveConditionTrue::setParamWidgetValue(const QDomElement &element, QWidget *, bool, QString &error)
{
//Nothing
QDomNode node = element.firstChild();
QString commentStr;
while (!node.isNull()) {
QDomElement e = node.toElement();
if (!e.isNull()) {
const QString tagName = e.tagName();
if (tagName == QLatin1String("comment")) {
commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, e.text());
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else {
unknownTag(tagName, error);
qCDebug(LIBKSIEVE_LOG) << " SieveConditionTrue::setParamWidgetValue unknown tagName " << tagName;
}
}
node = node.nextSibling();
}
if (!commentStr.isEmpty()) {
setComment(commentStr);
}
return true;
}
......
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