1 | /* |
2 | SPDX-FileCopyrightText: 2001-2010 Christoph Cullmann <cullmann@kde.org> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #ifndef _KATE_CMD_H |
8 | #define _KATE_CMD_H |
9 | |
10 | #include <KCompletion> |
11 | |
12 | #include <QHash> |
13 | #include <QStringList> |
14 | |
15 | namespace KTextEditor |
16 | { |
17 | class Command; |
18 | } |
19 | |
20 | class KateCmd |
21 | { |
22 | public: |
23 | KateCmd(); |
24 | ~KateCmd(); |
25 | |
26 | static KateCmd *self(); |
27 | |
28 | bool registerCommand(KTextEditor::Command *cmd); |
29 | bool unregisterCommand(KTextEditor::Command *cmd); |
30 | KTextEditor::Command *queryCommand(const QString &cmd) const; |
31 | QList<KTextEditor::Command *> commands() const; |
32 | QStringList commandList() const; |
33 | |
34 | QStringList cmds(); |
35 | void appendHistory(const QString &cmd); |
36 | const QString fromHistory(int i) const; |
37 | uint historyLength() const |
38 | { |
39 | return m_history.count(); |
40 | } |
41 | |
42 | KCompletion *commandCompletionObject(); |
43 | |
44 | private: |
45 | QHash<QString, KTextEditor::Command *> m_dict; |
46 | QStringList m_cmds; |
47 | QStringList m_history; |
48 | KCompletion m_cmdCompletion; // shared completion object for all KateCmdLineEdits in each KTE::View |
49 | }; |
50 | |
51 | /** |
52 | * A KCompletion object that completes last ?unquoted? word in the string |
53 | * passed. Do not mistake "shell" for anything related to quoting, this |
54 | * simply mimics shell tab completion by completing the last word in the |
55 | * provided text. |
56 | */ |
57 | class KateCmdShellCompletion : public KCompletion |
58 | { |
59 | public: |
60 | KateCmdShellCompletion(); |
61 | |
62 | /** |
63 | * Finds completions to the given text. |
64 | * The first match is returned and emitted in the signal match(). |
65 | * @param text the text to complete |
66 | * @return the first match, or QString() if not found |
67 | */ |
68 | QString makeCompletion(const QString &text) override; |
69 | |
70 | protected: |
71 | // Called by KCompletion |
72 | void postProcessMatch(QString *match) const override; |
73 | void postProcessMatches(QStringList *matches) const override; |
74 | void postProcessMatches(KCompletionMatches *matches) const override; |
75 | |
76 | private: |
77 | /** |
78 | * Split text at the last unquoted space |
79 | * |
80 | * @param text_start will be set to the text at the left, including the space |
81 | * @param text_compl Will be set to the text at the right. This is the text to complete. |
82 | */ |
83 | void splitText(const QString &text, QString &text_start, QString &text_compl) const; |
84 | |
85 | QChar m_word_break_char; |
86 | QChar m_quote_char1; |
87 | QChar m_quote_char2; |
88 | QChar m_escape_char; |
89 | |
90 | QString m_text_start; |
91 | QString m_text_compl; |
92 | }; |
93 | |
94 | #endif |
95 | |