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 "sievescriptdebuggerresulteditor.h" 0008 #include <KLocalizedString> 0009 #include <KStandardAction> 0010 #include <PimCommon/PimUtil> 0011 #include <QAction> 0012 #include <QMenu> 0013 0014 using namespace KSieveUi; 0015 0016 SieveScriptDebuggerResultEditor::SieveScriptDebuggerResultEditor(QWidget *parent) 0017 : TextCustomEditor::PlainTextEditor(parent) 0018 { 0019 } 0020 0021 SieveScriptDebuggerResultEditor::~SieveScriptDebuggerResultEditor() = default; 0022 0023 void SieveScriptDebuggerResultEditor::addExtraMenuEntry(QMenu *menu, QPoint pos) 0024 { 0025 TextCustomEditor::PlainTextEditor::addExtraMenuEntry(menu, pos); 0026 if (isReadOnly() && !document()->isEmpty()) { 0027 auto clearAction = new QAction(i18n("Clear"), menu); 0028 connect(clearAction, &QAction::triggered, this, &SieveScriptDebuggerResultEditor::slotClear); 0029 menu->addAction(clearAction); 0030 menu->addSeparator(); 0031 QAction *saveAsAction = KStandardAction::saveAs(this, &SieveScriptDebuggerResultEditor::slotSaveAs, this); 0032 menu->addAction(saveAsAction); 0033 } 0034 } 0035 0036 void SieveScriptDebuggerResultEditor::slotSaveAs() 0037 { 0038 const QString filter = i18n("Text Files (*.txt);;All Files (*)"); 0039 PimCommon::Util::saveTextAs(toPlainText(), filter, this); 0040 } 0041 0042 void SieveScriptDebuggerResultEditor::slotClear() 0043 { 0044 clear(); 0045 } 0046 0047 #include "moc_sievescriptdebuggerresulteditor.cpp"