File indexing completed on 2024-04-21 03:57:37

0001 /*
0002     SPDX-FileCopyrightText: 2008 Paul Giannaros <paul@giannaros.org>
0003     SPDX-FileCopyrightText: 2009-2018 Dominik Haumann <dhaumann@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KATE_INDENT_SCRIPT_H
0009 #define KATE_INDENT_SCRIPT_H
0010 
0011 #include "katescript.h"
0012 
0013 #include <KTextEditor/Cursor>
0014 
0015 namespace KTextEditor
0016 {
0017 class ViewPrivate;
0018 }
0019 
0020 class KateIndentScriptHeader
0021 {
0022 public:
0023     KateIndentScriptHeader() = default;
0024 
0025     inline void setName(const QString &name)
0026     {
0027         m_name = name;
0028     }
0029     inline const QString &name() const
0030     {
0031         return m_name;
0032     }
0033 
0034     inline void setRequiredStyle(const QString &requiredStyle)
0035     {
0036         m_requiredStyle = requiredStyle;
0037     }
0038     inline const QString &requiredStyle() const
0039     {
0040         return m_requiredStyle;
0041     }
0042 
0043     inline void setIndentLanguages(const QStringList &indentLanguages)
0044     {
0045         m_indentLanguages = indentLanguages;
0046     }
0047     inline const QStringList &indentLanguages() const
0048     {
0049         return m_indentLanguages;
0050     }
0051 
0052     inline void setPriority(int priority)
0053     {
0054         m_priority = priority;
0055     }
0056     inline int priority() const
0057     {
0058         return m_priority;
0059     }
0060 
0061     inline void setBaseName(const QString &baseName)
0062     {
0063         m_baseName = baseName;
0064     }
0065     inline const QString &baseName() const
0066     {
0067         return m_baseName;
0068     }
0069 
0070 private:
0071     QString m_name; ///< indenter name, e.g. Python
0072 
0073     /**
0074      * If this is an indenter, then this specifies the required syntax
0075      * highlighting style that must be used for this indenter to work properly.
0076      * If this property is empty, the indenter doesn't require a specific style.
0077      */
0078     QString m_requiredStyle;
0079     /**
0080      * If this script is an indenter, then the indentLanguages member specifies
0081      * which languages this is an indenter for. The values must correspond with
0082      * the name of a programming language given in a highlighting file (e.g "TI Basic")
0083      */
0084     QStringList m_indentLanguages;
0085     /**
0086      * If this script is an indenter, this value controls the priority it will take
0087      * when an indenter for one of the supported languages is requested and multiple
0088      * indenters are found
0089      */
0090     int m_priority = 0;
0091 
0092     /**
0093      * basename of script
0094      */
0095     QString m_baseName;
0096 };
0097 
0098 /**
0099  * A specialized class for scripts that are of type ScriptType::Indentation.
0100  */
0101 class KateIndentScript : public KateScript
0102 {
0103 public:
0104     explicit KateIndentScript(const QString &url, const KateIndentScriptHeader &header);
0105 
0106     const QString &triggerCharacters();
0107 
0108     const KateIndentScriptHeader &indentHeader() const;
0109 
0110     /**
0111      * Returns a pair where the first value is the indent amount, and the second
0112      * value is the alignment.
0113      */
0114     QPair<int, int> indent(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor position, QChar typedCharacter, int indentWidth);
0115 
0116 private:
0117     QString m_triggerCharacters;
0118     bool m_triggerCharactersSet = false;
0119     KateIndentScriptHeader m_indentHeader;
0120 };
0121 
0122 #endif