Commit a9699aa0 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Allow to edit specific code area

parent a1937b95
......@@ -96,6 +96,7 @@ SieveEditorTextModeWidget::SieveEditorTextModeWidget(QWidget *parent)
textEditLayout->addWidget(mTabWidget);
connect(mTextEdit, &SieveTextEdit::openHelp, mTabWidget, &SieveEditorTabWidget::slotAddHelpPage);
connect(mTextEdit, &SieveTextEdit::say, mTextToSpeechWidget, &KPIMTextEdit::TextToSpeechWidget::say);
connect(mTextEdit, &SieveTextEdit::editRule, this, &SieveEditorTextModeWidget::slotEditRule);
mGotoLineSliderContainer = new KPIMTextEdit::SlideContainer(this);
mGoToLine = new KPIMTextEdit::TextGoToLineWidget;
......@@ -223,6 +224,32 @@ void SieveEditorTextModeWidget::generateXml()
delete dlg;
}
void SieveEditorTextModeWidget::slotEditRule(const QString &selectedText)
{
const QByteArray script = selectedText.toUtf8();
KSieve::Parser parser(script.begin(),
script.begin() + script.length());
KSieveUi::XMLPrintingScriptBuilder psb(2);
parser.setScriptBuilder(&psb);
const bool result = parser.parse();
if (!result) {
//TODO
} else {
QPointer<AutoCreateScriptDialog> dlg = new AutoCreateScriptDialog(this);
dlg->setSieveCapabilities(mSieveCapabilities);
dlg->setSieveImapAccountSettings(mSieveImapAccountSettings);
dlg->setListOfIncludeFile(mListOfIncludeFile);
QString error;
//qDebug() << " psb.result()" << psb.result();
dlg->loadScript(psb.result(), error);
if (dlg->exec()) {
//set text
}
delete dlg;
}
}
void SieveEditorTextModeWidget::createRulesGraphically()
{
QPointer<AutoCreateScriptDialog> dlg = new AutoCreateScriptDialog(this);
......
......@@ -124,7 +124,7 @@ private:
void slotGoToLine(int line);
void readConfig();
void writeConfig();
bool loadFromFile(const QString &filename);
void slotEditRule(const QString &selectedText);
QString mOriginalScript;
QStringList mSieveCapabilities;
QStringList mListOfIncludeFile;
......
......@@ -38,6 +38,7 @@
#include <QMenu>
#include <QFontDatabase>
#include <QCompleter>
#include <QTextDocumentFragment>
using namespace KSieveUi;
class KSieveUi::SieveTextEditPrivate
......@@ -304,6 +305,12 @@ void SieveTextEdit::addExtraMenuEntry(QMenu *menu, QPoint pos)
connect(searchAction, &QAction::triggered, this, &SieveTextEdit::slotHelp);
menu->insertAction(menu->actions().at(0), searchAction);
}
} else {
QAction *editRules = new QAction(i18n("Edit Rule"), menu);
//editRules->setIcon(QIcon::fromTheme(QStringLiteral("help-hint")));
connect(editRules, &QAction::triggered, this, &SieveTextEdit::slotEditRule);
QAction *act = menu->addSeparator();
menu->insertActions(menu->actions().at(0), {editRules, act});
}
}
......@@ -316,6 +323,12 @@ QString SieveTextEdit::selectedWord(const QPoint &pos) const
return word;
}
void SieveTextEdit::slotEditRule()
{
QTextCursor textcursor = textCursor();
Q_EMIT editRule(textcursor.selection().toPlainText());
}
void SieveTextEdit::slotHelp()
{
QAction *act = qobject_cast<QAction *>(sender());
......
......@@ -66,16 +66,18 @@ protected:
void createHighlighter() override;
Q_SIGNALS:
void openHelp(const QUrl &url);
void editRule(const QString &selectedText);
private:
void slotUpdateLineNumberAreaWidth(int newBlockCount);
void slotUpdateLineNumberArea(const QRect &, int);
void slotHelp();
bool openVariableHelp();
void slotEditRule();
Q_REQUIRED_RESULT bool openVariableHelp();
bool overrideShortcut(QKeyEvent *event);
QStringList completerList() const;
Q_REQUIRED_RESULT QStringList completerList() const;
void setCompleterList(const QStringList &list);
QString selectedWord(const QPoint &pos = QPoint()) const;
Q_REQUIRED_RESULT QString selectedWord(const QPoint &pos = QPoint()) const;
SieveTextEditPrivate *const d;
};
......
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