File indexing completed on 2024-04-14 03:55:19

0001 /*
0002     SPDX-FileCopyrightText: 2009-2018 Dominik Haumann <dhaumann@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KATE_COMMANDLINE_SCRIPT_H
0008 #define KATE_COMMANDLINE_SCRIPT_H
0009 
0010 #include "katescript.h"
0011 
0012 #include <KTextEditor/Command>
0013 
0014 #include <QJsonArray>
0015 
0016 namespace KTextEditor
0017 {
0018 class View;
0019 }
0020 
0021 class KateCommandLineScriptHeader
0022 {
0023 public:
0024     KateCommandLineScriptHeader()
0025     {
0026     }
0027 
0028     inline void setFunctions(const QStringList &functions)
0029     {
0030         m_functions = functions;
0031     }
0032     inline const QStringList &functions() const
0033     {
0034         return m_functions;
0035     }
0036 
0037     inline void setActions(const QJsonArray &actions)
0038     {
0039         m_actions = actions;
0040     }
0041     inline const QJsonArray &actions() const
0042     {
0043         return m_actions;
0044     }
0045 
0046 private:
0047     QStringList m_functions; ///< the functions the script contains
0048     QJsonArray m_actions; ///< the action for this script
0049 };
0050 
0051 /**
0052  * A specialized class for scripts that are of type ScriptType::Indentation.
0053  */
0054 class KateCommandLineScript : public KateScript, public KTextEditor::Command
0055 {
0056 public:
0057     KateCommandLineScript(const QString &url, const KateCommandLineScriptHeader &header);
0058 
0059     const KateCommandLineScriptHeader &commandHeader();
0060 
0061     bool callFunction(const QString &cmd, const QStringList &args, QString &errorMessage);
0062 
0063     //
0064     // KTextEditor::Command interface
0065     //
0066 public:
0067     bool help(KTextEditor::View *view, const QString &cmd, QString &msg) override;
0068     bool exec(KTextEditor::View *view, const QString &cmd, QString &msg, const KTextEditor::Range &range = KTextEditor::Range::invalid()) override;
0069     bool supportsRange(const QString &cmd) override;
0070 
0071 private:
0072     KateCommandLineScriptHeader m_commandHeader;
0073 };
0074 
0075 #endif