Permalink
Browse files

Surround with tags live template for xml blocks in scala

#SCL-6533 fixed
  • Loading branch information...
1 parent 410cf64 commit e825b543bf82211f16ffd56540538bcc36f8bf6b @niktrop niktrop committed Jan 21, 2014
@@ -198,6 +198,7 @@
<defaultLiveTemplatesProvider implementation="org.jetbrains.plugins.scala.codeInsight.template.impl.ScalaDefaultLiveTemplatesProvider"/>
<liveTemplateContext implementation="org.jetbrains.plugins.scala.codeInsight.template.impl.ScalaLiveTemplateContextType"/>
+ <liveTemplateContext implementation="org.jetbrains.plugins.scala.codeInsight.template.impl.ScalaXmlContextType"/>
<liveTemplateMacro implementation="org.jetbrains.plugins.scala.codeInsight.template.macros.ScalaVariableOfTypeMacro"/>
<liveTemplateMacro implementation="org.jetbrains.plugins.scala.codeInsight.template.macros.SuggestScalaVariableNameMacro"/>
@@ -40,4 +40,14 @@
<option name="SCALA" value="true"/>
</context>
</template>
+ <template name="T" value="&lt;$TAG$&gt;$SELECTION$&lt;/$TAGNAME$&gt;&#13;&#10;"
+ description="Surround with &lt;tag&gt;&lt;/tag&gt;"
+ toReformat="true" toShortenFQNames="true" >
+ <variable name="TAG" expression="" defaultValue="" alwaysStopAt="true" />
+ <variable name="SELECTION" expression="" defaultValue="" alwaysStopAt="false" />
+ <variable name="TAGNAME" expression="firstWord(TAG)" defaultValue="&quot;&quot;" alwaysStopAt="false" />
+ <context>
+ <option name="SCALA_XML" value="true"/>
+ </context>
+ </template>
</templateSet>
@@ -0,0 +1,18 @@
+package org.jetbrains.plugins.scala
+package codeInsight.template.impl
+
+import com.intellij.codeInsight.template.TemplateContextType
+import com.intellij.psi.PsiFile
+import com.intellij.psi.util.PsiTreeUtil
+import org.jetbrains.plugins.scala.lang.psi.api.expr.xml.ScXmlExpr
+
+/**
+ * Nikolay.Tropin
+ * 1/20/14
+ */
+class ScalaXmlContextType extends TemplateContextType("SCALA_XML", "XML", classOf[ScalaLiveTemplateContextType]) {
+ def isInContext(file: PsiFile, offset: Int): Boolean = {
+ val element = file.findElementAt(offset)
+ PsiTreeUtil.getParentOfType(element, classOf[ScXmlExpr]) != null
+ }
+}

0 comments on commit e825b54

Please sign in to comment.