Commit 66eb115a authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

[spellcheck runner] Make each suggestion copyable as separate item

Summary:
Before all suggestions are only shown as single item with a text of
comma-separated terms. So one cannot select a single suggested term and e.g.
copy it to the clipboard

And if correct term, the term is not copyable directly as well.

Test Plan:
Activate spellcheck runner (disabled by default), enter
"spell Compilcated" or similar
and select spellchecker menu items.

Reviewers: broulik

Reviewed By: broulik

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D10499
parent 617099d1
......@@ -18,13 +18,22 @@
#include "spellcheck.h"
#include <QGuiApplication>
#include <QClipboard>
#include <QDebug>
#include <QLocale>
#include <QSet>
#include <QIcon>
#include <QMimeData>
#include <KLocalizedString>
namespace {
namespace ActionIds {
inline QString copyToClipboard() { return QStringLiteral("copyToClipboard"); }
}
}
SpellCheckRunner::SpellCheckRunner(QObject* parent, const QVariantList &args)
: Plasma::AbstractRunner(parent, args)
{
......@@ -32,6 +41,8 @@ SpellCheckRunner::SpellCheckRunner(QObject* parent, const QVariantList &args)
setObjectName(QLatin1String( "Spell Checker" ));
setIgnoredTypes(Plasma::RunnerContext::FileSystem | Plasma::RunnerContext::NetworkLocation);
setSpeed(AbstractRunner::SlowSpeed);
addAction(ActionIds::copyToClipboard(), QIcon::fromTheme(QStringLiteral("edit-copy")), i18n("Copy to Clipboard"));
}
SpellCheckRunner::~SpellCheckRunner()
......@@ -213,36 +224,60 @@ void SpellCheckRunner::match(Plasma::RunnerContext &context)
return;
}
Plasma::QueryMatch match(this);
match.setType(Plasma::QueryMatch::InformationalMatch);
if (speller->isValid()) {
QStringList suggestions;
const bool correct = speller->checkAndSuggest(query,suggestions);
if (correct) {
Plasma::QueryMatch match(this);
match.setType(Plasma::QueryMatch::InformationalMatch);
match.setIconName(QStringLiteral("checkbox"));
match.setText(i18n("Correct")+QLatin1String(": ")+query);
match.setText(query);
match.setSubtext(i18nc("Term is spelled correctly", "Correct"));
match.setData(query);
context.addMatch(match);
} else {
match.setIconName(QStringLiteral("edit-delete"));
const QString recommended = i18n("Suggested words: %1", suggestions.join(i18nc("separator for a list of words", ", ")));
//TODO: try setting a text and a subtext, with the subtext being the suggestions
match.setText(recommended);
match.setData(suggestions);
for (const auto& suggestion : qAsConst(suggestions)) {
Plasma::QueryMatch match(this);
match.setType(Plasma::QueryMatch::InformationalMatch);
match.setIconName(QStringLiteral("edit-rename"));
match.setText(suggestion);
match.setSubtext(i18n("Suggested term"));
match.setData(suggestion);
context.addMatch(match);
}
}
} else {
Plasma::QueryMatch match(this);
match.setType(Plasma::QueryMatch::InformationalMatch);
match.setIconName(QStringLiteral("task-attention"));
match.setText(i18n("Could not find a dictionary."));
context.addMatch(match);
}
context.addMatch(match);
}
void SpellCheckRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match)
{
Q_UNUSED(context)
//Copy words to clipboard
// FIXME:
// kapp->clipboard()->setText(match.data().toString());
if (match.selectedAction() == action(ActionIds::copyToClipboard())) {
//Copy words to clipboard
const QString text = match.data().toString();
QGuiApplication::clipboard()->setText(text);
}
}
QList<QAction *> SpellCheckRunner::actionsForMatch(const Plasma::QueryMatch &match)
{
Q_UNUSED(match)
return {action(ActionIds::copyToClipboard())};
}
QMimeData * SpellCheckRunner::mimeDataForMatch(const Plasma::QueryMatch &match)
{
QMimeData *result = new QMimeData();
const QString text = match.data().toString();
result->setText(text);
return result;
}
K_EXPORT_PLASMA_RUNNER(krunner_spellcheck, SpellCheckRunner)
......
......@@ -42,6 +42,9 @@ public:
protected Q_SLOTS:
void init() override;
QList<QAction *> actionsForMatch(const Plasma::QueryMatch &match) override;
QMimeData * mimeDataForMatch(const Plasma::QueryMatch &match) override;
void loaddata();
void destroydata();
......
Supports Markdown
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