So I want to create a file template in my IntelliJ IDEA plugin and I managed to mine these out from some other plugins, but the template always wants to be a java file and I cannot change the extension of it to be .cqt insteaf of .java
What I figured out:
I need to add these to the plugin.xml
<internalFileTemplate name="Croquette File" />
and I need
<createFromTemplateHandler implementation="...CroquetteCreateFromTemplateHandler" />
with the file creation action
<action
id="Croquette.NewFile"
class="...NewCroquetteFileDefinitionAction"
text="Croquette File"
description="Create a new Croquette file" >
<add-to-group group-id="NewGroup" anchor="after" relative-to-action="NewGroup1"/>
</action>
The NewCroquetteFileDefinitionAction contains this:
class NewCroquetteFileDefinitionAction
extends CreateFileFromTemplateAction(
NewCroquetteFileDefinitionAction.NEW_CQT_FILE,
"",
CroquetteIcons.fileIcon)
with DumbAware {
import NewCroquetteFileDefinitionAction._
override def buildDialog(
project: Project,
directory: PsiDirectory,
builder: CreateFileFromTemplateDialog.Builder): Unit = {
builder
.setTitle(NEW_CQT_FILE)
.addKind("Croquette File", CroquetteIcons.fileIcon, "Croquette File")
.setValidator(new InputValidatorEx {
override def getErrorText(inputString: String): String =
if (!inputString.isEmpty && !containsFuckyCharacters(inputString))
s"'$inputString' is not a valid Croquette file name."
else null
override def checkInput(inputString: String): Boolean = getErrorText(inputString) != null
override def canClose(inputString: String): Boolean = checkInput(inputString)
})
}
override def getActionName(directory: PsiDirectory, newName: String, templateName: String): String = NEW_CQT_FILE
override def hashCode(): Int = 0
override def equals(obj: Any): Boolean = obj.isInstanceOf[NewCroquetteFileDefinitionAction]
}
object NewCroquetteFileDefinitionAction {
val NEW_CQT_FILE = "New Croquette File"
def containsFuckyCharacters(strIn: String): Boolean = {
List("+", "-", "<", ">", "\\", "/", ",", ".", "[", "]", "{", "}", "@", "&", "$", ";", "*").foreach(ch =>
if (strIn.contains(ch))
return true
)
false
}
}
And I am guessing I have to do something here in the CroquetteDefaultPropertiesProvider class but not sure what, or even if that guess is correct or not as I cannot find any documentation on how to create file templates with plugins.
class CroquetteDefaultPropertiesProvider extends TemplatePackagePropertyProvider {
override def fillProperties(directory: PsiDirectory, props: Properties) {
super.fillProperties(directory, props)
}
}