File indexing completed on 2024-12-29 04:54:49
0001 /* 0002 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "sievescriptdebuggertextedit.h" 0008 0009 #include <KLocalizedString> 0010 0011 #include <QAction> 0012 #include <QMenu> 0013 0014 using namespace KSieveUi; 0015 0016 SieveScriptDebuggerTextEdit::SieveScriptDebuggerTextEdit(QWidget *parent) 0017 : KSieveUi::SieveTextEdit(parent) 0018 { 0019 setWordWrapMode(QTextOption::WordWrap); 0020 } 0021 0022 SieveScriptDebuggerTextEdit::~SieveScriptDebuggerTextEdit() = default; 0023 0024 void SieveScriptDebuggerTextEdit::addExtraMenuEntry(QMenu *menu, QPoint pos) 0025 { 0026 auto separator = new QAction(menu); 0027 separator->setSeparator(true); 0028 menu->addAction(separator); 0029 0030 auto addDebugAction = new QAction(i18n("Add debug here"), menu); 0031 connect(addDebugAction, &QAction::triggered, this, &SieveScriptDebuggerTextEdit::slotAddDebug); 0032 menu->addAction(addDebugAction); 0033 0034 KSieveUi::SieveTextEdit::addExtraMenuEntry(menu, pos); 0035 } 0036 0037 void SieveScriptDebuggerTextEdit::slotAddDebug() 0038 { 0039 QTextCursor cursor(textCursor()); 0040 cursor.insertText(QStringLiteral("debug_log \"DEBUG\";\n")); 0041 if (!document()->toPlainText().contains(QLatin1StringView("vnd.dovecot.debug"))) { 0042 cursor.movePosition(QTextCursor::Start); 0043 cursor.insertText(QStringLiteral("require \"vnd.dovecot.debug\";\n")); 0044 } 0045 } 0046 0047 #include "moc_sievescriptdebuggertextedit.cpp"