1 | /* |
2 | SPDX-FileCopyrightText: 2009-2018 Dominik Haumann <dhaumann@kde.org> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #ifndef KATE_COMMANDLINE_SCRIPT_H |
8 | #define KATE_COMMANDLINE_SCRIPT_H |
9 | |
10 | #include "katescript.h" |
11 | |
12 | #include <KTextEditor/Command> |
13 | |
14 | #include <QJsonArray> |
15 | |
16 | namespace KTextEditor |
17 | { |
18 | class View; |
19 | } |
20 | |
21 | class KateCommandLineScriptHeader |
22 | { |
23 | public: |
24 | KateCommandLineScriptHeader() |
25 | { |
26 | } |
27 | |
28 | inline void setFunctions(const QStringList &functions) |
29 | { |
30 | m_functions = functions; |
31 | } |
32 | inline const QStringList &functions() const |
33 | { |
34 | return m_functions; |
35 | } |
36 | |
37 | inline void setActions(const QJsonArray &actions) |
38 | { |
39 | m_actions = actions; |
40 | } |
41 | inline const QJsonArray &actions() const |
42 | { |
43 | return m_actions; |
44 | } |
45 | |
46 | private: |
47 | QStringList m_functions; ///< the functions the script contains |
48 | QJsonArray m_actions; ///< the action for this script |
49 | }; |
50 | |
51 | /** |
52 | * A specialized class for scripts that are of type ScriptType::Indentation. |
53 | */ |
54 | class KateCommandLineScript : public KateScript, public KTextEditor::Command |
55 | { |
56 | public: |
57 | KateCommandLineScript(const QString &url, const KateCommandLineScriptHeader &); |
58 | |
59 | const KateCommandLineScriptHeader &commandHeader(); |
60 | |
61 | bool callFunction(const QString &cmd, const QStringList &args, QString &errorMessage); |
62 | |
63 | // |
64 | // KTextEditor::Command interface |
65 | // |
66 | public: |
67 | bool help(KTextEditor::View *view, const QString &cmd, QString &msg) override; |
68 | bool exec(KTextEditor::View *view, const QString &cmd, QString &msg, const KTextEditor::Range &range = KTextEditor::Range::invalid()) override; |
69 | bool supportsRange(const QString &cmd) override; |
70 | |
71 | private: |
72 | KateCommandLineScriptHeader m_commandHeader; |
73 | }; |
74 | |
75 | #endif |
76 | |