如何注册一个CDT项目模板(project template)

How to register a project template with CDT

如何注册一个CDT项目模板(project template)


Once the project template is ready, you need to register it with Eclipse to make the template available for use. It is a good practice to group all the files and resources related to the project template together in one folder. For example, if you are writing a project template for a Hello World Application, group all the resources required for this application in a folder "HelloWorld".

项目模板做好以后,你需要把它注册到Eclipse环境才能使模板生效以便使用.一个好的办法是把所有和项目模板相关的文件和资源放在一个文件夹下.例如,如果你正在写一个"HelloWorld"应用程序的项目模板,把所有这个应用程序所需的资源放在一个"HelloWorld"文件夹下.

To register a project template with CDT follow the steps given below:

按下列步骤注册一个CDT项目模板:

1.    Create an empty plug-in project from the Eclipse workbench without the source folders.

在Eclipse workbench中创建一个不带source文件夹的空的plug-in项目.


2.    Create a new folder to contain the template project's content e.g. "MyExampleProject/templates/MyExampleTemplate". Copy the project template.xml along with all the resources required to create the project. For example, all the header files, source files, resource files etc.

创建一个新文件夹以包含模板项目的内容,例如"MyExampleProject/templates/MyExampleTemplate".拷贝项目模板.xml文件以及所有创建项目所需的关联资源.例如,所有的头文件,源文件,资源文件等.


3.    Open the plug-in manifest editor and select the Dependencies page. For more information on plug-in manifest editor, refer to PDE Guide > Getting Started > Basic Plug-in Tutorial > Plug-in manifest editor.

打开plug-in manifest编辑器,选中"Dependencies"页.要了解更多关于plug-in manifest编辑器的内容,可以参考PDE Guide > Getting Started > Basic Plug-in Tutorial > Plug-in manifest editor.


4.    Click Add to select org.eclipse.cdt.core and org.eclipse.cdt.ui plug-ins from the list.

点击Add并从列表中选中org.eclipse.cdt.core和org.eclipse.cdt.ui插件.


5.    Select the Extensions page in the plug-in manifest editor.

在plug-in manifest编辑器选中"Extensions"页面.


6.    Click Add to create an extension to the extension-point.

点击Add创建一个针对扩展点(extension-point)的扩展(extension).


7.    Select the extension-point with ID org.eclipse.cdt.core.templates from the list of extension-points.

在扩展点列表中选中ID为"org.eclipse.cdt.core.templates"的扩展点.


8.    Right-click on the newly added extension, and select New > template from the context menu. The first one has already been added for you, "(template)".

右击刚添加的扩展,在右键菜单中选择"New > template".第一项(template)已经为你添加好了.

译注:如果右键菜单New里只有Generic,需要在Eclipse→Help→Install New Software安装CDT相关的组件.



9.    Select the new template added in the previous step from the All Extensions list. Its name is initially "(template)".

在所有扩展列表中选中上一步添加的新模板.初始名是"(template)".


10.    Specify the id attribute of this template contribution, for example "com.foobar.templates.contrib.MyTemplate1". This attribute is mandatory. The id need not be the same as the template id (from template.xml). This allows contributing the same template.xml multiple times. It will replace "(template)" in the list.

指定提供模板的id属性,例如"com.foobar.templates.contrib.MyTemplate1",该属性是必须的.这个id不需要跟模板id(template.xml中的id)一样.这样就可以多次提供同一个模板.这个id将替换列表中初始的的"(template)".


11.    Specify the location of the template XML file, relative to the plug-in created in step 1. This attribute is mandatory.

指定模板XML文件的位置,路径相对于第一步创建的plug-in项目.这个属性是必须的.


12.    Specify a filterPattern to indicate the build Configurations for which the template is created. It is a regular expression used to filter the build Configurations. If the template is designed for a particular Configuration, it is recommended to specify the filter pattern. For example, If the template is designed for GCC Configurations, the filter pattern can be ".*gcc". If the template is designed for multiple     build Configurations, you can specify the filter patterns delimited by "|" .

指定一个过滤器模式(filterPattern)以表明创建这个模板所针对的构建配置(build Configurations).它是一个用于过滤build Configurations的正则表达式.如果模板是针对特定配置的,推荐指定过滤器模式.例如,如果模板是针对GCC配置的,那么过滤模式可以是".*gcc".如果模板是针对多种构建配置的,可以使用"|"区分以指定多个过滤模式.

The New Project wizard filters the available build Configurations based on the filter pattern for the selected template. The filter patterns are matched against the available Configurations' ID to get a list of matching SDKs. This is an optional attribute.

新项目向导(New Project wizard)为选中的模板过滤可用的构建配置(build Configurations).过滤模式(filter patterns)通过匹配可用配置的ID取得匹配的SDK的列表.这个属性是可选的.

For more information on regular expression patterns, refer to Java API document for java.util.regex.Pattern.

更多关于正则表达式模式的信息,请参阅Java API文档java.util.regex.Pattern.


13.    Specify the project type you wish the template to be associated with. The project type id can be found by looking at the project types contributed to the buildDefinitions extension point. For more information about project types, see New project information in the What's New in CDT Build section, especially the section "What are the general project type entries?". This attribute is mandatory.

指定模板将要关联的项目类型(project type),项目类型id可以从提供给buildDefinitions扩展点的所有项目类型中找到.更多关于项目类型的信息,请参照New project information in the What's New in CDT Build section,特别是"What are the general project type entries?"这部分.这个属性是必须的.


14.    Specify the pagesAfterTemplateSelectionProvider, which is a fully qualified name of the class that implementsorg.eclipse.cdt.ui.templateengine.IPagesAfterTemplateSelectionProvider interface. This is an optional attribute.

指定pagesAfterTemplateSelectionProvider,这是一个完整实现了org.eclipse.cdt.ui.templateengine.IPagesAfterTemplateSelectionProvider接口的类名.这是一个可选属性.

译注:既然是可选的,这个类我就暂时空着没填,不知道如何实现这个接口类.

After creating the plug-ins and registering the templates, launch a runtime workbench and invoke the New Project wizard to check that the template you added is listed.

在创建了插件并注册了模板以后,启动一个runtime workbench并触发新项目向导以验证新添加的模板在列表中.

File → New → Project... → C Project

你可能感兴趣的:(如何注册一个CDT项目模板(project template))