KTextEditor

katescript.h
1 /*
2  SPDX-FileCopyrightText: 2008 Paul Giannaros <[email protected]>
3  SPDX-FileCopyrightText: 2009-2018 Dominik Haumann <[email protected]>
4  SPDX-FileCopyrightText: 2010 Joseph Wenninger <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #ifndef KATE_SCRIPT_H
10 #define KATE_SCRIPT_H
11 
12 #include <QJSValue>
13 #include <QMap>
14 #include <QString>
15 
16 class QJSEngine;
17 
18 namespace KTextEditor
19 {
20 class ViewPrivate;
21 }
22 
23 class KateScriptEditor;
24 class KateScriptDocument;
25 class KateScriptView;
26 
27 namespace Kate
28 {
29 enum class ScriptType {
31  Indentation,
33  CommandLine,
35  Unknown
36 };
37 }
38 
39 // BEGIN KateScriptHeader
40 
41 class KateScriptHeader
42 {
43 public:
44  KateScriptHeader() = default;
45  virtual ~KateScriptHeader() = default;
46 
47  inline void setLicense(const QString &license)
48  {
49  m_license = license;
50  }
51  inline const QString &license() const
52  {
53  return m_license;
54  }
55 
56  inline void setAuthor(const QString &author)
57  {
58  m_author = author;
59  }
60  inline const QString &author() const
61  {
62  return m_author;
63  }
64 
65  inline void setRevision(int revision)
66  {
67  m_revision = revision;
68  }
69  inline int revision() const
70  {
71  return m_revision;
72  }
73 
74  inline void setKateVersion(const QString &kateVersion)
75  {
76  m_kateVersion = kateVersion;
77  }
78  inline const QString &kateVersion() const
79  {
80  return m_kateVersion;
81  }
82 
83  inline void setScriptType(Kate::ScriptType scriptType)
84  {
85  m_scriptType = scriptType;
86  }
87  inline Kate::ScriptType scriptType() const
88  {
89  return m_scriptType;
90  }
91 
92 private:
93  QString m_license;
94  QString m_author;
95  int m_revision = 0;
96  QString m_kateVersion;
97  Kate::ScriptType m_scriptType = Kate::ScriptType::Unknown;
98 };
99 // END
100 
101 // BEGIN KateScript
102 
107 {
108 public:
109  enum InputType { InputURL, InputSCRIPT };
110 
112 
118  explicit KateScript(const QString &urlOrScript, enum InputType inputType = InputURL);
119  virtual ~KateScript();
120 
122  const QString &url()
123  {
124  return m_url;
125  }
126 
134  bool load();
135 
140  bool setView(KTextEditor::ViewPrivate *view);
141 
146  QJSValue global(const QString &name);
147 
152  QJSValue function(const QString &name);
153 
156  {
157  return m_errorMessage;
158  }
159 
161  QString backtrace(const QJSValue &error, const QString &header = QString());
162 
164  QJSValue evaluate(const QString &program, const FieldMap &env = FieldMap());
165 
167  void displayBacktrace(const QJSValue &error, const QString &header = QString());
168 
170  void clearExceptions();
171 
173  void setGeneralHeader(const KateScriptHeader &generalHeader);
175  KateScriptHeader &generalHeader();
176 
177 protected:
179  bool hasException(const QJSValue &object, const QString &file);
180 
181 private:
183  bool m_loaded = false;
184 
186  bool m_loadSuccessful = false;
187 
189  QString m_url;
190 
192  QString m_errorMessage;
193 
194 protected:
196  QJSEngine *m_engine = nullptr;
197 
198 private:
200  KateScriptHeader m_generalHeader;
201 
203  KateScriptEditor *m_editor = nullptr;
204  KateScriptDocument *m_document = nullptr;
205  KateScriptView *m_view = nullptr;
206 
207 private:
209  enum InputType m_inputType;
210  QString m_script;
211 };
212 
213 // END
214 
215 #endif
KateScript objects represent a script that can be executed and inspected.
Definition: katescript.h:106
This class wraps the global editor instance KateGlobal, exposing some helper methods such as the clip...
qint64 revision() const override
Current revision.
Thinish wrapping around KTextEditor::DocumentPrivate, exposing the methods we want exposed and adding...
const QString & url()
The script&#39;s URL.
Definition: katescript.h:122
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
const QString & errorMessage()
Return a context-specific error message.
Definition: katescript.h:155
Thinish wrapping around KTextEditor::ViewPrivate, exposing the methods we want exposed and adding som...
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Sep 17 2020 22:57:34 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.