use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class AppEngineSupportProvider method createFileFromTemplate.
@Nullable
public static VirtualFile createFileFromTemplate(final String templateName, final VirtualFile parent, final String fileName) {
parent.refresh(false, false);
final FileTemplate template = FileTemplateManager.getDefaultInstance().getJ2eeTemplate(templateName);
try {
final String text = template.getText(FileTemplateManager.getDefaultInstance().getDefaultProperties());
VirtualFile file = parent.findChild(fileName);
if (file == null) {
file = parent.createChildData(AppEngineSupportProvider.class, fileName);
}
VfsUtil.saveText(file, text);
return file;
} catch (IOException e) {
LOG.error(e);
return null;
}
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class LightFileTemplatesTest method testSchemas.
public void testSchemas() throws Exception {
assertEquals(FileTemplatesScheme.DEFAULT, myTemplateManager.getCurrentScheme());
FileTemplate template = myTemplateManager.getTemplate(TEST_TEMPLATE_TXT);
assertEquals(HI_THERE, template.getText());
String newText = "good bye";
template.setText(newText);
assertEquals(newText, myTemplateManager.getTemplate(TEST_TEMPLATE_TXT).getText());
myTemplateManager.setCurrentScheme(myTemplateManager.getProjectScheme());
assertEquals(HI_THERE, myTemplateManager.getTemplate(TEST_TEMPLATE_TXT).getText());
myTemplateManager.setCurrentScheme(FileTemplatesScheme.DEFAULT);
assertEquals(newText, myTemplateManager.getTemplate(TEST_TEMPLATE_TXT).getText());
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class LightFileTemplatesTest method testSaveFileAsTemplate.
public void testSaveFileAsTemplate() throws Exception {
AllFileTemplatesConfigurable configurable = new AllFileTemplatesConfigurable(getProject());
try {
configurable.createComponent();
configurable.reset();
FileTemplate template = configurable.createNewTemplate("foo", "bar", "hey");
assertTrue(configurable.isModified());
FileTemplate[] templates = configurable.getTabs()[0].getTemplates();
assertTrue(ArrayUtil.contains(template, templates));
configurable.changeScheme(myTemplateManager.getProjectScheme());
assertTrue(configurable.isModified());
// assertEquals(templates.length, configurable.getTabs()[0].getTemplates().length);
// assertTrue(ArrayUtil.contains(template, configurable.getTabs()[0].getTemplates()));
} finally {
configurable.disposeUIResources();
}
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class LightFileTemplatesTest method testSurviveOnProjectReopen.
public void testSurviveOnProjectReopen() throws Exception {
File foo = PlatformTestCase.createTempDir("foo");
Project reloaded = null;
final Project project = ProjectManager.getInstance().createProject("foo", foo.getPath());
try {
assertNotNull(project);
FileTemplateManager manager = FileTemplateManager.getInstance(project);
manager.setCurrentScheme(manager.getProjectScheme());
FileTemplate template = manager.getTemplate(TEST_TEMPLATE_TXT);
assertEquals(HI_THERE, template.getText());
String newText = "good bye";
template.setText(newText);
assertEquals(newText, manager.getTemplate(TEST_TEMPLATE_TXT).getText());
manager.saveAllTemplates();
PlatformTestUtil.saveProject(project);
closeProject(project);
reloaded = ProjectManager.getInstance().loadAndOpenProject(foo.getPath());
assertNotNull(reloaded);
manager = FileTemplateManager.getInstance(reloaded);
assertEquals(manager.getProjectScheme(), manager.getCurrentScheme());
//manager.setCurrentScheme(FileTemplatesScheme.DEFAULT);
//manager.setCurrentScheme(manager.getProjectScheme()); // enforce reloading
assertEquals(newText, manager.getTemplate(TEST_TEMPLATE_TXT).getText());
} finally {
closeProject(project);
closeProject(reloaded);
}
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class LightFileTemplatesTest method testRemoveTemplate.
public void testRemoveTemplate() throws Exception {
FileTemplate[] before = myTemplateManager.getAllTemplates();
try {
FileTemplate template = myTemplateManager.getTemplate(TEST_TEMPLATE_TXT);
myTemplateManager.removeTemplate(template);
assertNull(myTemplateManager.getTemplate(TEST_TEMPLATE_TXT));
myTemplateManager.setCurrentScheme(myTemplateManager.getProjectScheme());
assertNotNull(myTemplateManager.getTemplate(TEST_TEMPLATE_TXT));
myTemplateManager.setCurrentScheme(FileTemplatesScheme.DEFAULT);
assertNull(myTemplateManager.getTemplate(TEST_TEMPLATE_TXT));
} finally {
myTemplateManager.setTemplates(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY, Arrays.asList(before));
myTemplateManager.setCurrentScheme(myTemplateManager.getProjectScheme());
myTemplateManager.setTemplates(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY, Arrays.asList(before));
}
}
Aggregations