summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-08-26 11:59:58 (GMT)
committerMontel Laurent <montel@kde.org>2016-08-26 11:59:58 (GMT)
commit95bf7797141f720f3e80e1cf5ba08807246cd9f5 (patch)
tree87bf7ed2ebd2a5252cfbd8c089b83f68dfb076cf
parentcd1f68534a2aba4577f7c1e5f73f1a06bf04605f (diff)
Add support for autocorrect selected text
-rw-r--r--kmail/editorplugins/autocorrection/autocorrectionplugineditorinterface.cpp30
-rw-r--r--kmail/editorplugins/autocorrection/autocorrectionplugineditorinterface.h6
2 files changed, 27 insertions, 9 deletions
diff --git a/kmail/editorplugins/autocorrection/autocorrectionplugineditorinterface.cpp b/kmail/editorplugins/autocorrection/autocorrectionplugineditorinterface.cpp
index e1db7fb..78092a0 100644
--- a/kmail/editorplugins/autocorrection/autocorrectionplugineditorinterface.cpp
+++ b/kmail/editorplugins/autocorrection/autocorrectionplugineditorinterface.cpp
@@ -22,9 +22,11 @@
#include <KLocalizedString>
#include <KActionCollection>
#include <QAction>
+#include <KActionMenu>
AutoCorrectionPluginEditorInterface::AutoCorrectionPluginEditorInterface(QObject *parent)
- : MessageComposer::PluginEditorInterface(parent)
+ : MessageComposer::PluginEditorInterface(parent),
+ mSelectedText(false)
{
}
@@ -35,19 +37,33 @@ AutoCorrectionPluginEditorInterface::~AutoCorrectionPluginEditorInterface()
void AutoCorrectionPluginEditorInterface::createAction(KActionCollection *ac)
{
- QAction *action = new QAction(i18n("Autocorrect Text"), this);
- ac->addAction(QStringLiteral("autocorrect_tool"), action);
- connect(action, &QAction::triggered, this, &AutoCorrectionPluginEditorInterface::slotActivated);
- MessageComposer::ActionType type(action, MessageComposer::ActionType::Tools);
+ KActionMenu *menu = new KActionMenu(i18n("Autocorrect Text"), this);
+ ac->addAction(QStringLiteral("autocorrect_tool"), menu);
+ MessageComposer::ActionType type(menu, MessageComposer::ActionType::Tools);
setActionType(type);
+
+ QAction *action = new QAction(i18n("Autocorrect Text"), this);
+ menu->addAction(action);
+ connect(action, &QAction::triggered, this, &AutoCorrectionPluginEditorInterface::slotAutoCorrectAllText);
+
+ action = new QAction(i18n("Autocorrect Selected Text"), this);
+ menu->addAction(action);
+ connect(action, &QAction::triggered, this, &AutoCorrectionPluginEditorInterface::slotAutoCorrectSelectedText);
+}
+
+void AutoCorrectionPluginEditorInterface::slotAutoCorrectSelectedText()
+{
+ mSelectedText = true;
+ Q_EMIT emitPluginActivated(this);
}
-void AutoCorrectionPluginEditorInterface::slotActivated()
+void AutoCorrectionPluginEditorInterface::slotAutoCorrectAllText()
{
+ mSelectedText = false;
Q_EMIT emitPluginActivated(this);
}
void AutoCorrectionPluginEditorInterface::exec()
{
- richTextEditor()->forceAutoCorrection();
+ richTextEditor()->forceAutoCorrection(mSelectedText);
}
diff --git a/kmail/editorplugins/autocorrection/autocorrectionplugineditorinterface.h b/kmail/editorplugins/autocorrection/autocorrectionplugineditorinterface.h
index 6fcb8be..f26c7e7 100644
--- a/kmail/editorplugins/autocorrection/autocorrectionplugineditorinterface.h
+++ b/kmail/editorplugins/autocorrection/autocorrectionplugineditorinterface.h
@@ -33,8 +33,10 @@ public:
void createAction(KActionCollection *ac) Q_DECL_OVERRIDE;
void exec() Q_DECL_OVERRIDE;
-private Q_SLOTS:
- void slotActivated();
+private:
+ void slotAutoCorrectAllText();
+ void slotAutoCorrectSelectedText();
+ bool mSelectedText;
};
#endif