abstract
| - Delphi Live Templates are just one of the many cool features of the BDS and Turbo IDEs. Have you wondered how to get in and tweak the template that you are presented with when you've gone through the steps required to create a new Live Template? It's not that hard, but it's one of those features, that if you don't know it's there ... it's really easy to miss. The trick is to start the IDE without a project in it. If you've already set the IDE to start up without the last project you had open -or- creating a new empty one, you are all set if not you can start the IDE using the -np command-line argument. The reason for this is, once you open a file into the IDE, you can't get at the template you need to edit. With the empty IDE up and running, open the Templates window and expand the IDE tree. There you should find a template called ... template_template. you need to select that file and click on the Edit Button on the ToolBar [or Right_Click and select Edit from the pop-up menu that is presented]. That should have opened the file in the IDE. As I mentioned, once you open anything ... the IDE tree is no longer available in the Templates window - that includes the file you just opened. There are a number of things you can do to enhance the template so that when you create Live Templates from it, it will be a little easier or at least customized to your needs. The first thing you should do is change the delimiter used for the Live Templates created for you. You'll find that information between the innermost brackets of the item - about two thirds the way down the code block. In the output code you will find the <code language="$language$"></code> <p> node. You need to add a <code>delimiter="|"</code> parameter so that the whole thing looks like </p> <pre> <code><code language="$language$" delimiter="|"></code></code></pre> <code> <p> It has been noted in a number of place that leaving the delimiter in its default state of <code>$</code> is a bad idea - <code>$</code> can be used in code so if you don't change it and your code includes a <code>$</code> it will confuse the script parser when it tries to output the code contained in your template into the IDE. The remainder of the output block can pretty well remain the same unless there are more complex changes that you would like to make. </p> <p> One of the enhancements you can make is to add default text to some of the data entry points. If you look further up from where we've been working you will find some <code> <point></point></code> nodes. <a href="/mediawiki/Live_Templates_Technical_Info" title="Live Templates Technical Info">Live Templates Technical Info</a> covers these much better than I ever could except to say the ones where we're working are pretty generic. To give you an example of what can be done, I've added my name [changed here to protect the guilty] as default in the "author" point: </p> <pre> <code></code></pre> <code> <p> <point name="author"></point> </p> <pre> <text> Ima Wannabe </text> <hint> Name of the author </hint></pre> <p> </p> </code> <pre><code> </code></pre> <p> Because I always work with Delphi I've also changed the "language" point to: </p> <pre> <code></code></pre> <code> <p> <point name="language"></point> </p> <pre> <text> Delphi </text> <hint> Language that the template targets </hint></pre> <p> </p> </code> <pre><code> </code></pre> <p> Of note in the point node changes I've show above all this does is set the <b>default</b> values, they can easily be changed by simply typing in something new when you're in the automated mode of creating a new template. If you want to make changes that are permanent and not part of the automated process ... delete the related point node and replace the appropriate text [the <code>name="whatever"</code> parameter of the node] in the output code block. </p> <p> Another change you might want to make is adding $end$ to the CDATA section, so your cursor doesn't stay in the Language entry point but moves on to the actual content of the template: </p> </code><code> $end$$selected$$CDATAEND$</pre> <p> I've also changed the output code to have all the minor nodes be single line but I won't show that here [except in the samples above] ... bigger wars have started over much smaller things. You get the idea now. </p> <p> Here's a handy template you can add to your system to use when creating templates. It will automate the process of adding <code><point></point></code>s to your code: </p> <p> <pre> <?xml version="1.0" encoding="utf-8" ?> <codetemplate xmlns="http://schemas.borland.com/Delphi/2005/codetemplates" version="1.0.0"> <template name="point" invoke="manual"> <description>Used to enter points in Live Templates</description> <author>Stolen from Nick Hodges who borrowed it from Deborah Pate</author> <point name="pointname"> <text>pointname</text> <hint>The name to be used for this point.</hint> </point> <point name="pointtext"> <text /> <hint>The default text to insert.</hint> </point> <point name="pointhint"> <text /> <hint>The text describing the point.</hint> </point> <code language="XML" delimiter="|"> <![CDATA[ <point name="|pointname|"> |*|<text>|pointtext|</text> |*|<hint>|pointhint|</hint> </point> |end| </code> Have fun with the BDS/Turbo you've chosen to use as your programming IDE. If you want to learn more about templates and how the above works, see Live Templates Technical Info.
|