KTextEditor

kateindentscript.h
1/*
2 SPDX-FileCopyrightText: 2008 Paul Giannaros <paul@giannaros.org>
3 SPDX-FileCopyrightText: 2009-2018 Dominik Haumann <dhaumann@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef KATE_INDENT_SCRIPT_H
9#define KATE_INDENT_SCRIPT_H
10
11#include "katescript.h"
12
13#include <KTextEditor/Cursor>
14
15namespace KTextEditor
16{
17class ViewPrivate;
18}
19
20class KateIndentScriptHeader
21{
22public:
23 KateIndentScriptHeader() = default;
24
25 inline void setName(const QString &name)
26 {
27 m_name = name;
28 }
29 inline const QString &name() const
30 {
31 return m_name;
32 }
33
34 inline void setRequiredStyle(const QString &requiredStyle)
35 {
36 m_requiredStyle = requiredStyle;
37 }
38 inline const QString &requiredStyle() const
39 {
40 return m_requiredStyle;
41 }
42
43 inline void setIndentLanguages(const QStringList &indentLanguages)
44 {
45 m_indentLanguages = indentLanguages;
46 }
47 inline const QStringList &indentLanguages() const
48 {
49 return m_indentLanguages;
50 }
51
52 inline void setPriority(int priority)
53 {
54 m_priority = priority;
55 }
56 inline int priority() const
57 {
58 return m_priority;
59 }
60
61 inline void setBaseName(const QString &baseName)
62 {
63 m_baseName = baseName;
64 }
65 inline const QString &baseName() const
66 {
67 return m_baseName;
68 }
69
70private:
71 QString m_name; ///< indenter name, e.g. Python
72
73 /**
74 * If this is an indenter, then this specifies the required syntax
75 * highlighting style that must be used for this indenter to work properly.
76 * If this property is empty, the indenter doesn't require a specific style.
77 */
78 QString m_requiredStyle;
79 /**
80 * If this script is an indenter, then the indentLanguages member specifies
81 * which languages this is an indenter for. The values must correspond with
82 * the name of a programming language given in a highlighting file (e.g "TI Basic")
83 */
84 QStringList m_indentLanguages;
85 /**
86 * If this script is an indenter, this value controls the priority it will take
87 * when an indenter for one of the supported languages is requested and multiple
88 * indenters are found
89 */
90 int m_priority = 0;
91
92 /**
93 * basename of script
94 */
95 QString m_baseName;
96};
97
98/**
99 * A specialized class for scripts that are of type ScriptType::Indentation.
100 */
101class KateIndentScript : public KateScript
102{
103public:
104 explicit KateIndentScript(const QString &url, const KateIndentScriptHeader &header);
105
106 const QString &triggerCharacters();
107
108 const KateIndentScriptHeader &indentHeader() const;
109
110 /**
111 * Returns a pair where the first value is the indent amount, and the second
112 * value is the alignment.
113 */
114 QPair<int, int> indent(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor position, QChar typedCharacter, int indentWidth);
115
116private:
117 QString m_triggerCharacters;
118 bool m_triggerCharactersSet = false;
119 KateIndentScriptHeader m_indentHeader;
120};
121
122#endif
The Cursor represents a position in a Document.
Definition cursor.h:75
QPair< int, int > indent(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor position, QChar typedCharacter, int indentWidth)
Returns a pair where the first value is the indent amount, and the second value is the alignment.
const QString & url()
The script's URL.
Definition katescript.h:125
KateScript(const QString &urlOrScript, enum InputType inputType=InputURL)
Create a new script representation, passing either a file or the script content urlOrScript to it.
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:55:24 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.