KTextEditor

katescriptview.h
1/*
2 SPDX-FileCopyrightText: 2008 Paul Giannaros <paul@giannaros.org>
3 SPDX-FileCopyrightText: 2008 Christoph Cullmann <cullmann@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef KATE_SCRIPT_VIEW_H
9#define KATE_SCRIPT_VIEW_H
10
11#include <QJSValue>
12#include <QObject>
13
14#include <ktexteditor_export.h>
15
16#include <ktexteditor/cursor.h>
17#include <ktexteditor/range.h>
18
19namespace KTextEditor
20{
21class ViewPrivate;
22}
23class QJSEngine;
24/**
25 * Thinish wrapping around KTextEditor::ViewPrivate, exposing the methods we want exposed
26 * and adding some helper methods.
27 *
28 * setView _must_ be called before using any other method. This is not checked
29 * for the sake of speed.
30 */
31class KTEXTEDITOR_EXPORT KateScriptView : public QObject
32{
33 /// Properties are accessible with a nicer syntax from JavaScript
34 Q_OBJECT
35
36public:
37 explicit KateScriptView(QJSEngine *, QObject *parent = nullptr);
38 void setView(KTextEditor::ViewPrivate *view);
39 KTextEditor::ViewPrivate *view();
40
41 Q_INVOKABLE void copy();
42 Q_INVOKABLE void cut();
43 Q_INVOKABLE void paste();
44
45 Q_INVOKABLE QJSValue cursorPosition();
46 Q_INVOKABLE QJSValue cursorPositions();
47
48 /**
49 * Set the cursor position in the view.
50 * @since 4.4
51 */
52 Q_INVOKABLE void setCursorPosition(int line, int column);
53 Q_INVOKABLE void setCursorPosition(const QJSValue &cursor);
54 Q_INVOKABLE void setCursorPositions(const QJSValue &cursors);
55
56 Q_INVOKABLE QJSValue virtualCursorPosition();
57 Q_INVOKABLE void setVirtualCursorPosition(int line, int column);
58 Q_INVOKABLE void setVirtualCursorPosition(const QJSValue &cursor);
59
60 Q_INVOKABLE QString selectedText();
61 Q_INVOKABLE bool hasSelection();
62 Q_INVOKABLE QJSValue selection();
63 Q_INVOKABLE QJSValue selections();
64 Q_INVOKABLE void setSelection(const QJSValue &range);
65 Q_INVOKABLE void setSelections(const QJSValue &ranges);
66 Q_INVOKABLE void removeSelectedText();
67 Q_INVOKABLE void selectAll();
68 Q_INVOKABLE void clearSelection();
69
70 Q_INVOKABLE void setBlockSelection(bool on);
71 Q_INVOKABLE bool blockSelection();
72
73 Q_INVOKABLE void align(const QJSValue &range);
74 Q_INVOKABLE void alignOn(const QJSValue &jsrange, const QJSValue &pattern = QJSValue(QStringLiteral("")));
75
76 Q_INVOKABLE QJSValue searchText(const QJSValue &range, const QString &pattern, bool backwards = false);
77
78 Q_INVOKABLE QJSValue executeCommand(const QString &command, const QString &args = QString(), const QJSValue &jsrange = QJSValue());
79
80private:
81 KTextEditor::ViewPrivate *m_view;
82 QJSEngine *m_engine;
83};
84
85#endif
Thinish wrapping around KTextEditor::ViewPrivate, exposing the methods we want exposed and adding som...
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-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:15:44 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.