Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "CDT/HowTo extend CDT with custom file templates"

< CDT
(HowTo extend CDT with custom file templates)
(HowTo extend CDT with custom file templates)
Line 8: Line 8:
 
  2. Add to the plugin following extension point: org.eclipse.ui.editors.templates
 
  2. Add to the plugin following extension point: org.eclipse.ui.editors.templates
  
  3. For every xml file where u define your templates you need an include tag in the extension point.
+
  3. For a XML template file where you later define your templates you have to add an include tag in the extension point.
 
     An example plugin.xml file which you can use for testing looks like following:
 
     An example plugin.xml file which you can use for testing looks like following:
  
Line 19: Line 19:
  
 
  4. Now create in your plugin project a folder called "templates" and put a file "templates.xml" into it.
 
  4. Now create in your plugin project a folder called "templates" and put a file "templates.xml" into it.
     Of course you can use own paths and filenames if you modify the include XML tag.
+
     Of course you can use own paths and filenames if you modify the include XML tag. Also make sure that the file get included in
 +
    the build path of your plugin.
  
 
  5. After that you must edit the xml file cotaining your templates. In this example i create two templates,
 
  5. After that you must edit the xml file cotaining your templates. In this example i create two templates,
Line 30: Line 31:
 
         context="org.eclipse.cdt.core.cSource.contenttype_context"  
 
         context="org.eclipse.cdt.core.cSource.contenttype_context"  
 
         enabled="true">
 
         enabled="true">
 +
        // ${file_name}
 
         // Test Source
 
         // Test Source
 
       </template>
 
       </template>
Line 37: Line 39:
 
       context="org.eclipse.cdt.core.cHeader.contenttype_context"  
 
       context="org.eclipse.cdt.core.cHeader.contenttype_context"  
 
       enabled="true">
 
       enabled="true">
 +
      // ${file_name}
 
       // Test Header
 
       // Test Header
 
     </template>
 
     </template>
Line 48: Line 51:
 
  7. To check what possibilities you have for creating templates, have a look in plugin.xml from org.eclipse.cdt.ui.
 
  7. To check what possibilities you have for creating templates, have a look in plugin.xml from org.eclipse.cdt.ui.
 
     In the subfolder "templates" of this package you will also find the cdt template XML files.
 
     In the subfolder "templates" of this package you will also find the cdt template XML files.
 +
   
 +
PS: To use the "$" sign if its no macro take the following syntax in your templates: "$$"

Revision as of 10:20, 5 September 2008

HowTo extend CDT with custom file templates

In this article i give a short description how to add your own file templates to CDT. You will be able to use them in every CDT C/C++ project.

1. Create a new Eclipse Plugin project.
2. Add to the plugin following extension point: org.eclipse.ui.editors.templates
3. For a XML template file where you later define your templates you have to add an include tag in the extension point.
   An example plugin.xml file which you can use for testing looks like following:
   <plugin>
     <extension
       point="org.eclipse.ui.editors.templates">
       <include file="templates/templates.xml"/>
     </extension>
   </plugin>
4. Now create in your plugin project a folder called "templates" and put a file "templates.xml" into it.
   Of course you can use own paths and filenames if you modify the include XML tag. Also make sure that the file get included in
   the build path of your plugin.
5. After that you must edit the xml file cotaining your templates. In this example i create two templates,
   one for C source and one for C header files. Just look at the following XML Code, i think should be quite easy to understand: 
   <templates>
     <template name="testC" 
       id="test.codetemplates.csourcefile" 
       description="testC" 
       context="org.eclipse.cdt.core.cSource.contenttype_context" 
       enabled="true">
       // ${file_name}
       // Test Source
     </template>
   <template name="testH" 
     id="test.codetemplates.headerfile" 
     description="testH" 
     context="org.eclipse.cdt.core.cHeader.contenttype_context" 
     enabled="true">
     // ${file_name}
     // Test Header
   </template>
 </templates>
6. OK, thats all. Now you can export the plugin project to a plugin and put it into your eclpsePath/plugin folder.
   After you restart eclipse and create a new c source/header file u can choose your template in the template field.
 NewFileTemplate.JPG
7. To check what possibilities you have for creating templates, have a look in plugin.xml from org.eclipse.cdt.ui.
   In the subfolder "templates" of this package you will also find the cdt template XML files.
   
PS: To use the "$" sign if its no macro take the following syntax in your templates: "$$"

Back to the top