KTextEditor

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

KDE's Doxygen guidelines are available online.