use of com.intellij.ide.fileTemplates.FileTemplateManager in project intellij-community by JetBrains.
the class PyMoveTest method testTemplateAttributesExpansionInCreatedDestinationModule.
// PY-14979
public void testTemplateAttributesExpansionInCreatedDestinationModule() {
final FileTemplateManager instance = FileTemplateManager.getInstance(myFixture.getProject());
final FileTemplate template = instance.getInternalTemplate("Python Script");
assertNotNull(template);
final String oldTemplateContent = template.getText();
try {
template.setText("NAME = '${NAME}'");
doMoveSymbolTest("C", "b.py");
} finally {
template.setText(oldTemplateContent);
}
}
use of com.intellij.ide.fileTemplates.FileTemplateManager in project intellij-community by JetBrains.
the class CreatePackageAction method createInitPy.
private static void createInitPy(PsiDirectory directory) {
final FileTemplateManager fileTemplateManager = FileTemplateManager.getInstance(directory.getProject());
final FileTemplate template = fileTemplateManager.getInternalTemplate("Python Script");
if (directory.findFile(PyNames.INIT_DOT_PY) != null) {
return;
}
if (template != null) {
try {
FileTemplateUtil.createFromTemplate(template, PyNames.INIT_DOT_PY, fileTemplateManager.getDefaultProperties(), directory);
} catch (Exception e) {
LOG.error(e);
}
} else {
final PsiFile file = PsiFileFactory.getInstance(directory.getProject()).createFileFromText(PyNames.INIT_DOT_PY, "");
directory.add(file);
}
}
use of com.intellij.ide.fileTemplates.FileTemplateManager 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.FileTemplateManager in project intellij-community by JetBrains.
the class ConfigFileFactoryImpl method getText.
private static String getText(final String templateName, @Nullable Project project) throws IOException {
final FileTemplateManager templateManager = project == null ? FileTemplateManager.getDefaultInstance() : FileTemplateManager.getInstance(project);
final FileTemplate template = templateManager.getJ2eeTemplate(templateName);
if (template == null) {
return "";
}
return template.getText(templateManager.getDefaultProperties());
}
use of com.intellij.ide.fileTemplates.FileTemplateManager in project android by JetBrains.
the class AndroidResourceUtil method createFileResource.
@NotNull
public static XmlFile createFileResource(@NotNull String fileName, @NotNull PsiDirectory resSubdir, @NotNull String rootTagName, @NotNull String resourceType, boolean valuesResourceFile) throws Exception {
FileTemplateManager manager = FileTemplateManager.getInstance(resSubdir.getProject());
String templateName = getTemplateName(resourceType, valuesResourceFile, rootTagName);
FileTemplate template = manager.getJ2eeTemplate(templateName);
Properties properties = new Properties();
if (!valuesResourceFile) {
properties.setProperty(ROOT_TAG_PROPERTY, rootTagName);
}
if (ResourceType.LAYOUT.getName().equals(resourceType)) {
final Module module = ModuleUtilCore.findModuleForPsiElement(resSubdir);
final AndroidPlatform platform = module != null ? AndroidPlatform.getInstance(module) : null;
final int apiLevel = platform != null ? platform.getApiLevel() : -1;
final String value = apiLevel == -1 || apiLevel >= 8 ? "match_parent" : "fill_parent";
properties.setProperty(LAYOUT_WIDTH_PROPERTY, value);
properties.setProperty(LAYOUT_HEIGHT_PROPERTY, value);
}
PsiElement createdElement = FileTemplateUtil.createFromTemplate(template, fileName, properties, resSubdir);
assert createdElement instanceof XmlFile;
return (XmlFile) createdElement;
}
Aggregations