KTextEditor

katecmds.h
1/*
2 SPDX-FileCopyrightText: 2003-2005 Anders Lund <anders@alweb.dk>
3 SPDX-FileCopyrightText: 2001-2010 Christoph Cullmann <cullmann@kde.org>
4 SPDX-FileCopyrightText: 2001 Charles Samuels <charles@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#ifndef KATE_CMDS_H
10#define KATE_CMDS_H
11
12#include <KTextEditor/Command>
13
14#include <QStringList>
15
16class KCompletion;
17
18/**
19 * The KateCommands namespace collects subclasses of KTextEditor::Command
20 * for specific use in kate.
21 */
22namespace KateCommands
23{
24/**
25 * This KTextEditor::Command provides access to a lot of the core functionality
26 * of kate part, settings, utilities, navigation etc.
27 * it needs to get a kateview pointer, it will cast the kate::view pointer
28 * hard to kateview
29 */
31{
33 : KTextEditor::Command({QStringLiteral("indent"),
34 QStringLiteral("unindent"),
35 QStringLiteral("cleanindent"),
36 QStringLiteral("fold"),
37 QStringLiteral("tfold"),
38 QStringLiteral("unfold"),
39 QStringLiteral("comment"),
40 QStringLiteral("uncomment"),
41 QStringLiteral("goto"),
42 QStringLiteral("kill-line"),
43 QStringLiteral("set-tab-width"),
44 QStringLiteral("set-replace-tabs"),
45 QStringLiteral("set-show-tabs"),
46 QStringLiteral("set-indent-width"),
47 QStringLiteral("set-indent-mode"),
48 QStringLiteral("set-auto-indent"),
49 QStringLiteral("set-line-numbers"),
50 QStringLiteral("set-folding-markers"),
51 QStringLiteral("set-icon-border"),
52 QStringLiteral("set-indent-pasted-text"),
53 QStringLiteral("set-word-wrap"),
54 QStringLiteral("set-word-wrap-column"),
55 QStringLiteral("set-replace-tabs-save"),
56 QStringLiteral("set-remove-trailing-spaces"),
57 QStringLiteral("set-highlight"),
58 QStringLiteral("set-mode"),
59 QStringLiteral("set-show-indent"),
60 QStringLiteral("print")})
61 {
62 }
63
64 static CoreCommands *m_instance;
65
66public:
67 ~CoreCommands() override
68 {
69 m_instance = nullptr;
70 }
71
72 /**
73 * execute command
74 * @param view view to use for execution
75 * @param cmd cmd string
76 * @param errorMsg error to return if no success
77 * @return success
78 */
79 bool exec(class KTextEditor::View *view, const QString &cmd, QString &errorMsg);
80
81 /**
82 * execute command on given range
83 * @param view view to use for execution
84 * @param cmd cmd string
85 * @param errorMsg error to return if no success
86 * @param range range to execute command on
87 * @return success
88 */
89 bool
90 exec(class KTextEditor::View *view, const QString &cmd, QString &errorMsg, const KTextEditor::Range &range = KTextEditor::Range(-1, -0, -1, 0)) override;
91
92 bool supportsRange(const QString &range) override;
93
94 /** This command does not have help. @see KTextEditor::Command::help */
95 bool help(class KTextEditor::View *, const QString &, QString &) override;
96
97 /** override from KTextEditor::Command */
99
100 static CoreCommands *self()
101 {
102 if (m_instance == nullptr) {
103 m_instance = new CoreCommands();
104 }
105 return m_instance;
106 }
107};
108
109/**
110 * insert a unicode or ascii character
111 * base 9+1: 1234
112 * hex: 0x1234 or x1234
113 * octal: 01231
114 *
115 * prefixed with "char:"
116 **/
118{
119 Character()
120 : KTextEditor::Command({QStringLiteral("char")})
121 {
122 }
123
124 static Character *m_instance;
125
126public:
127 ~Character() override
128 {
129 m_instance = nullptr;
130 }
131
132 /**
133 * execute command
134 * @param view view to use for execution
135 * @param cmd cmd string
136 * @param errorMsg error to return if no success
137 * @return success
138 */
139 bool
140 exec(class KTextEditor::View *view, const QString &cmd, QString &errorMsg, const KTextEditor::Range &range = KTextEditor::Range(-1, -0, -1, 0)) override;
141
142 /** This command does not have help. @see KTextEditor::Command::help */
143 bool help(class KTextEditor::View *, const QString &, QString &) override;
144
145 static Character *self()
146 {
147 if (m_instance == nullptr) {
148 m_instance = new Character();
149 }
150 return m_instance;
151 }
152};
153
154/**
155 * insert the current date/time in the given format
156 */
158{
159 Date()
160 : KTextEditor::Command({QStringLiteral("date")})
161 {
162 }
163
164 static Date *m_instance;
165
166public:
167 ~Date() override
168 {
169 m_instance = nullptr;
170 }
171
172 /**
173 * execute command
174 * @param view view to use for execution
175 * @param cmd cmd string
176 * @param errorMsg error to return if no success
177 * @return success
178 */
179 bool
180 exec(class KTextEditor::View *view, const QString &cmd, QString &errorMsg, const KTextEditor::Range &range = KTextEditor::Range(-1, -0, -1, 0)) override;
181
182 /** This command does not have help. @see KTextEditor::Command::help */
183 bool help(class KTextEditor::View *, const QString &, QString &) override;
184
185 static Date *self()
186 {
187 if (m_instance == nullptr) {
188 m_instance = new Date();
189 }
190 return m_instance;
191 }
192};
193
194} // namespace KateCommands
195#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
insert a unicode or ascii character base 9+1: 1234 hex: 0x1234 or x1234 octal: 01231
Definition katecmds.h:118
bool help(class KTextEditor::View *, const QString &, QString &) override
This command does not have help.
Definition katecmds.cpp:488
bool exec(class KTextEditor::View *view, const QString &cmd, QString &errorMsg, const KTextEditor::Range &range=KTextEditor::Range(-1, -0, -1, 0)) override
execute command
Definition katecmds.cpp:503
This KTextEditor::Command provides access to a lot of the core functionality of kate part,...
Definition katecmds.h:31
bool help(class KTextEditor::View *, const QString &, QString &) override
This command does not have help.
Definition katecmds.cpp:47
bool exec(class KTextEditor::View *view, const QString &cmd, QString &errorMsg)
execute command
bool supportsRange(const QString &range) override
Find out if a given command can act on a range.
Definition katecmds.cpp:437
KCompletion * completionObject(KTextEditor::View *, const QString &) override
override from KTextEditor::Command
Definition katecmds.cpp:449
insert the current date/time in the given format
Definition katecmds.h:158
bool help(class KTextEditor::View *, const QString &, QString &) override
This command does not have help.
Definition katecmds.cpp:555
bool exec(class KTextEditor::View *view, const QString &cmd, QString &errorMsg, const KTextEditor::Range &range=KTextEditor::Range(-1, -0, -1, 0)) override
execute command
Definition katecmds.cpp:588
The KateCommands namespace collects subclasses of KTextEditor::Command for specific use in kate.
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.