Nodes with children

Extension nodes may have child nodes. In this case an extension node behaves like an extension point, and the extension node must declare the kind of child nodes it accepts. For example:

<Addin 	namespace="TextEditor" id="Core" version="1.0" isroot="true">
	...
	<ExtensionPoint path="/TextEditor/Templates" name="...">
		<Description>Templates that allow creating files with a default content</Description>
		<ExtensionNode name="TemplateCategory" type="TextEditor.TemplateCategory">
			<Description>A category which contains related templates</Description>
			<ExtensionNode name="FileTemplate" type="TextEditor.FileTemplateNode">
		</ExtensionNode>
	</ExtensionPoint>
	...
</Addin>

The previous extension point would accept extensions like this:

<Addin ...>
	...
	<Extension path="/TextEditor/Templates">
		<TemplateCategory id="Documents">
			<FileTemplate id="Letter" resource="letter-template.txt" />
			<FileTemplate id="Fax" resource="fax-template.txt" />
		</TemplateCategory>
		<TemplateCategory id="Development">
			<FileTemplate id="README" resource="readme-template.txt" />
			<FileTemplate id="ChangeLog" resource="changelog-template.txt" />
		</TemplateCategory>
	</Extension>
	...
</Addin>

Extension nodes which accept children behave like extension points, and can be extended by add-ins just like them. For example, if an add-in adds the previous extensions to the extension point, another add-in could further extend this new template like this:

<Addin ...>
	...
	<Extension path="/TextEditor/Templates/Development">
		<FileTemplate file="LICENSE" resource="license-template.txt"/>
	</Extension>
	...
</Addin>

Notice that the path used in this extension is directly referencing an extension node using its ID. So, only nodes which have an ID can be extended in this way.

Children of an extension node can also be declared by applying the [Mono.Addins.ExtensionNodeChild] attribute to the class that implements the node. This is explained later in the Custom Extension Node Types section.

Last edited May 20, 2010 at 2:59 PM by slluis, version 4

Comments

No comments yet.