mirror of
https://github.com/EiffelSoftware/eiffel-org.git
synced 2025-12-07 07:12:25 +01:00
Update wikipage Code Templates. (Signed-off-by:javier).
git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@1676 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
This commit is contained in:
@@ -51,111 +51,6 @@ When you insert a template into your code, it will often have some highlighted f
|
||||
[[Image:targetless_template_1_4|680px]]
|
||||
Figure 4. Targetless Auto-completion with code templates option list.
|
||||
|
||||
|
||||
====Context templates====
|
||||
The next example shows how to define a template that will be applicable to types that conforms <code>ARRAY [COMPARABLE]</code>.
|
||||
|
||||
EiffelStudio editor provides automatic help to use code templates, in the case of context templates, when you type a dot ('.') character after a feature name, as part of feature call auto-completion, a new option will be available by pressing <code>crtl+space</code>
|
||||
the list of available templates will be display.
|
||||
|
||||
[[Image:target_template_1_0]]
|
||||
Figure 1. Auto-completion with code template option
|
||||
|
||||
At this point a user can select an available template, to insert into the current feature, back to the list of completion possibles by pressing <code>crtl+space</code>, or just ignore and continue editing the code.
|
||||
|
||||
[[Image:target_template_1_1]]
|
||||
Figure 2. Auto-completion with code templates option list
|
||||
|
||||
|
||||
|
||||
<code>
|
||||
note
|
||||
description: "[
|
||||
Code templates for Arrays of COMPARABLES.
|
||||
]"
|
||||
template_version: "1.0"
|
||||
|
||||
|
||||
class ARRAY_TEMPLATE [T -> COMPARABLE]
|
||||
|
||||
inherit
|
||||
|
||||
TEMPLATE [ARRAY [T]]
|
||||
|
||||
feature -- Templates
|
||||
|
||||
maximum: T
|
||||
-- Maximum of `target' array.
|
||||
note
|
||||
tags: "Algorithm, Maximum, ARRAY"
|
||||
do
|
||||
across target as element loop
|
||||
Result := Result.max (element.item)
|
||||
end
|
||||
end
|
||||
|
||||
slice_maximum (low, high: INTEGER): T
|
||||
-- Get the maximum of an array,
|
||||
-- where the interval is defined by default
|
||||
-- by array.lower |..| array.upper.
|
||||
note
|
||||
tags: "Algorithm, Maximum, ARRAY"
|
||||
default: "target.lower, target.upper"
|
||||
do
|
||||
across low |..| high as i loop
|
||||
Result := Result.max (target [i.item])
|
||||
end
|
||||
end
|
||||
end
|
||||
</code>
|
||||
|
||||
====Targetless Templates====
|
||||
The next example shows how to define a template that will be applicable without any specific target.
|
||||
To show the list of available targetless templates by pressing <code>crtl+space</code> you will see a new option in the list
|
||||
of completion possibilities.
|
||||
|
||||
[[Image:target_template_1_3]]
|
||||
Figure 3. Targetless Auto-completion with code template option
|
||||
|
||||
By pressing again <code>crtl+space</code>, the list of targetless templates will be available.
|
||||
|
||||
[[Image:target_template_1_4|780px]]
|
||||
Figure 4. Targetless Auto-completion with code templates option list.
|
||||
|
||||
|
||||
<code>
|
||||
class TEMPLATE_DIRECTORY_GLOBAL
|
||||
|
||||
inherit
|
||||
|
||||
TEMPLATE
|
||||
|
||||
feature -- Templates
|
||||
|
||||
entries
|
||||
-- Display entries of current directory.
|
||||
note
|
||||
title: "Entries for a directory"
|
||||
tags: "Algorithm, entries , DIRECTORY"
|
||||
local
|
||||
l_path: PATH
|
||||
l_dir: DIRECTORY
|
||||
i,j: INTEGER
|
||||
do
|
||||
|
||||
create l_path.make_current
|
||||
create l_dir.make_with_path (l_path)
|
||||
|
||||
across
|
||||
l_dir.entries as ic
|
||||
loop
|
||||
print (ic.item.name)
|
||||
io.put_new_line
|
||||
end
|
||||
end
|
||||
end
|
||||
</code>
|
||||
|
||||
<span id="gui_template"></span>
|
||||
==Associating GUI with Template definition==
|
||||
The following image shows the relationship between the template definition and how they will look in the GUI.
|
||||
|
||||
Reference in New Issue
Block a user