1 /*
2  SPDX-FileCopyrightText: 2008 Paul Giannaros <[email protected]>
3  SPDX-FileCopyrightText: 2009-2018 Dominik Haumann <[email protected]>
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
11 #include <QObject>
12 #include <QStringList>
14 #include <ktexteditor_export.h>
16 #include <QJSValue>
18 #include <ktexteditor/cursor.h>
19 #include <ktexteditor/range.h>
21 namespace KTextEditor
22 {
23 class DocumentPrivate;
24 }
33 class KTEXTEDITOR_EXPORT KateScriptDocument : public QObject
34 {
36  // Note: we have no Q_PROPERTIES due to consistency: everything is a function.
38 public:
39  explicit KateScriptDocument(QJSEngine *, QObject *parent = nullptr);
40  void setDocument(KTextEditor::DocumentPrivate *document);
41  KTextEditor::DocumentPrivate *document();
43  // BEGIN
44  Q_INVOKABLE QString fileName();
45  Q_INVOKABLE QString url();
46  Q_INVOKABLE QString mimeType();
47  Q_INVOKABLE QString encoding();
48  Q_INVOKABLE QString highlightingMode();
49  Q_INVOKABLE QStringList embeddedHighlightingModes();
50  Q_INVOKABLE QString highlightingModeAt(const QJSValue &pos);
51  Q_INVOKABLE bool isModified();
52  Q_INVOKABLE QString text();
53  Q_INVOKABLE QString text(int fromLine, int fromColumn, int toLine, int toColumn);
54  Q_INVOKABLE QString text(const QJSValue &jsfrom, const QJSValue &jsto);
55  Q_INVOKABLE QString text(const QJSValue &jsrange);
56  Q_INVOKABLE QString line(int line);
57  Q_INVOKABLE QString wordAt(int line, int column);
58  Q_INVOKABLE QString wordAt(const QJSValue &jscursor);
59  Q_INVOKABLE QJSValue wordRangeAt(int line, int column);
60  Q_INVOKABLE QJSValue wordRangeAt(const QJSValue &jscursor);
61  Q_INVOKABLE QString charAt(int line, int column);
62  Q_INVOKABLE QString charAt(const QJSValue &jscursor);
63  Q_INVOKABLE QString firstChar(int line);
64  Q_INVOKABLE QString lastChar(int line);
65  Q_INVOKABLE bool isSpace(int line, int column);
66  Q_INVOKABLE bool isSpace(const QJSValue &jscursor);
67  Q_INVOKABLE bool matchesAt(int line, int column, const QString &s);
68  Q_INVOKABLE bool matchesAt(const QJSValue &cursor, const QString &s);
69  Q_INVOKABLE bool setText(const QString &s);
70  Q_INVOKABLE bool clear();
71  Q_INVOKABLE bool truncate(int line, int column);
72  Q_INVOKABLE bool truncate(const QJSValue &jscursor);
73  Q_INVOKABLE bool insertText(int line, int column, const QString &s);
74  Q_INVOKABLE bool insertText(const QJSValue &jscursor, const QString &s);
75  Q_INVOKABLE bool removeText(int fromLine, int fromColumn, int toLine, int toColumn);
76  Q_INVOKABLE bool removeText(const QJSValue &range);
77  Q_INVOKABLE bool removeText(const QJSValue &jsfrom, const QJSValue &jsto);
78  Q_INVOKABLE bool insertLine(int line, const QString &s);
79  Q_INVOKABLE bool removeLine(int line);
80  Q_INVOKABLE bool wrapLine(int line, int column);
81  Q_INVOKABLE bool wrapLine(const QJSValue &cursor);
82  Q_INVOKABLE void joinLines(int startLine, int endLine);
83  Q_INVOKABLE int lines();
84  Q_INVOKABLE bool isLineModified(int line);
85  Q_INVOKABLE bool isLineSaved(int line);
86  Q_INVOKABLE bool isLineTouched(int line);
87  Q_INVOKABLE int findTouchedLine(int startLine, bool down);
88  Q_INVOKABLE int length();
89  Q_INVOKABLE int lineLength(int line);
90  Q_INVOKABLE void editBegin();
91  Q_INVOKABLE void editEnd();
92  Q_INVOKABLE int firstColumn(int line);
93  Q_INVOKABLE int lastColumn(int line);
94  Q_INVOKABLE int prevNonSpaceColumn(int line, int column);
95  Q_INVOKABLE int prevNonSpaceColumn(const QJSValue &jscursor);
96  Q_INVOKABLE int nextNonSpaceColumn(int line, int column);
97  Q_INVOKABLE int nextNonSpaceColumn(const QJSValue &jscursor);
98  Q_INVOKABLE int prevNonEmptyLine(int line);
99  Q_INVOKABLE int nextNonEmptyLine(int line);
100  Q_INVOKABLE bool isInWord(const QString &character, int attribute);
101  Q_INVOKABLE bool canBreakAt(const QString &character, int attribute);
102  Q_INVOKABLE bool canComment(int startAttribute, int endAttribute);
103  Q_INVOKABLE QString commentMarker(int attribute);
104  Q_INVOKABLE QString commentStart(int attribute);
105  Q_INVOKABLE QString commentEnd(int attribute);
107  Q_INVOKABLE QJSValue documentRange();
108  Q_INVOKABLE QJSValue documentEnd();
109  Q_INVOKABLE bool isValidTextPosition(int line, int column);
110  Q_INVOKABLE bool isValidTextPosition(const QJSValue &cursor);
115  Q_INVOKABLE int attribute(int line, int column);
116  Q_INVOKABLE int attribute(const QJSValue &jscursor);
121  Q_INVOKABLE bool isAttribute(int line, int column, int attr);
122  Q_INVOKABLE bool isAttribute(const QJSValue &jscursor, int attr);
127  Q_INVOKABLE QString attributeName(int line, int column);
128  Q_INVOKABLE QString attributeName(const QJSValue &jscursor);
133  Q_INVOKABLE bool isAttributeName(int line, int column, const QString &name);
134  Q_INVOKABLE bool isAttributeName(const QJSValue &cursor, const QString &name);
136  Q_INVOKABLE QString variable(const QString &s);
137  Q_INVOKABLE void setVariable(const QString &s, const QString &v);
138  // END
140  Q_INVOKABLE int firstVirtualColumn(int line);
141  Q_INVOKABLE int lastVirtualColumn(int line);
142  Q_INVOKABLE int toVirtualColumn(int line, int column);
143  Q_INVOKABLE int toVirtualColumn(const QJSValue &cursor);
144  Q_INVOKABLE QJSValue toVirtualCursor(int line, int column);
145  Q_INVOKABLE QJSValue toVirtualCursor(const QJSValue &jscursor);
146  Q_INVOKABLE int fromVirtualColumn(int line, int virtualColumn);
147  Q_INVOKABLE int fromVirtualColumn(const QJSValue &jscursor);
148  Q_INVOKABLE QJSValue fromVirtualCursor(int line, int column);
149  Q_INVOKABLE QJSValue fromVirtualCursor(const QJSValue &jscursor);
151  KTextEditor::Cursor anchorInternal(int line, int column, QChar character);
152  KTextEditor::Cursor anchor(const KTextEditor::Cursor &cursor, QChar character);
153  Q_INVOKABLE QJSValue anchor(int line, int column, QChar character);
154  Q_INVOKABLE QJSValue anchor(const QJSValue &cursor, QChar character);
155  KTextEditor::Cursor rfindInternal(int line, int column, const QString &text, int attribute = -1);
156  KTextEditor::Cursor rfind(const KTextEditor::Cursor &cursor, const QString &text, int attribute = -1);
157  Q_INVOKABLE QJSValue rfind(int line, int column, const QString &text, int attribute = -1);
158  Q_INVOKABLE QJSValue rfind(const QJSValue &cursor, const QString &text, int attribute = -1);
160  Q_INVOKABLE int defStyleNum(int line, int column);
161  Q_INVOKABLE int defStyleNum(const QJSValue &cursor);
162  Q_INVOKABLE bool isCode(int line, int column);
163  Q_INVOKABLE bool isCode(const QJSValue &cursor);
164  Q_INVOKABLE bool isComment(int line, int column);
165  Q_INVOKABLE bool isComment(const QJSValue &cursor);
166  Q_INVOKABLE bool isString(int line, int column);
167  Q_INVOKABLE bool isString(const QJSValue &cursor);
168  Q_INVOKABLE bool isRegionMarker(int line, int column);
169  Q_INVOKABLE bool isRegionMarker(const QJSValue &cursor);
170  Q_INVOKABLE bool isChar(int line, int column);
171  Q_INVOKABLE bool isChar(const QJSValue &cursor);
172  Q_INVOKABLE bool isOthers(int line, int column);
173  Q_INVOKABLE bool isOthers(const QJSValue &cursor);
175  Q_INVOKABLE bool startsWith(int line, const QString &pattern, bool skipWhiteSpaces);
176  Q_INVOKABLE bool endsWith(int line, const QString &pattern, bool skipWhiteSpaces);
178  Q_INVOKABLE void indent(const QJSValue &jsrange, int change);
180 private:
181  bool _isCode(int defaultStyle);
183  KTextEditor::DocumentPrivate *m_document;
184  QJSEngine *m_engine;
185 };
187 #endif
void editBegin()
Alias for editStart()
Definition: katedocument.h:225
virtual void setVariable(const QString &name, const QString &value)
Set the variable name to value.
void joinLines(uint first, uint last)
Unwrap a range of lines.
The Cursor represents a position in a Document.
Definition: cursor.h:71
Thinish wrapping around KTextEditor::DocumentPrivate, exposing the methods we want exposed and adding...
QString highlightingMode() const override
Return the name of the currently used mode.
int findTouchedLine(int startLine, bool down)
Find the next modified/saved line, starting at startLine.
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
QString mimeType() override
Tries to detect mime-type based on file name and content of buffer.
bool editEnd()
End a editor operation.
virtual QString variable(const QString &name) const
Returns the value for the variable name.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Oct 28 2020 23:02:31 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.