Custom File Type in File -> New

Answered

Is there a way to add my file type to the File -> New popup? :

0
4 comments

Hi Karol,

great, worked fine, thx. I extended and implemented the CreateFileFromTemplateAction:

public class ScpiFileCreateFromTemplate extends CreateFileFromTemplateAction
{
public ScpiFileCreateFromTemplate()
{
super("SCPI File", "Creates new SCPI file", ScpiLangIcons.FILE);
}

@Override
protected void buildDialog(@NotNull Project project, @NotNull PsiDirectory directory,
CreateFileFromTemplateDialog.Builder builder)
{
builder.setTitle("New SCPI File").
addKind("SCPI", ScpiLangIcons.FILE, "Empty SCPI File.scpi");
}

@Override
protected String getActionName(PsiDirectory directory,
@NotNull String newName, String templateName) {
return "Create New SCPI File: " + newName;
}
}

and placed my template file into the plugin's resources folder:

src\main\resources\Empty SCPI File.scpi.ft

Is there a way to have this template file not directly in the src\main\resources, but in a sub-folder?

 

Milo

0

Looking at the documentation, it seems that they can be placed in `resources/fileTemplates` directory. Please review the documentation.

0

Sorry, you are right, the file must be in the sub-folder, e.g.:

src\main\resources\fileTemplates\Empty SCPI File.scpi.ft

 

It worked in my setup, because I also added the same template through the File -> New -> Edit File Templates...

I'd suggest to add one example of a template file path like mine above to the description here : https://plugins.jetbrains.com/docs/intellij/providing-file-templates.html#creating-file-templates

The theory description there is nice, but without a concrete example it's much harder to adopt it to a specific case.

 

 

0

Please sign in to leave a comment.