| How to add custom code templates to my plugin? [message #670307] |
Fri, 13 May 2011 09:26  |
Dwight Johnson Messages: 19 Registered: March 2011 |
Junior Member |
|
|
Hello,
I am working on a plugin myplugin that supports a custom webproject and perspective.
XHTML, CSS en .JS have an adapted syntax.
Code templates need to be provided that must be stored in the plugin in templates/templates.xml.
In templates.xml resides:
<templates>
<template autoinsert="true"
contextTypeId="html_tag"
description="[Description]"
id="org.eclipse.jst.jsf.ui.newHtmltag"
name="testTag"
enabled="true"
context="html_tag" >
Some template content...
</template>
</templates>
In plugin.xml we have:
<extension
point="org.eclipse.ui.editors.templates">
<include file="templates/templates.xml"/>
</extension>
This template does indeed show up in Preferences > Web > HTML files > Editor > Templates under context=HTML Tag.
What I do not understand is: how can I introduce a new HTML context 'CE_HTML' where my new templates will reside under? Changes/additions allowed only in myplugin.
I tried this in plugin.xml:
<!-- Templates -->
<extension point="org.eclipse.ui.editors.templates">
<contextType
name="%CE_HTML_context_type_Extension_Element.name"
class="org.eclipse.wst.html.ui.internal.templates.TemplateContextTypeHTML"
id="html_ce">
</contextType>
<include
file="templates/htmldefault-templates2.xml"
translations="$nl$/templates/htmldefault-templates.properties">
</include>
</extension>
with templates in htmldefault-templates2.xml but nothing shows up.
Any suggestion would be much appreciated.
|
|
|
|
|
|
| (no subject) [message #693645 is a reply to message #670343] |
Wed, 06 July 2011 19:45  |
 |
Nitin Dahyabhai Messages: 1843 Registered: July 2009 |
Senior Member |
|
|
On 5/13/2011 11:20 AM, Dwight Johnson wrote:
> Nitin Dahyabhai wrote on Fri, 13 May 2011 10:31
>> The HTML Templates preference page is only designed to
>> show the template contexts defined by the HTML plug-ins. It sounds
>> like you need to contribute your own subclass of
>> org.eclipse.ui.texteditor.templates.TemplatePreferencePage.
>
>
> Hello Nitin,
>
> That seems to be rather a big task.
Not as much as you think. Besides, our template proposal computers
won't be processing the templates from your contexts anyway.
> Under Windows > Show View > there is a template view. For some reason it
> does show templates for java but not for
> css/js/html.
It's not implemented for those editors since the editors are built in a
way that their viewer configurations and supported content type can be
changed on the fly. The Templates View is locked down in one content
type from the start (possibly before we've figured out which content
type is in the editor), and that's all it ever gets to show.
--
Nitin Dahyabhai
Eclipse WTP Source Editing and JSDT
IBM Rational
---
Nitin Dahyabhai
Eclipse WTP, IBM
|
|
|
Powered by
FUDForum. Page generated in 0.02384 seconds