Commit 95bf7797 authored by Laurent Montel's avatar Laurent Montel 😁

Add support for autocorrect selected text

parent cd1f6853
......@@ -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);
}
......@@ -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
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