Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext templates(Xtext templates)
Xtext templates [message #1008341] Tue, 12 February 2013 04:32 Go to next message
Girish Kumar is currently offline Girish KumarFriend
Messages: 40
Registered: May 2011
Member
Hi All,

I wanted to create template for content assist.

The documentation says : you need to create a folder named templates and add templates.xml inside it.

I have created templates.xml by exporting it from the runtime preference page.

The same i added into templates folder of ui plugin.

But it is not working..

Please let me know, i have done anything wrong ??

As a matter of fact, I have also added template folder to exported in build.properties.

Regards
Girish
Re: Xtext templates [message #1008354 is a reply to message #1008341] Tue, 12 February 2013 07:12 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1189
Registered: July 2009
Senior Member
Hi,

the documentation says a bit more than this!
Quote:
It is best practice to edit the templates in the preferences page, export them into the templates.xml-file and put this one into the templates folder of your UI-plug-in. However, these templates will not be visible by default. To fix it, you have to manually edit the xml-file and insert an id attribute for each template element. Note that the attribute name is case sensitive. As always in eclipse plug-in development, if the folder templates did not exist before, you have to add it to the bin.includes in your build.properties.


Alex
Re: Xtext templates [message #1740360 is a reply to message #1008354] Fri, 12 August 2016 09:25 Go to previous messageGo to next message
Olaf Bigalk is currently offline Olaf BigalkFriend
Messages: 97
Registered: July 2009
Location: Berlin
Member
Hi,
I did all you mentioned but it does not work either.
Re: Xtext templates [message #1740361 is a reply to message #1740360] Fri, 12 August 2016 09:29 Go to previous messageGo to next message
Stephane Galland is currently offline Stephane GallandFriend
Messages: 65
Registered: July 2014
Location: Belfort, France
Member
In your "lang.ui" project:
* create the folder "templates"
* create the file "templates/templates.xml"
* edit the file with something similar to:
<?xml version="1.0" encoding="UTF-8" ?> 
<templates>
	<template
	    name="def"
	    description="public method"
	    id="def"
	    context="io.sarl.lang.SARL.Member"
	    enabled="true"
	    autoinsert="false">def ${name}(${params}) {
		${cursor}
	}</template>
	<template
	    name="protecteddef"
	    description="protected method"
	    id="protected_def"
	    context="io.sarl.lang.SARL.Member"
	    enabled="true"
	    autoinsert="false">protected def ${name}(${params}) {
		${cursor}
	}</template>
</templates>

[Updated on: Fri, 12 August 2016 09:30]

Report message to a moderator

Re: Xtext templates [message #1740363 is a reply to message #1740361] Fri, 12 August 2016 09:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 9592
Registered: July 2009
Senior Member
please be aware. the ID is a must must must Wink
Re: Xtext templates [message #1740365 is a reply to message #1740363] Fri, 12 August 2016 09:53 Go to previous messageGo to next message
Olaf Bigalk is currently offline Olaf BigalkFriend
Messages: 97
Registered: July 2009
Location: Berlin
Member
Hi,
I have this templates.xml it resides in the templates folder in the ui project of my plugin and it is enabled in the build section for binary builds.
if I run my plugin in a runtime eclipse the templates are not loaded.
I cannot see my mistake:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<templates>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatterDefinition"
		deleted="false" description="keyword &quot;.&quot; &quot;:&quot;"
		enabled="true" name="keyworddot" id="keyworddot">keyword "." ":" {
			format dot {
			nospace around
			}
		}
	</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatterDefinition"
		deleted="false" description="keyword &quot;,&quot; " enabled="true"
		name="keywordkomma" id="keywordkomma">keyword "," {
			format komma {
			nospace before
			space " " after
			}
		}
	</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatterDefinition"
		deleted="false" description="keyword &quot;;&quot;" enabled="true"
		name="keywordsemicolon" id="keywordsemicolon">keyword ";" {
			format semicolon {
			nospace before
			linewrap(2,0,1) after
			}
		}
	</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatterDefinition"
		deleted="false" description="format linewrapAround(2,1,1)" enabled="true"
		name="linewrapAround" id="linewrapAround">format linewrapAround linewrap (2, 1,1)
		around</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatterDefinition"
		deleted="false" description="pair &quot;(&quot; &quot;)&quot; &quot;[&quot; &quot;]&quot;"
		enabled="true" name="pair()"id="pairparenteses">pair "(" ")" "[" "]" {
			format openParentesis {
			nospace around
			}
			format closingParentesis {
			nospace before
			}
		}
	</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatterDefinition"
		deleted="false" description="pair &quot;{&quot; &quot;}&quot; "
		enabled="true" name="pair{}" id="pairbaces">pair "{" "}" {
			format openBrace {
			space " " before
			linewrap(2, 0, 0) after
			indent after
			}
			format closingBrace {
			linewrap(2, 1, 1) before
			deindent before
			}
		}
	</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatDefinition"
		deleted="false" description="use closingBrace" enabled="true"
		name="useclosingBrace" id="useclosingBrace">use closingBrace</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatDefinition"
		deleted="false" description="use closingParentesis" enabled="true"
		name="useclosingParentesis"id="useclosingParentesis">use closingParentesis</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatDefinition"
		deleted="false" description="use dot" enabled="true" name="usedot" id="usedot">use dot
	</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatDefinition"
		deleted="false" description="use komma" enabled="true" name="usekomma"id="usekomma">use komma
	</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatDefinition"
		deleted="false" description="use semicolon" enabled="true" name="useksemicolon"id="useksemicolon">use
		semicolon</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatDefinition"
		deleted="false" description="use linewrapAround" enabled="true"
		name="uselinewrapAround"id="uselinewrapAround">use linewrapAround ${Max_Min_Default}</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatDefinition"
		deleted="false" description="use openBrace" enabled="true" name="useopenBrace"id="useopenBrace">use
		openBrace</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatDefinition"
		deleted="false" description="use openParentesis" enabled="true"
		name="useopenParentesis"id="useopenParentesis">use openParentesis</template>
</templates>
Re: Xtext templates [message #1740366 is a reply to message #1740365] Fri, 12 August 2016 10:01 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 9592
Registered: July 2009
Senior Member
can you try the following

(1) create a bunch of templates with the editor in eclipse
(1b) test them in eclipse
(2) export them
(3) remove those created in eclipse
(4) add the exportted to your template.xml
(5) add the missing ids
(6) start eclipse

[Updated on: Fri, 12 August 2016 10:02]

Report message to a moderator

Previous Topic:Xtext Project from or with Ecore model
Next Topic:Runnable DSL File
Goto Forum:
  


Current Time: Tue Aug 30 05:00:27 GMT 2016

Powered by FUDForum. Page generated in 0.19534 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software