use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class LightFileTemplatesTest method testAddRemoveShared.
public void testAddRemoveShared() throws Exception {
File foo = PlatformTestCase.createTempDir("foo");
final Project project = ProjectManager.getInstance().createProject("foo", foo.getPath());
try {
assertNotNull(project);
FileTemplateManager manager = FileTemplateManager.getInstance(project);
manager.setCurrentScheme(manager.getProjectScheme());
manager.saveAllTemplates();
FileTemplateSettings settings = ServiceManager.getService(project, FileTemplateSettings.class);
FTManager ftManager = settings.getDefaultTemplatesManager();
File root = ftManager.getConfigRoot(false);
assertTrue(root.exists());
File file = new File(root, "Foo.java");
assertTrue(file.createNewFile());
manager.saveAllTemplates();
assertTrue(file.exists());
/*
FileTemplate template = manager.addTemplate("Foo", "java");
// now remove it via "remove template" call
manager.removeTemplate(template);
manager.saveAllTemplates();
assertFalse(file.exists());
*/
// check "setTemplates" call
FileTemplateBase templateBase = (FileTemplateBase) manager.addTemplate("Foo", "java");
List<FileTemplate> templates = new ArrayList<>(ftManager.getAllTemplates(true));
assertTrue(templates.contains(templateBase));
ftManager.saveTemplates();
assertTrue(file.exists());
templates.remove(templateBase);
manager.setTemplates(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY, templates);
assertFalse(file.exists());
} finally {
closeProject(project);
}
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class LightFileTemplatesTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
myTemplateManager = FileTemplateManagerImpl.getInstanceImpl(getProject());
FileTemplate template = myTemplateManager.getTemplate(TEST_TEMPLATE_TXT);
((BundledFileTemplate) template).revertToDefaults();
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class GradleModuleBuilder method saveFile.
private static void saveFile(@NotNull VirtualFile file, @NotNull String templateName, @Nullable Map templateAttributes) throws ConfigurationException {
FileTemplateManager manager = FileTemplateManager.getDefaultInstance();
FileTemplate template = manager.getInternalTemplate(templateName);
try {
appendToFile(file, templateAttributes != null ? template.getText(templateAttributes) : template.getText());
} catch (IOException e) {
LOG.warn(String.format("Unexpected exception on applying template %s config", GradleConstants.SYSTEM_ID.getReadableName()), e);
throw new ConfigurationException(e.getMessage(), String.format("Can't apply %s template config text", GradleConstants.SYSTEM_ID.getReadableName()));
}
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class GradleModuleBuilder method appendToFile.
private static void appendToFile(@NotNull VirtualFile file, @NotNull String templateName, @Nullable Map templateAttributes) throws ConfigurationException {
FileTemplateManager manager = FileTemplateManager.getDefaultInstance();
FileTemplate template = manager.getInternalTemplate(templateName);
try {
appendToFile(file, templateAttributes != null ? template.getText(templateAttributes) : template.getText());
} catch (IOException e) {
LOG.warn(String.format("Unexpected exception on appending template %s config", GradleConstants.SYSTEM_ID.getReadableName()), e);
throw new ConfigurationException(e.getMessage(), String.format("Can't append %s template config text", GradleConstants.SYSTEM_ID.getReadableName()));
}
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class NewGroovyClassAction method buildDialog.
@Override
protected void buildDialog(Project project, PsiDirectory directory, CreateFileFromTemplateDialog.Builder builder) {
builder.setTitle(GroovyBundle.message("newclass.dlg.title")).addKind("Class", JetgroovyIcons.Groovy.Class, GroovyTemplates.GROOVY_CLASS).addKind("Interface", JetgroovyIcons.Groovy.Interface, GroovyTemplates.GROOVY_INTERFACE);
if (GroovyConfigUtils.getInstance().isVersionAtLeast(directory, GroovyConfigUtils.GROOVY2_3, true)) {
builder.addKind("Trait", JetgroovyIcons.Groovy.Trait, GroovyTemplates.GROOVY_TRAIT);
}
builder.addKind("Enum", JetgroovyIcons.Groovy.Enum, GroovyTemplates.GROOVY_ENUM).addKind("Annotation", JetgroovyIcons.Groovy.AnnotationType, GroovyTemplates.GROOVY_ANNOTATION);
for (FileTemplate template : FileTemplateManager.getInstance(project).getAllTemplates()) {
FileType fileType = FileTypeManagerEx.getInstanceEx().getFileTypeByExtension(template.getExtension());
if (fileType.equals(GroovyFileType.GROOVY_FILE_TYPE) && JavaDirectoryService.getInstance().getPackage(directory) != null) {
builder.addKind(template.getName(), JetgroovyIcons.Groovy.Class, template.getName());
}
}
}
Aggregations