Commit 451363da authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Allow to insert rule where we want

parent 00db14c1
...@@ -98,6 +98,7 @@ SieveEditorTextModeWidget::SieveEditorTextModeWidget(QWidget *parent) ...@@ -98,6 +98,7 @@ SieveEditorTextModeWidget::SieveEditorTextModeWidget(QWidget *parent)
connect(mTextEdit, &SieveTextEdit::openHelp, mTabWidget, &SieveEditorTabWidget::slotAddHelpPage); connect(mTextEdit, &SieveTextEdit::openHelp, mTabWidget, &SieveEditorTabWidget::slotAddHelpPage);
connect(mTextEdit, &SieveTextEdit::say, mTextToSpeechWidget, &KPIMTextEdit::TextToSpeechWidget::say); connect(mTextEdit, &SieveTextEdit::say, mTextToSpeechWidget, &KPIMTextEdit::TextToSpeechWidget::say);
connect(mTextEdit, &SieveTextEdit::editRule, this, &SieveEditorTextModeWidget::slotEditRule); connect(mTextEdit, &SieveTextEdit::editRule, this, &SieveEditorTextModeWidget::slotEditRule);
connect(mTextEdit, &SieveTextEdit::insertRule, this, &SieveEditorTextModeWidget::slotInsertRule);
mGotoLineSliderContainer = new KPIMTextEdit::SlideContainer(this); mGotoLineSliderContainer = new KPIMTextEdit::SlideContainer(this);
mGoToLine = new KPIMTextEdit::TextGoToLineWidget; mGoToLine = new KPIMTextEdit::TextGoToLineWidget;
...@@ -252,6 +253,20 @@ void SieveEditorTextModeWidget::slotEditRule(const QString &selectedText) ...@@ -252,6 +253,20 @@ void SieveEditorTextModeWidget::slotEditRule(const QString &selectedText)
} }
} }
void SieveEditorTextModeWidget::slotInsertRule()
{
QPointer<AutoCreateScriptDialog> dlg = new AutoCreateScriptDialog(this);
dlg->setSieveCapabilities(mSieveCapabilities);
dlg->setSieveImapAccountSettings(mSieveImapAccountSettings);
dlg->setListOfIncludeFile(mListOfIncludeFile);
if (dlg->exec()) {
QString requireModules;
const QString newScript = dlg->script(requireModules);
mTextEdit->insertPlainText(newScript);
}
delete dlg;
}
void SieveEditorTextModeWidget::createRulesGraphically() void SieveEditorTextModeWidget::createRulesGraphically()
{ {
QPointer<AutoCreateScriptDialog> dlg = new AutoCreateScriptDialog(this); QPointer<AutoCreateScriptDialog> dlg = new AutoCreateScriptDialog(this);
......
...@@ -125,6 +125,7 @@ private: ...@@ -125,6 +125,7 @@ private:
void readConfig(); void readConfig();
void writeConfig(); void writeConfig();
void slotEditRule(const QString &selectedText); void slotEditRule(const QString &selectedText);
void slotInsertRule();
QString mOriginalScript; QString mOriginalScript;
QStringList mSieveCapabilities; QStringList mSieveCapabilities;
QStringList mListOfIncludeFile; QStringList mListOfIncludeFile;
......
...@@ -291,6 +291,12 @@ void SieveTextEdit::addExtraMenuEntry(QMenu *menu, QPoint pos) ...@@ -291,6 +291,12 @@ void SieveTextEdit::addExtraMenuEntry(QMenu *menu, QPoint pos)
} }
if (!textCursor().hasSelection()) { if (!textCursor().hasSelection()) {
QAction *insertRules = new QAction(i18n("Insert Rule"), menu);
//editRules->setIcon(QIcon::fromTheme(QStringLiteral("help-hint")));
connect(insertRules, &QAction::triggered, this, &SieveTextEdit::insertRule);
QAction *act = menu->addSeparator();
menu->insertActions(menu->actions().at(0), {insertRules, act});
const QString word = selectedWord(pos); const QString word = selectedWord(pos);
const KSieveUi::SieveEditorUtil::HelpVariableName type = KSieveUi::SieveEditorUtil::strToVariableName(word); const KSieveUi::SieveEditorUtil::HelpVariableName type = KSieveUi::SieveEditorUtil::strToVariableName(word);
if (type != KSieveUi::SieveEditorUtil::UnknownHelp) { if (type != KSieveUi::SieveEditorUtil::UnknownHelp) {
......
...@@ -67,6 +67,7 @@ protected: ...@@ -67,6 +67,7 @@ protected:
Q_SIGNALS: Q_SIGNALS:
void openHelp(const QUrl &url); void openHelp(const QUrl &url);
void editRule(const QString &selectedText); void editRule(const QString &selectedText);
void insertRule();
private: private:
void slotUpdateLineNumberAreaWidth(int newBlockCount); void slotUpdateLineNumberAreaWidth(int newBlockCount);
......
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