How to register a project template with CDT
如何注冊(cè)一個(gè)CDT項(xiàng)目模板(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".
項(xiàng)目模板做好以后,你需要把它注冊(cè)到Eclipse環(huán)境才能使模板生效以便使用.一個(gè)好的辦法是把所有和項(xiàng)目模板相關(guān)的文件和資源放在一個(gè)文件夾下.例如,如果你正在寫一個(gè)"HelloWorld"應(yīng)用程序的項(xiàng)目模板,把所有這個(gè)應(yīng)用程序所需的資源放在一個(gè)"HelloWorld"文件夾下.
To register a project template with CDT follow the steps given below:
按下列步驟注冊(cè)一個(gè)CDT項(xiàng)目模板:
1.????Create an empty plug-in project from the Eclipse workbench without the source folders.
在Eclipse workbench中創(chuàng)建一個(gè)不帶source文件夾的空的plug-in項(xiàng)目.
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.
創(chuàng)建一個(gè)新文件夾以包含模板項(xiàng)目的內(nèi)容,例如"MyExampleProject/templates/MyExampleTemplate".拷貝項(xiàng)目模板.xml文件以及所有創(chuàng)建項(xiàng)目所需的關(guān)聯(lián)資源.例如,所有的頭文件,源文件,資源文件等.
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"頁.要了解更多關(guān)于plug-in manifest編輯器的內(nèi)容,可以參考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.
點(diǎn)擊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.
點(diǎn)擊Add創(chuàng)建一個(gè)針對(duì)擴(kuò)展點(diǎn)(extension-point)的擴(kuò)展(extension).
7.????Select the extension-point with ID?org.eclipse.cdt.core.templates?from the list of extension-points.
在擴(kuò)展點(diǎn)列表中選中ID為"org.eclipse.cdt.core.templates"的擴(kuò)展點(diǎn).
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)".
右擊剛添加的擴(kuò)展,在右鍵菜單中選擇"New?>?template".第一項(xiàng)(template)已經(jīng)為你添加好了.
譯注:如果右鍵菜單New里只有Generic,需要在Eclipse→Help→Install New Software安裝CDT相關(guān)的組件.
9.????Select the new template added in the previous step from the?All Extensions?list. Its name is initially?"(template)".
在所有擴(kuò)展列表中選中上一步添加的新模板.初始名是"(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",該屬性是必須的.這個(gè)id不需要跟模板id(template.xml中的id)一樣.這樣就可以多次提供同一個(gè)模板.這個(gè)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文件的位置,路徑相對(duì)于第一步創(chuàng)建的plug-in項(xiàng)目.這個(gè)屬性是必須的.
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 "|" .
指定一個(gè)過濾器模式(filterPattern)以表明創(chuàng)建這個(gè)模板所針對(duì)的構(gòu)建配置(build Configurations).它是一個(gè)用于過濾build Configurations的正則表達(dá)式.如果模板是針對(duì)特定配置的,推薦指定過濾器模式.例如,如果模板是針對(duì)GCC配置的,那么過濾模式可以是".*gcc".如果模板是針對(duì)多種構(gòu)建配置的,可以使用"|"區(qū)分以指定多個(gè)過濾模式.
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.
新項(xiàng)目向?qū)?New Project wizard)為選中的模板過濾可用的構(gòu)建配置(build Configurations).過濾模式(filter patterns)通過匹配可用配置的ID取得匹配的SDK的列表.這個(gè)屬性是可選的.
For more information on regular expression patterns, refer to Java API document for?java.util.regex.Pattern.
更多關(guān)于正則表達(dá)式模式的信息,請(qǐng)參閱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.
指定模板將要關(guān)聯(lián)的項(xiàng)目類型(project type),項(xiàng)目類型id可以從提供給buildDefinitions擴(kuò)展點(diǎn)的所有項(xiàng)目類型中找到.更多關(guān)于項(xiàng)目類型的信息,請(qǐng)參照New project information in the What's New in CDT Build section,特別是"What are the general project type entries?"這部分.這個(gè)屬性是必須的.
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,這是一個(gè)完整實(shí)現(xiàn)了org.eclipse.cdt.ui.templateengine.IPagesAfterTemplateSelectionProvider接口的類名.這是一個(gè)可選屬性.
譯注:既然是可選的,這個(gè)類我就暫時(shí)空著沒填,不知道如何實(shí)現(xiàn)這個(gè)接口類.
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.
在創(chuàng)建了插件并注冊(cè)了模板以后,啟動(dòng)一個(gè)runtime workbench并觸發(fā)新項(xiàng)目向?qū)б则?yàn)證新添加的模板在列表中.
File → New → Project... → C Project