1 | /* |
2 | SPDX-FileCopyrightText: 2008-2009 Michel Ludwig <michel.ludwig@kdemail.net> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #ifndef SPELLCHECK_H |
8 | #define SPELLCHECK_H |
9 | |
10 | #include <QList> |
11 | #include <QObject> |
12 | #include <QPair> |
13 | #include <QString> |
14 | |
15 | #include <ktexteditor/document.h> |
16 | #include <sonnet/backgroundchecker.h> |
17 | #include <sonnet/speller.h> |
18 | |
19 | namespace KTextEditor |
20 | { |
21 | class DocumentPrivate; |
22 | } |
23 | |
24 | class KateSpellCheckManager : public QObject |
25 | { |
26 | Q_OBJECT |
27 | |
28 | typedef QPair<KTextEditor::Range, QString> RangeDictionaryPair; |
29 | |
30 | public: |
31 | explicit KateSpellCheckManager(QObject *parent = nullptr); |
32 | ~KateSpellCheckManager() override; |
33 | |
34 | static QStringList suggestions(const QString &word, const QString &dictionary); |
35 | |
36 | void ignoreWord(const QString &word, const QString &dictionary); |
37 | void addToDictionary(const QString &word, const QString &dictionary); |
38 | |
39 | /** |
40 | * 'r2' is a subrange of 'r1', which is extracted from 'r1' and the remaining ranges are returned |
41 | **/ |
42 | static QList<KTextEditor::Range> rangeDifference(KTextEditor::Range r1, KTextEditor::Range r2); |
43 | |
44 | Q_SIGNALS: |
45 | /** |
46 | * These signals are used to propagate the dictionary changes to the |
47 | * BackgroundChecker instance in other components (e.g. onTheFlyChecker). |
48 | */ |
49 | void wordAddedToDictionary(const QString &word); |
50 | void wordIgnored(const QString &word); |
51 | |
52 | public: |
53 | static QList<QPair<KTextEditor::Range, QString>> spellCheckLanguageRanges(KTextEditor::DocumentPrivate *doc, KTextEditor::Range range); |
54 | |
55 | QList<QPair<KTextEditor::Range, QString>> spellCheckWrtHighlightingRanges(KTextEditor::DocumentPrivate *doc, |
56 | KTextEditor::Range range, |
57 | const QString &dictionary = QString(), |
58 | bool singleLine = false, |
59 | bool returnSingleRange = false); |
60 | QList<QPair<KTextEditor::Range, QString>> spellCheckRanges(KTextEditor::DocumentPrivate *doc, KTextEditor::Range range, bool singleLine = false); |
61 | |
62 | static void replaceCharactersEncodedIfNecessary(const QString &newWord, KTextEditor::DocumentPrivate *doc, KTextEditor::Range replacementRange); |
63 | |
64 | private: |
65 | static void trimRange(KTextEditor::DocumentPrivate *doc, KTextEditor::Range &r); |
66 | }; |
67 | |
68 | #endif |
69 | |