Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Extending Code Templates

Code templates used by CDT are taken from the value of "org.eclipse.cdt.ui.text.custom_code_templates" preference. To cusomize them, all you need to do is to change the preference value. This can be done programmatically or through plugin_customization.ini (http://blog.vogella.com/2012/08/07/eclipse-papercut-9-default-preference-settings-via-plugin_customization-ini-type-filter-example/).

-sergey


On Wed, Oct 23, 2013 at 12:57 PM, Joseph Henry <Joseph.Henry@xxxxxxx> wrote:

Ok, so I am still not able to get this working.

 

Is there someone on this list that could explain to me how to properly use this extension (org.eclipse.ui.editors.templates)?

 

Basically my short term goal is this:

 

1.)    Contribute a template that will when “New -> Source File” is chosen, I can choose my custom template for the source code

2.)    Allow that custom template to be able to use variable that I have defined

 

Any help would be appreciated.

 

Thanks,

Joseph Henry.

 

From: Joseph Henry
Sent: Wednesday, October 23, 2013 10:05 AM


To: 'CDT General developers list.'
Subject: RE: Extending Code Templates

 

I think I figured it out. I am pretty sure that I needed a resolver component.

 

Sorry for jumping the gun on posting.

 

From: Joseph Henry
Sent: Wednesday, October 23, 2013 9:54 AM
To: CDT General developers list.
Subject: Extending Code Templates

 

Hi,

 

I am in need to distributing some default code templates with our plugin and am having a hard time getting this to work.

 

I have created an extension in my plugin org.eclipse.ui.editors.templates and created an include child.

 

For the simple case I want to create a C Source code template similar to org.eclipse.cdt.ui.text.codetemplates.csourcefile But I want it to use our companies default comment header.

 

I used the file /org.eclipse.cdt.ui/templates/default-codetemplates.xml as an example and was able to create a template using the default variables, but when I tried to create a new variable, it would not work.

 

How I attempted to create a variable was to define a section in the xml with the variable name, and define its content. I am guessing that is not the right way because it does not work.

 

I guess my question is: How do you create a substitution variable for a code template? My xml is pasted below.

 

 

<?xml version="1.0" encoding="UTF-8"?>

<templates>

               

                <template name="sas_c_file_comment" id="com.sas.tools.cdt.ui.text.codetemplates.cFileComment" context="org.eclipse.cdt.ui.text.codetemplates.filecomment_context" enabled="true"

                                description="Default comments for a SAS C Source File">

/*---------------------------------------------------------------------

*  Copyright (C), ${year}

*  SAS Institute Inc., Cary, N.C. 27513, U.S.A.  All rights reserved.

* --------------------------------------------------------------------

*

*  NAME:       {file_name}

*  AUTHOR:     {user}

*  DATE:       {date}

*  SUPPORT:    {user} -

 *  PRODUCT:   

 *  LANGUAGE:   C

*  SCRIPT:    

 *  PURPOSE:   

 *

*  HISTORY:

*    Defect    Action                        Date        Name

*    ----------------------------------------------------------------

*   

 *    ----------------------------------------------------------------

*/

                </template>

                <template name="SAS C Source File" id="com.sas.tools.cdt.ui.text.codetemplates.csourcefile" description="Default SAS C Source Template" context="org.eclipse.cdt.core.cSource.contenttype_context" enabled="true">             

                   ${sas_c_file_comment}

 

       ${includes}

 

       ${declarations}

    </template>

               

 

</templates>

 

 

Thanks,

Joseph.


_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev



Back to the top