Changeset View
Changeset View
Standalone View
Standalone View
src/script/katescriptview.h
Context not available. | |||||
21 | #define KATE_SCRIPT_VIEW_H | 21 | #define KATE_SCRIPT_VIEW_H | ||
---|---|---|---|---|---|
22 | 22 | | |||
23 | #include <QObject> | 23 | #include <QObject> | ||
24 | #include <QScriptable> | 24 | #include <QJSValue> | ||
25 | 25 | | |||
26 | #include <ktexteditor_export.h> | 26 | #include <ktexteditor_export.h> | ||
27 | 27 | | |||
Context not available. | |||||
29 | #include <ktexteditor/range.h> | 29 | #include <ktexteditor/range.h> | ||
30 | 30 | | |||
31 | namespace KTextEditor { class ViewPrivate; } | 31 | namespace KTextEditor { class ViewPrivate; } | ||
32 | 32 | class QJSEngine; | |||
33 | /** | 33 | /** | ||
34 | * Thinish wrapping around KTextEditor::ViewPrivate, exposing the methods we want exposed | 34 | * Thinish wrapping around KTextEditor::ViewPrivate, exposing the methods we want exposed | ||
35 | * and adding some helper methods. | 35 | * and adding some helper methods. | ||
36 | * | 36 | * | ||
37 | * We inherit from QScriptable to have more thight access to the scripting | | |||
38 | * engine. | | |||
39 | * | | |||
40 | * setView _must_ be called before using any other method. This is not checked | 37 | * setView _must_ be called before using any other method. This is not checked | ||
41 | * for the sake of speed. | 38 | * for the sake of speed. | ||
42 | */ | 39 | */ | ||
43 | class KTEXTEDITOR_EXPORT KateScriptView : public QObject, protected QScriptable | 40 | class KTEXTEDITOR_EXPORT KateScriptView : public QObject | ||
44 | { | 41 | { | ||
45 | /// Properties are accessible with a nicer syntax from JavaScript | 42 | /// Properties are accessible with a nicer syntax from JavaScript | ||
46 | Q_OBJECT | 43 | Q_OBJECT | ||
47 | 44 | | |||
48 | public: | 45 | public: | ||
49 | KateScriptView(QObject *parent = nullptr); | 46 | KateScriptView(QJSEngine *, QObject *parent = nullptr); | ||
50 | void setView(KTextEditor::ViewPrivate *view); | 47 | void setView(KTextEditor::ViewPrivate *view); | ||
51 | KTextEditor::ViewPrivate *view(); | 48 | KTextEditor::ViewPrivate *view(); | ||
52 | 49 | | |||
53 | Q_INVOKABLE KTextEditor::Cursor cursorPosition(); | 50 | Q_INVOKABLE QJSValue cursorPosition(); | ||
54 | /** | 51 | /** | ||
55 | * Set the cursor position in the view. | 52 | * Set the cursor position in the view. | ||
56 | * @since 4.4 | 53 | * @since 4.4 | ||
57 | */ | 54 | */ | ||
58 | Q_INVOKABLE void setCursorPosition(int line, int column); | 55 | Q_INVOKABLE void setCursorPosition(int line, int column); | ||
59 | Q_INVOKABLE void setCursorPosition(const KTextEditor::Cursor &cursor); | 56 | Q_INVOKABLE void setCursorPosition(const KTextEditor::Cursor &cursor); | ||
57 | Q_INVOKABLE void setCursorPosition(const QJSValue &cursor); | ||||
60 | 58 | | |||
61 | Q_INVOKABLE KTextEditor::Cursor virtualCursorPosition(); | 59 | Q_INVOKABLE QJSValue virtualCursorPosition(); | ||
62 | Q_INVOKABLE void setVirtualCursorPosition(int line, int column); | 60 | Q_INVOKABLE void setVirtualCursorPosition(int line, int column); | ||
63 | Q_INVOKABLE void setVirtualCursorPosition(const KTextEditor::Cursor &cursor); | 61 | Q_INVOKABLE void setVirtualCursorPosition(const KTextEditor::Cursor &cursor); | ||
62 | Q_INVOKABLE void setVirtualCursorPosition(const QJSValue &cursor); | ||||
64 | 63 | | |||
65 | Q_INVOKABLE QString selectedText(); | 64 | Q_INVOKABLE QString selectedText(); | ||
66 | Q_INVOKABLE bool hasSelection(); | 65 | Q_INVOKABLE bool hasSelection(); | ||
67 | Q_INVOKABLE KTextEditor::Range selection(); | 66 | Q_INVOKABLE QJSValue selection(); | ||
68 | Q_INVOKABLE void setSelection(const KTextEditor::Range &range); | 67 | Q_INVOKABLE void setSelection(const QJSValue &range); | ||
69 | Q_INVOKABLE void removeSelectedText(); | 68 | Q_INVOKABLE void removeSelectedText(); | ||
70 | Q_INVOKABLE void selectAll(); | 69 | Q_INVOKABLE void selectAll(); | ||
71 | Q_INVOKABLE void clearSelection(); | 70 | Q_INVOKABLE void clearSelection(); | ||
72 | 71 | | |||
73 | Q_INVOKABLE void align(const KTextEditor::Range &range); | 72 | Q_INVOKABLE void align(const QJSValue &range); | ||
74 | 73 | | |||
75 | private: | 74 | private: | ||
76 | KTextEditor::ViewPrivate *m_view; | 75 | KTextEditor::ViewPrivate *m_view; | ||
76 | QJSEngine *m_engine; | ||||
77 | }; | 77 | }; | ||
78 | 78 | | |||
79 | #endif | 79 | #endif | ||
Context not available. |