1 | /* |
2 | SPDX-FileCopyrightText: 2003 Anders Lund <anders.lund@lund.tdcadsl.dk> |
3 | SPDX-FileCopyrightText: 2010 Christoph Cullmann <cullmann@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-or-later |
6 | */ |
7 | |
8 | #ifndef _KateWordCompletion_h_ |
9 | #define _KateWordCompletion_h_ |
10 | |
11 | #include <ktexteditor/codecompletionmodel.h> |
12 | #include <ktexteditor/codecompletionmodelcontrollerinterface.h> |
13 | #include <ktexteditor/view.h> |
14 | |
15 | #include <QEvent> |
16 | #include <QList> |
17 | #include <QObject> |
18 | |
19 | #include "katepartdebug.h" |
20 | #include <ktexteditor_export.h> |
21 | |
22 | class KateWordCompletionModel : public KTextEditor::CodeCompletionModel, public KTextEditor::CodeCompletionModelControllerInterface |
23 | { |
24 | Q_OBJECT |
25 | Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface) |
26 | public: |
27 | KTEXTEDITOR_EXPORT explicit KateWordCompletionModel(QObject *parent); |
28 | KTEXTEDITOR_EXPORT ~KateWordCompletionModel() override; |
29 | |
30 | /** |
31 | * This function is responsible to generating / updating the list of current |
32 | * completions. The default implementation does nothing. |
33 | * |
34 | * When implementing this function, remember to call setRowCount() (or implement |
35 | * rowCount()), and to generate the appropriate change notifications (for instance |
36 | * by calling QAbstractItemModel::reset()). |
37 | * @param view The view to generate completions for |
38 | * @param range The range of text to generate completions for |
39 | * */ |
40 | void completionInvoked(KTextEditor::View *view, const KTextEditor::Range &range, InvocationType invocationType) override; |
41 | |
42 | bool shouldStartCompletion(KTextEditor::View *view, const QString &insertedText, bool userInsertion, const KTextEditor::Cursor &position) override; |
43 | bool shouldAbortCompletion(KTextEditor::View *view, const KTextEditor::Range &range, const QString ¤tCompletion) override; |
44 | |
45 | void saveMatches(KTextEditor::View *view, const KTextEditor::Range &range); |
46 | |
47 | int rowCount(const QModelIndex &parent) const override; |
48 | |
49 | QVariant data(const QModelIndex &index, int role) const override; |
50 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; |
51 | QModelIndex parent(const QModelIndex &index) const override; |
52 | MatchReaction matchingItem(const QModelIndex &matched) override; |
53 | |
54 | bool shouldHideItemsWithEqualNames() const override; |
55 | |
56 | KTEXTEDITOR_EXPORT QStringList allMatches(KTextEditor::View *view, const KTextEditor::Range &range); |
57 | |
58 | void executeCompletionItem(KTextEditor::View *view, const KTextEditor::Range &word, const QModelIndex &index) const override; |
59 | |
60 | private: |
61 | QStringList m_matches; |
62 | bool m_automatic; |
63 | }; |
64 | |
65 | class KateWordCompletionView : public QObject |
66 | { |
67 | public: |
68 | KateWordCompletionView(KTextEditor::View *view, KActionCollection *ac); |
69 | ~KateWordCompletionView() override; |
70 | |
71 | private: |
72 | void completeBackwards(); |
73 | void completeForwards(); |
74 | void slotCursorMoved(); |
75 | |
76 | void shellComplete(); |
77 | |
78 | void (); |
79 | |
80 | private: |
81 | void complete(bool fw = true); |
82 | |
83 | QString word() const; |
84 | KTextEditor::Range range() const; |
85 | |
86 | static QString findLongestUnique(const QStringList &matches, int lead); |
87 | |
88 | KTextEditor::View *m_view; |
89 | KateWordCompletionModel *m_dWCompletionModel; |
90 | struct KateWordCompletionViewPrivate *d; |
91 | }; |
92 | |
93 | #endif // _DocWordCompletionPlugin_h_ |
94 | |