1
<?xml version="1.0" encoding="UTF-8"?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
6
<title>KTextEditor.TemplateInterface</title>
7
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
8
<meta http-equiv="Content-Style-Type" content="text/css" />
9
<link rel="stylesheet" type="text/css" href="../common/doxygen.css" />
10
<link rel="stylesheet" media="screen" type="text/css" title="KDE Colors" href="../common/kde.css" />
18
<img alt ="" src="../common/top-kde.jpg"/>
19
KDE 4.9 PyKDE API Reference
23
<div id="header_bottom">
26
<li>KDE's Python API</li>
32
<li><a href="../modules.html">Overview</a></li>
33
<li><a href="http://techbase.kde.org/Development/Languages/Python">PyKDE Home</a></li>
34
<li><a href="http://kde.org/family/">Sitemap</a></li>
35
<li><a href="http://kde.org/contact/">Contact Us</a></li>
41
<div id="body_wrapper">
46
<div class="clearer"> </div>
48
<h1>TemplateInterface Class Reference</h1>
49
<code>from PyKDE4.ktexteditor import *</code>
53
Namespace: <a href="../ktexteditor/KTextEditor.html">KTextEditor</a><br />
54
<h2>Detailed Description</h2>
56
<p>This is an interface for inserting template strings with user editable
57
fields into a document.
59
<table border="0" cellpadding="0" cellspacing="0"><tr><td colspan="2"><br><h2>Methods</h2></td></tr>
60
<tr><td class="memItemLeft" nowrap align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="#TemplateInterface">__init__</a> (self)</td></tr>
61
<tr><td class="memItemLeft" nowrap align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="#KTE_INTERNAL_setupIntialValues">KTE_INTERNAL_setupIntialValues</a> (self, QString templateString, {QString:QString} initialValues)</td></tr>
62
<tr><td class="memItemLeft" nowrap align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="#insertTemplateText">insertTemplateText</a> (self, <a href="../ktexteditor/KTextEditor.Cursor.html">KTextEditor.Cursor</a> insertPosition, QString templateString, {QString:QString} initialValues)</td></tr>
63
<tr><td class="memItemLeft" nowrap align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="#insertTemplateTextImplementation">insertTemplateTextImplementation</a> (self, <a href="../ktexteditor/KTextEditor.Cursor.html">KTextEditor.Cursor</a> insertPosition, QString templateString, {QString:QString} initialValues)</td></tr>
64
<tr><td colspan="2"><br><h2>Static Methods</h2></td></tr>
65
<tr><td class="memItemLeft" nowrap align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="#expandMacros">expandMacros</a> ({QString:QString} initialValues, QWidget parentWindow)</td></tr>
67
<hr><h2>Method Documentation</h2><a class="anchor" name="TemplateInterface"></a>
69
<div class="memproto">
70
<table class="memname"><tr>
71
<td class="memname">__init__</td>
73
<td class="paramtype"> </td>
74
<td class="paramname"><em>self</em> )</td>
75
<td width="100%"> </td>
79
<div class="memdoc"></div></div><a class="anchor" name="KTE_INTERNAL_setupIntialValues"></a>
81
<div class="memproto">
82
<table class="memname"><tr>
83
<td class="memname">bool KTE_INTERNAL_setupIntialValues</td>
85
<td class="paramtype"> <em>self</em>, </td>
86
<td class="paramname"></td>
88
<td class="memname"></td>
90
<td class="paramtype">QString </td>
91
<td class="paramname"><em>templateString</em>, </td>
94
<td class="memname"></td>
96
<td class="paramtype">{QString:QString} </td>
97
<td class="paramname"><em>initialValues</em></td>
104
<td width="100%"> </td>
107
<div class="memdoc"><p>DO NOT USE !!!! THIS IS USED INTERNALLY by the interface only !!!!!!
108
Behaviour might change !!!!!!!
109
</p></div></div><a class="anchor" name="insertTemplateText"></a>
110
<div class="memitem">
111
<div class="memproto">
112
<table class="memname"><tr>
113
<td class="memname">bool insertTemplateText</td>
115
<td class="paramtype"> <em>self</em>, </td>
116
<td class="paramname"></td>
118
<td class="memname"></td>
120
<td class="paramtype"><a href="../ktexteditor/KTextEditor.Cursor.html">KTextEditor.Cursor</a> </td>
121
<td class="paramname"><em>insertPosition</em>, </td>
124
<td class="memname"></td>
126
<td class="paramtype">QString </td>
127
<td class="paramname"><em>templateString</em>, </td>
130
<td class="memname"></td>
132
<td class="paramtype">{QString:QString} </td>
133
<td class="paramname"><em>initialValues</em></td>
140
<td width="100%"> </td>
143
<div class="memdoc"><p>Inserts an interactive ediable template text at line "line", column "col".
144
<dl class="return" compact><dt><b>Returns:</b></dt><dd> true if inserting the string succeeded
147
Use insertTemplateText(lines(), ...) to append text at end of document
148
Template strings look like
149
"for( int ${index}=0;${index}<10;${index}++) { ${cursor} };"
153
This syntax is somewhat similar to the one found in the Eclipse editor or textmate.
156
There are certain common placeholders (macros), which get assigned a
157
default initialValue, If the second parameter does not a given value.
158
For all others the initial value is the name of the placeholder.
161
Placeholder names may only consist of a-zA-Z0-9_
164
<dl class="since" compact><dt><b>Since:</b></dt><dd> 4.5
165
if a placeholder is a mirror, the place holder name may contain additional information
166
${something/regexp/replacement/} takes the value of the placeholder something and replaces the match with the replacement before inserting the mirrored value
167
${something/regexp/replacement/g} like above, but for all occurences
168
The syntax of the regexp and the replacement are the ones from kateparts regexp search/replace
169
${something/regexp/replacement/i} like above, but case insensitive
170
The syntax of the regexp and the replacement are the ones from kateparts regexp search/replace
171
Possible flags: g and i. Those flags can be combined too
172
If a literal / should appear in the regexp, it has to be escaped \/,
173
literal \ has to be escaped too
176
If you have mirrored ranges and want another occurence than the first one as the master
177
you can add @directly after the placeholder name.
180
The interface2 version invokes the function specified by functionName within the script specified
181
by the scriptToken, if a placeholder is specified with backticks like
182
${placeholder`functionName`}
183
The function has a global environment containing "view", "document" and "debug", at
184
least in the katepart implementation. The function invokation is not allowed to be mixed with other replacements
187
If a / or ` replacement is done on a master the initial value is modified and therefor
188
also all mirrored placeholders are affected too, later on the replacement is not done anymore on master ranges
191
The parameters for invoked javascript functions will be the following:
192
value of the master (or initial value), //to be done: placeholder name, small wrapper around the template handler (to do more sophisticated things, like adding additional placehlder points, aattaching custom properties for state keeping, ....) you tell
195
Specification of initial values
196
You can specify initial values which are different from the placeholder name
197
this is done via, this makes only sense for $ placeholders, not for %
198
${placeholder:some value} or ${placeholder@:some value}
199
It is not allowed to mix : and /
200
after the first colon, everything is interpreted as default value, } in
201
the default value have to be escaped (backslashes before } have to be escaped themselves) and regexp searches are ignored. The : has to be
202
directly after the placeholder name or after an optional @symbol.
205
Common placeholders and values are
209
- loginname: The current users's loginname
210
- firstname: The current user's first name retrieved from kabc
211
- lastname: The current user's last name retrieved from kabc
212
- fullname: The current user's first and last name retrieved from kabc
213
- email: The current user's primary email address retrieved from kabc
217
- month: current month
219
- hostname: hostname of the computer
220
- selection: The implementation should set this to the selected text, if any
221
- cursor: at this position the cursor will be after editing of the
222
template has finished, this has to be taken care of by the actual
223
implementation. The placeholder gets a value of "|" assigned.
226
If a macro is started with a % (persent sign) like "%{date}" it isn't added
227
to the list editable strings ( for example TAB key navigation) if a value
228
differing from the macro name is found.
231
If the editor supports some kind of smart indentation, the inserted code
232
should be layouted by the indenter.
233
<dl class="deprecated" compact><dt><b>Deprecated:</b></dt><dd>
235
</p></div></div><a class="anchor" name="insertTemplateTextImplementation"></a>
236
<div class="memitem">
237
<div class="memproto">
238
<table class="memname"><tr>
239
<td class="memname">bool insertTemplateTextImplementation</td>
241
<td class="paramtype"> <em>self</em>, </td>
242
<td class="paramname"></td>
244
<td class="memname"></td>
246
<td class="paramtype"><a href="../ktexteditor/KTextEditor.Cursor.html">KTextEditor.Cursor</a> </td>
247
<td class="paramname"><em>insertPosition</em>, </td>
250
<td class="memname"></td>
252
<td class="paramtype">QString </td>
253
<td class="paramname"><em>templateString</em>, </td>
256
<td class="memname"></td>
258
<td class="paramtype">{QString:QString} </td>
259
<td class="paramname"><em>initialValues</em></td>
266
<td width="100%"> </td>
269
<div class="memdoc"><dl compact><dt><b>Abstract method:</b></dt><dd>This method is abstract and can be overridden but not called directly.</dd></dl><p>You must implement this, it is called by insertTemplateText, after all
270
default values are inserted. If you are implementing this interface,
271
this method should work as described in the documentation for
272
insertTemplateText above.
273
<dl class="return" compact><dt><b>Returns:</b></dt><dd> true if any text was inserted.
274
</dd></dl> <dl class="deprecated" compact><dt><b>Deprecated:</b></dt><dd>
276
</p></div></div><hr><h2>Static Method Documentation</h2><a class="anchor" name="expandMacros"></a>
277
<div class="memitem">
278
<div class="memproto">
279
<table class="memname"><tr>
280
<td class="memname">bool expandMacros</td>
282
<td class="paramtype">{QString:QString} </td>
283
<td class="paramname"><em>initialValues</em>, </td>
286
<td class="memname"></td>
288
<td class="paramtype">QWidget </td>
289
<td class="paramname"><em>parentWindow</em></td>
296
<td width="100%"> </td>
299
<div class="memdoc"><p>Parses <b>templateString</b> for macros in the form [$%]{NAME} and finds
300
the value corresponding to NAME if any. The NAME string may contain
301
any non-whitespace character execpt '}'
302
</p><dl compact><dt><b>Parameters:</b></dt><dd>
303
<table border="0" cellspacing="2" cellpadding="0">
304
<tr><td></td><td valign="top"><em>initialValues</em> </td><td> a map with the keys for the macros to expand.
305
keys with a value are ignored.
306
</td></tr> </table></dl>
307
<p> </p><dl compact><dt><b>Parameters:</b></dt><dd>
308
<table border="0" cellspacing="2" cellpadding="0">
309
<tr><td></td><td valign="top"><em>parentWindow</em> </td><td> is used if dialogs have to be shown
310
</td></tr> </table></dl>
311
<p> <dl class="return" compact><dt><b>Returns:</b></dt><dd> true if all macros was successfully expanded
312
</dd></dl> <dl class="see" compact><dt><b>See also:</b></dt><dd> insertTemplateText for a list of supported macros
321
<div class="menu_box">
322
<div class="nav_list">
324
<li><a href="../allclasses.html">Full Index</a></li>
328
<a name="cp-menu" /><div class="menutitle"><div>
329
<h2 id="cp-menu-project">Modules</h2>
331
<div class="nav_list">
332
<ul><li><a href="../akonadi/index.html">akonadi</a></li>
333
<li><a href="../dnssd/index.html">dnssd</a></li>
334
<li><a href="../kdecore/index.html">kdecore</a></li>
335
<li><a href="../kdeui/index.html">kdeui</a></li>
336
<li><a href="../khtml/index.html">khtml</a></li>
337
<li><a href="../kio/index.html">kio</a></li>
338
<li><a href="../knewstuff/index.html">knewstuff</a></li>
339
<li><a href="../kparts/index.html">kparts</a></li>
340
<li><a href="../kutils/index.html">kutils</a></li>
341
<li><a href="../nepomuk/index.html">nepomuk</a></li>
342
<li><a href="../phonon/index.html">phonon</a></li>
343
<li><a href="../plasma/index.html">plasma</a></li>
344
<li><a href="../polkitqt/index.html">polkitqt</a></li>
345
<li><a href="../solid/index.html">solid</a></li>
346
<li><a href="../soprano/index.html">soprano</a></li>
352
<div class="clearer"/>
355
<div id="end_body"></div>
357
<div id="footer"><div id="footer_text">
358
This documentation is maintained by <a href="mailto:simon@simonzone.com">Simon Edwards</a>.<br />
359
KDE<sup>®</sup> and <a href="../images/kde_gear_black.png">the K Desktop Environment<sup>®</sup> logo</a> are registered trademarks of <a href="http://ev.kde.org/" title="Homepage of the KDE non-profit Organization">KDE e.V.</a> |
360
<a href="http://www.kde.org/contact/impressum.php">Legal</a>