KTextEditor

katescriptmanager.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_MANAGER_H
10 #define KATE_SCRIPT_MANAGER_H
11 
12 #include <KTextEditor/Command>
13 #include <ktexteditor/cursor.h>
14 
15 #include <QVector>
16 
17 class QString;
18 class KateIndentScript;
20 
21 /**
22  * Manage the scripts on disks -- find them and query them.
23  * Provides access to loaded scripts too.
24  */
26 {
27  Q_OBJECT
28 
30  static KateScriptManager *m_instance;
31 
32 public:
33  ~KateScriptManager() override;
34 
35  /** Get all scripts available in the command line */
37  {
38  return m_commandLineScripts;
39  }
40 
41  /**
42  * Get an indentation script for the given language -- if there is more than
43  * one result, this will return the script with the highest priority. If
44  * both have the same priority, an arbitrary script will be returned.
45  * If no scripts are found, 0 is returned.
46  */
47  KateIndentScript *indenter(const QString &language);
48 
49  //
50  // KTextEditor::Command
51  //
52 public:
53  /**
54  * execute command
55  * @param view view to use for execution
56  * @param cmd cmd string
57  * @param errorMsg error to return if no success
58  * @return success
59  */
60  bool exec(KTextEditor::View *view, const QString &cmd, QString &errorMsg, const KTextEditor::Range &) override;
61 
62  /**
63  * get help for a command
64  * @param view view to use
65  * @param cmd cmd name
66  * @param msg help message
67  * @return help available or not
68  */
69  bool help(KTextEditor::View *view, const QString &cmd, QString &msg) override;
70 
71  static KateScriptManager *self()
72  {
73  if (m_instance == nullptr) {
74  m_instance = new KateScriptManager();
75  }
76  return m_instance;
77  }
78 
79  //
80  // Helper methods
81  //
82 public:
83  /**
84  * Collect all scripts.
85  */
86  void collect();
87 
88 public:
89  KateIndentScript *indentationScript(const QString &scriptname)
90  {
91  return m_indentationScriptMap.value(scriptname);
92  }
93 
94  int indentationScriptCount()
95  {
96  return m_indentationScripts.size();
97  }
98  KateIndentScript *indentationScriptByIndex(int index)
99  {
100  return m_indentationScripts[index];
101  }
102 
103 public:
104  /** explicitly reload all scripts */
105  void reload();
106 
107 Q_SIGNALS:
108  /** this signal is emitted when all scripts are _deleted_ and reloaded again. */
109  void reloaded();
110 
111 private:
112  /** List of all command line scripts */
113  QVector<KateCommandLineScript *> m_commandLineScripts;
114 
115  /** list of all indentation scripts */
116  QList<KateIndentScript *> m_indentationScripts;
117 
118  /** hash of all existing indenter scripts, hashes basename -> script */
119  QHash<QString, KateIndentScript *> m_indentationScriptMap;
120 
121  /** Map of language to indent scripts */
122  QHash<QString, QVector<KateIndentScript *>> m_languageToIndenters;
123 };
124 
125 #endif
Q_OBJECTQ_OBJECT
An Editor command line command.
const T value(const Key &key) const const
bool help(KTextEditor::View *view, const QString &cmd, QString &msg) override
get help for a command
void collect()
Collect all scripts.
Manage the scripts on disks – find them and query them.
void reload()
explicitly reload all scripts
const QVector< KateCommandLineScript * > & commandLineScripts()
Get all scripts available in the command line.
A specialized class for scripts that are of type ScriptType::Indentation.
A specialized class for scripts that are of type ScriptType::Indentation.
void reloaded()
this signal is emitted when all scripts are deleted and reloaded again.
An object representing a section of text, from one Cursor to another.
KateIndentScript * indenter(const QString &language)
Get an indentation script for the given language – if there is more than one result,...
int size() const const
bool exec(KTextEditor::View *view, const QString &cmd, QString &errorMsg, const KTextEditor::Range &) override
execute command
A text widget with KXMLGUIClient that represents a Document.
Definition: view.h:146
Q_SIGNALSQ_SIGNALS
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Mar 23 2023 03:59:01 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.